buildSuggestions method
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) {
final SearchBloc searchBloc = BlocProvider.of<SearchBloc>(context);
final List<Feature> history = searchBloc.state.history;
return Column(
children: [
ListTile(
leading: const Icon(Icons.place_outlined),
title: const Text('Set location manually'),
onTap: () =>
close(context, SearchResult(isCancelled: false, isManual: true)),
),
const Divider(),
ListTile(
title: const Text('Search history'),
trailing: IconButton(
tooltip: 'Delete history',
icon: const Icon(
Icons.restore,
),
onPressed: () => searchBloc.add(OnDeleteHistoryEvent()),
)),
Expanded(
child: history.isNotEmpty
? ListView.separated(
separatorBuilder: (context, index) => const Divider(),
itemCount: history.length,
itemBuilder: (context, index) {
final Feature place = history[index];
return ListTile(
title: Text(place.text),
subtitle: Text(place.placeName),
leading: const Icon(Icons.place_outlined),
onTap: () {
close(
context,
SearchResult(
isCancelled: false,
position:
LatLng(place.center[1], place.center[0]),
name: place.text,
description: place.placeName));
});
})
: const Center(
child: Text('Empty history'),
),
)
],
);
}