In flutter_typehead TypeAheadField widget, how do I customize the message letting user know there is no matching item found?

Issue

I am trying to use this module https://github.com/AbdulRahmanAlHamali/flutter_typeahead to make a text field with autocomplete/"type ahead" functionality.

When the user searches an item in the text field form and the item is not found, there is a ‘No Item Found’ message returned. How do I customize this message for localization purposes?

Solution

The TypeAheadFormField provides a callback which can be used to customize the message "No Item Found". I did not see this in the doc but its available. The callback is: noItemsFoundBuilder .

Here a sample code for using this callback:

TypeAheadFormField(
          textFieldConfiguration: TextFieldConfiguration(
              controller:
              decoration: 
              )),
          itemBuilder: (context, suggestion) {
            return ListTile(
              title: Text(''),
            );
          },
          noItemsFoundBuilder: (value) {
            var localizedMessage = "Parlez-vous Français!";
            return Text(localizedMessage);
          }, )

Answered By – Keita

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *