diff --git a/example/lib/main.dart b/example/lib/main.dart index 631c8ec..5170747 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -39,10 +39,21 @@ class SearchFieldSample extends StatefulWidget { class _SearchFieldSampleState extends State { int suggestionsCount = 12; final focus = FocusNode(); + @override - Widget build(BuildContext context) { - final suggestions = + void initState() { + suggestions = List.generate(suggestionsCount, (index) => 'suggestion $index'); + super.initState(); + } + + var suggestions = []; + @override + Widget build(BuildContext context) { + Widget searchChild(x) => Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12), + child: Text(x, style: TextStyle(fontSize: 24, color: Colors.white)), + ); return Scaffold( appBar: AppBar( title: Text('Dynamic sample Demo'), @@ -66,13 +77,8 @@ class _SearchFieldSampleState extends State { element.toLowerCase().contains(query.toLowerCase())) .toList(); return filter - .map((e) => SearchFieldListItem(e, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), - child: Text(e, - style: - TextStyle(fontSize: 24, color: Colors.red)), - ))) + .map((e) => + SearchFieldListItem(e, child: searchChild(e))) .toList(); }, key: const Key('searchfield'), @@ -86,6 +92,8 @@ class _SearchFieldSampleState extends State { // trackRadius: const Radius.circular(10), // ), onTapOutside: (x) {}, + suggestionStyle: + const TextStyle(fontSize: 24, color: Colors.white), searchInputDecoration: InputDecoration( focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(24), @@ -115,12 +123,8 @@ class _SearchFieldSampleState extends State { borderRadius: BorderRadius.circular(24), ), suggestions: suggestions - .map((e) => SearchFieldListItem(e, - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0,horizontal: 12), - child: Text(e, - style: TextStyle(fontSize: 24, color: Colors.white)), - ))) + .map((e) => + SearchFieldListItem(e, child: searchChild(e))) .toList(), focusNode: focus, suggestionState: Suggestion.expand,