|
|
@ -17,47 +17,58 @@ class SearchScreen extends StatefulWidget {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
|
|
|
final _controller = TextEditingController();
|
|
|
|
final controller = TextEditingController();
|
|
|
|
final _focusNode = FocusNode();
|
|
|
|
final focusNode = FocusNode();
|
|
|
|
String _terms = '';
|
|
|
|
String terms = '';
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
_controller.addListener(_onTextChanged);
|
|
|
|
controller.addListener(_onTextChanged);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
void dispose() {
|
|
|
|
_focusNode.dispose();
|
|
|
|
focusNode.dispose();
|
|
|
|
super.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _onTextChanged() {
|
|
|
|
void _onTextChanged() {
|
|
|
|
setState(() => _terms = _controller.text);
|
|
|
|
setState(() => terms = controller.text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget _createSearchBox() {
|
|
|
|
Widget _createSearchBox() {
|
|
|
|
return Padding(
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: SearchBar(
|
|
|
|
child: SearchBar(
|
|
|
|
controller: _controller,
|
|
|
|
controller: controller,
|
|
|
|
focusNode: _focusNode,
|
|
|
|
focusNode: focusNode,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<Widget> _generateVeggieRows(List<Veggie> veggies) {
|
|
|
|
Widget _buildSearchResults(List<Veggie> veggies) {
|
|
|
|
final cards = new List<Widget>();
|
|
|
|
if (veggies.isEmpty) {
|
|
|
|
|
|
|
|
return Center(
|
|
|
|
for (Veggie veggie in veggies) {
|
|
|
|
child: Padding(
|
|
|
|
cards.add(Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
|
|
|
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
|
|
|
|
child: Text(
|
|
|
|
child: VeggieHeadline(veggie),
|
|
|
|
'No veggies matching your search terms were found.',
|
|
|
|
));
|
|
|
|
style: Styles.headlineDescription,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return cards;
|
|
|
|
return ListView.builder(
|
|
|
|
|
|
|
|
itemCount: veggies.length,
|
|
|
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
|
|
|
|
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
|
|
|
|
|
|
|
|
child: VeggieHeadline(veggies[i]),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
@ -75,9 +86,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
_createSearchBox(),
|
|
|
|
_createSearchBox(),
|
|
|
|
Expanded(
|
|
|
|
Expanded(
|
|
|
|
child: ListView(
|
|
|
|
child: _buildSearchResults(model.searchVeggies(terms)),
|
|
|
|
children: _generateVeggieRows(model.searchVeggies(_terms)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|