Ahmed Wagdi
Ahmed Wagdi

Reputation: 4371

How to make flutter SimpleAutoCompleteField suggest based on contains not startWith

I've used SimpleAutoCompleteTextField in my flutter project but am facing a problem of not being suggestions the right suggestions unless I started to type the beginning of the word not from the middle of it .. example:

When I am looking for the word "Astalavista", if I type "asta" it will be suggested but if I typed "lavis" it won't be suggested, I need to fix this out.

Here is my code :

                            child: SimpleAutoCompleteTextField(
                              key: endKey,
                              decoration: InputDecoration(
                                  filled: true,
                                  fillColor: Colors.white,
                                  hintText: S.of(context).end_location_hint),
                              controller: endLocationTextEditingController,
                              suggestions: suggestions,
                              textChanged: (text) => currentText = text,
                              clearOnSubmit: true,
                              textSubmitted: (text) async {
                                await movingCameraToLocation(
                                    double.parse(
                                        allStations[suggestions.indexOf(text)]
                                            .stationLatitude),
                                    double.parse(
                                        allStations[suggestions.indexOf(text)]
                                            .stationLongitude));
                                toLocationName = text;
                                setState(() {});
                              },
                            ),

Upvotes: 0

Views: 162

Answers (1)

SempaiLeo
SempaiLeo

Reputation: 344

Try adding the filter parameter, im not sure if it can be used with SimpleAutoCompleteTextField, but the official documentation states that "itemFilter" parameter can be used with AutoCompleteTextField <String>(),

Your filter would be :

itemFilter: (suggestion, input) =>
          suggestion.toLowerCase().contains(input.toLowerCase()),```

Upvotes: 1

Related Questions