SearchDelegate does not call buildResults method SearchDelegate does not call buildResults method dart dart

SearchDelegate does not call buildResults method


BuildSuggestions is meant to do just that, build a list of suggestions to whatever is typed in the search bar. The listener responds to each and every change to the Text Field state. This could be used to provide autocomplete suggestions to the user.

BuildResults is called when the user calls for the results by clicking on the "magnifying glass" button on the keyboard, or whatever is used to "submit" the results indicating that the user has finished their typing and is requesting the results of the text search.

You can see an explanation here Flutter's Search Support (The Boring Flutter Development Show, Ep. 10)

Taken from the documentation for buildResults(BuildContext context) → Widget "The results shown after the user submits a search from the search page."


Try Calling the buildResults function at the ontap() session in your ListTile widget. Also call the data you want displayed by the BuildResults inside it like this

     @override     Widget buildResults(BuildContext context,["Data you want displayed when you click      search"]) {     return Text(query);      }

And in the suggestion area like this

 onTap: () =>                         Navigator.push(                              context,                              MaterialPageRoute(                                builder: (context) => Scaffold(                                    appBar: AppBar(                                        backgroundColor:                                            Colors.blueGrey[900],                                        title: new Text(                                          "Country",                                          style: TextStyle(                                              color: Colors.white),                                        )),                                    body: buildResults(context)),                              )),

Ofcourse this is just for an Example however you want to call the buildResults "lies in your court". This is how it works, The buildResult(context) takes the context in this case the data you are using from "final results" whether in "BuildResults(BuildContext, context)" and displays as called or used in-code like this

final results = snapshot.data.length;            results = filteredUsers                 .where((a) => (a.region.contains(query))                      || a.region.contains(query)                     )                 .toList();return ListView.builder(                        itemCount: results.length,                         itemBuilder: (context, index) => Column(                           crossAxisAlignment: CrossAxisAlignment.center,                           mainAxisAlignment: MainAxisAlignment.spaceEvenly,                           mainAxisSize: MainAxisSize.max,                           children: <Widget>[              //As used in-code                          Text(${results[index].region})                             ]))

So in my case "Data you want displayed when you clicksearch"=[Results] represented like this

 @override  Widget buildResults(BuildContext context, [results]) {//How you want your BuildResult page to look like}