buildResults method

  1. @override
Widget buildResults(
  1. BuildContext context
)
override

The results shown after the user submits a search from the search page.

The current value of query can be used to determine what the user searched for.

This method might be applied more than once to the same query. If your buildResults method is computationally expensive, you may want to cache the search results for one or more queries.

Typically, this method returns a ListView with the search results. When the user taps on a particular search result, close should be called with the selected result as argument. This will close the search page and communicate the result back to the initial caller of showSearch.

Implementation

@override
Widget buildResults(BuildContext context) {
  for (var element in allVerbs) {
    if (element.toLowerCase().contains(query.toLowerCase())) {
      suggestedVerbs.add(element);
    }
  }

  return ListView.builder(
      itemCount: suggestedVerbs.length,
      itemBuilder: (BuildContext context, int index) {
        var result = suggestedVerbs[index];
        return ListTile(
          title: Text(
            result,
            key: Key("searchResult_$result"),
          ),
          onTap: () {
            close(context, result);
          },
        );
      });
}