Autocomplete Dropdown

Loading preview

Starting the Flutter app

A Flutter autocomplete dropdown that filters suggestions as you type.

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

AutocompleteTextField wraps Flutter’s Autocomplete, which owns the controller, focus node and suggestions overlay, so there’s nothing to dispose here. optionsBuilder filters items by substring on every keystroke, and fieldViewBuilder supplies a TextFormField so the field joins the Form. Validation is selection-only: onItemSelect sets _selectedItem, onChanged clears it when the text diverges, and a typed country fails until it’s picked from the list.

Adapting it

  • Replace _countries with your own options, or fetch them inside optionsBuilder.
  • Style the list with optionsViewBuilder.
  • Use displayStringForOption if your options are typed models.