flutterdarttypeahead

Is there a way to not show the user input as a suggestion using Flutter typeahead?


I am using flutter typeahead to suggest options to a user based on their text input. When entering any input, the first suggestion is always just what the user types. I would like to restrict this to just suggestions retrieved from the backend, and this is getting in the way of that. Is there a solution?

Widget get typeAheadField{
    return SingleChildScrollView (
      child: TypeAheadField(
        //autoFlipDirection: true,
        hideOnEmpty: true,
        hideOnLoading: true,
        minCharsForSuggestions: 1,
        getImmediateSuggestions: false,
        direction: AxisDirection.up,
        keepSuggestionsOnLoading: false,
        textFieldConfiguration: TextFieldConfiguration(
          textAlign: TextAlign.center,
          autofocus: true,
          style: DefaultTextStyle.of(context).style.copyWith(
            color: Colors.white,
            fontSize: 20.0,
          ),
          decoration: InputDecoration(
            hintText: "Tag Friends: ",
            hintStyle: TextStyle(color: Colors.grey, fontSize: 20.0,),
            border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(12.0),
              borderSide: const BorderSide(
                color: Colors.white,
                width: 2.0,
              ),
            ),
            ),
          ),
        suggestionsCallback: getSuggestions,
        itemBuilder: (context, suggestion) {
          return getList(context, suggestion);
        },
        onSuggestionSelected: (suggestion) {
          addUser(suggestion);
        },
      )
    );
  }

Solution

  • replace return getList(context, suggestion); with

    List<String> newSuggestions=suggestion.where((e)=>e!= "the user input from the controller " ) ).toList() ;
    return getList(context, newSuggestions);