Search Suggestions

Loading preview

Starting the Flutter app

Autocomplete, recent searches, trending

Get the source

Add it to your project

Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.

First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.

How it works

A listener on _controller filters _recent into _suggestions on each keystroke, adding a Suggestions block above the Recent and Trending lists. Only _recent is searched, so trending terms never match. The query is lowercased but entries aren’t, so a capitalized recent term would be missed. Tapping a recent item fills the field; suggestion and trending taps show a demo SnackBar.

Adapting it

  • Replace the .where filter with a debounced autocomplete API call.
  • Lowercase both sides of s.contains(q).
  • Persist _recent and submit the query from each onTap.