felixmccuaig / flutter-autocomplete-textfield

An autocomplete Textfield for flutter
MIT License
181 stars 131 forks source link

overlay not collapsing upon selection after updateSuggestions #64

Open marcelser opened 4 years ago

marcelser commented 4 years ago

Hi,

I'm using AutoCompleteTextField in a StatefulWidget and have defined a function to initialize it like this:

_buildTextField() { textField = new AutoCompleteTextField<Product>( decoration: new InputDecoration( labelText: "Produkt", hintText: "Produkt suchen", suffixIcon: new IconButton( icon: new Icon(Icons.add), onPressed: () async { await Navigator.push( context, MaterialPageRoute( builder: (context) => ProductEditScreen(), settings: RouteSettings(arguments: new Product(id: 0, name: autoCompleteController.text)), ) ).then((result) async { Product newproduct = result; setState(() { textField.addSuggestion(newproduct); autoCompleteController.text = newproduct.getName; }); }); }, ) ), itemSubmitted: (item) => setState(() => selectedItem(item)), controller: autoCompleteController, key: autoCompleteKey, suggestions: products, suggestionsAmount: 5, itemBuilder: (context, suggestion) => new Padding( child: new ListTile( title: new Text(suggestion.getName), trailing: new Text(suggestion.getPoints != null ? "Punkte: ${suggestion.getPoints}" : "")), padding: EdgeInsets.all(8.0)), itemSorter: (a, b) => a.getName.compareTo(b.getName), itemFilter: (suggestion, input) => suggestion.getName.toLowerCase().contains(input.toLowerCase()), clearOnSubmit: false, ); }

The problem occurs when the suggestions are updated in the "OnTap" of IconButton in the ListTile on return of the widget which is called to add a new "Product" entry.

What works is that the suggestion is properly updated and shown in the overlay. What is broken is two things. First the currentText is wiped out and second when tapping on the newly created entry in the overlay it get's selected but the overlay doesn't close and stays open after selection even after clicking on another Widget in the same screen. To make it go away I have to type something in the autocomplete and then click somewhere else.

XF9 commented 4 years ago

Hi, I kinda have the same problem with updateDecoration(). The overlay won't close until I type something and click somewhere else.

class SimpleAutoCompleteTextFormField extends FormField<String> {
  [..]
}) : super(
  builder: (FormFieldState<String> state) {
    [..]
    final autoCompleteField = SimpleAutoCompleteTextField(
      key: automcompleteKey,
      [..]
    )
    if(automcompleteKey.currentState != null)
      autoCompleteField.updateDecoration(
        decoration: effectiveDecoration
      );
);
Karlheinzniebuhr commented 3 years ago

having the same problem, the overlay pops up when I call updateSuggestions() Any suggestions?