buildSuggestions method

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

Suggestions shown in the body of the search page while the user types a query into the search field.

The delegate method is called whenever the content of query changes. The suggestions should be based on the current query string. If the query string is empty, it is good practice to show suggested queries based on past queries or the current context.

Usually, this method will return a ListView with one ListTile per suggestion. When ListTile.onTap is called, query should be updated with the corresponding suggestion and the results page should be shown by calling showResults.

Implementation

@override
Widget buildSuggestions(BuildContext context) {
  suggestedVerbs.clear();
  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("suggestedResult_$result"),
            textScaleFactor: TextSizeLimiter.textScaleFactor(context),
          ),
          onTap: () {
            close(context, result);
          },
        );
      });
}