Giter Site home page Giter Site logo

Comments (15)

LordLaser avatar LordLaser commented on May 30, 2024 8

I had to add this to the AutoCompleteTextField properties even though it's not marked as required:

onFocusChanged: (hasFocus) {},

from flutter-autocomplete-textfield.

aleaforny avatar aleaforny commented on May 30, 2024 1

I have the same issue, the suggestions won't disappear when selecting one. But no error is shown in the console. This issue happens with v 1.6.4 and 1.6.6

Have you tried to add the property onFocusChanged: (hasFocus) {} to your widget ?

from flutter-autocomplete-textfield.

Karlheinzniebuhr avatar Karlheinzniebuhr commented on May 30, 2024 1

I have the same issue, the suggestions won't disappear when selecting one. But no error is shown in the console. This issue happens with v 1.6.4 and 1.6.6

Have you tried to add the property onFocusChanged: (hasFocus) {} to your widget ?

That solved the issue, thanks!

from flutter-autocomplete-textfield.

banfger avatar banfger commented on May 30, 2024 1

onFocusChanged: (hasFocus) {} did nothing for me. But looking into the source code, I could solve it.

In the updateOverlay function selecting the text does not result in an update, so I changed it to this:

onTap: () {
   setState(() {
      if (submitOnSuggestionTap) {
         String newText = suggestion.toString();
         textField.controller.text = newText;
         textField.focusNode.unfocus();
         itemSubmitted(suggestion);
         if (clearOnSubmit) {
            clear();
         }
         else{
            updateOverlay();
         }
     }
     else {
        String newText = suggestion.toString();
        textField.controller.text = newText;
        textChanged(newText);
        updateOverlay();
    }
   });
}

Now after selecting a suggestion the dialog disappears. But if you click in the textfield again, the new suggestions are the same as the ones that were suggested at the time you selected the current value. What should appear are the suggestions for the submitted value, so itself. It is solved if I add currentText = newText like this:

onTap: () {
   setState(() {
      if (submitOnSuggestionTap) {
         String newText = suggestion.toString();
         textField.controller.text = newText;
         textField.focusNode.unfocus();
         itemSubmitted(suggestion);
         if (clearOnSubmit) {
            clear();
         }
         else{
            currentText = newText;
            updateOverlay();
         }
     }
     else {
        String newText = suggestion.toString();
        textField.controller.text = newText;
        currentText = newText;
        textChanged(newText);
        updateOverlay();
    }
   });
}

And lastly, somehow after a decoration update the textfield loses it's focusNode and it's listener. I simply changed the updateDecoration function by adding the listener again if the focusNode null, and it is good for me.

setState(() {
      if(focusNode == null){
        focusNode = new FocusNode()..addListener(() {
          if (onFocusChanged != null) {
            onFocusChanged(textField.focusNode.hasFocus);
          }
          if (!textField.focusNode.hasFocus) {
            filteredSuggestions = [];
            updateOverlay();
          }
          else if (!(currentText == "" || currentText == null)) {
            updateOverlay(currentText);
          }
        });
      }

      textField = new TextField(
        inputFormatters: this.inputFormatters,
        textCapitalization: this.textCapitalization,
        decoration: this.decoration,
        style: this.style,
        keyboardType: this.keyboardType,
        focusNode: focusNode ?? ?? FocusNode(),
        controller: controller ?? new TextEditingController(),
        textInputAction: this.textInputAction,
        onChanged: (newText) {
          currentText = newText;
          updateOverlay(newText);

          if (textChanged != null) {
            textChanged(newText);
          }
        },
        onTap: () {
          updateOverlay(currentText);
        },
        onSubmitted: (submittedText) =>
            triggerSubmitted(submittedText: submittedText),
      );
    });

from flutter-autocomplete-textfield.

mayurprajapati avatar mayurprajapati commented on May 30, 2024

I got the same error.

from flutter-autocomplete-textfield.

ahaboubi avatar ahaboubi commented on May 30, 2024

Same here

from flutter-autocomplete-textfield.

rmathias86 avatar rmathias86 commented on May 30, 2024

I'm facing the same issue here.

from flutter-autocomplete-textfield.

asrinagesh avatar asrinagesh commented on May 30, 2024

Has anyone found a solution?

from flutter-autocomplete-textfield.

rmathias86 avatar rmathias86 commented on May 30, 2024

Unfortunately, I haven't found a solution yet. I've decided to use this one
https://pub.dev/documentation/flutter_typeahead_plugin/latest/

from flutter-autocomplete-textfield.

Karlheinzniebuhr avatar Karlheinzniebuhr commented on May 30, 2024

I have the same issue, the suggestions won't disappear when selecting one. But no error is shown in the console. This issue happens with v 1.6.4 and 1.6.6

from flutter-autocomplete-textfield.

felixmccuaig avatar felixmccuaig commented on May 30, 2024

I'll look into it. Thanks.

from flutter-autocomplete-textfield.

felixmccuaig avatar felixmccuaig commented on May 30, 2024

I'm going to need a little bit more information to fix this issue, would you mind supplying some code which causes this error?

from flutter-autocomplete-textfield.

Karlheinzniebuhr avatar Karlheinzniebuhr commented on May 30, 2024

this is my code which was solved once I added hasFocus()

` asignSearchTextField = AutoCompleteTextField(
//style: new TextStyle(color: Colors.black, fontSize: 15.0),
decoration: InputDecoration(
// suffixIcon: Container(
// width: 85.0,
// height: 60.0,
// ),
filled: false,
//labelText: 'Asignar a',
hintText: 'Asignar a',
//hintStyle: TextStyle(color: Colors.black38),

      errorText: _validateAssignee ? 'Debe asignar a alguien' : null,
      prefixIcon: Icon(Icons.person),
    ),
    itemSubmitted: (item) {
      print('itemSubmitted');
      setState(() {
        _task.assignee_id = item.id;
        asignSearchTextField.textField.controller.text = item.username;
      });
    },
    onFocusChanged: (hasFocus) {},
    clearOnSubmit: false,
    submitOnSuggestionTap: true,
    key: key,
    suggestions: UsersViewModel.users ?? [],
    itemBuilder: (context, item) {
      print('itemBuilder');
      return Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Text(
            item.username,
            style: TextStyle(fontSize: 16.0),
          ),
          Padding(
            padding: EdgeInsets.all(15.0),
          ),
          Text(
            item.email,
            style: TextStyle(fontSize: 16.0),
          )
        ],
      );
    },
    minLength: 0,
    itemSorter: (a, b) {
      print('itemSorter');
      return a.username.compareTo(b.username);
    },
    itemFilter: (item, query) {
      print('itemFilter');
      return item.username.toLowerCase().startsWith(query.toLowerCase());
    });`

from flutter-autocomplete-textfield.

felixmccuaig avatar felixmccuaig commented on May 30, 2024

Thanks, however, I'm still not really understanding the dialog part. Is the TextField inside a dialog? Is the submit action creating/closing a dialog?

from flutter-autocomplete-textfield.

Karlheinzniebuhr avatar Karlheinzniebuhr commented on May 30, 2024

Before (dialog won't dismiss)

before

After using onFocusChanged: (hasFocus) {},

after

from flutter-autocomplete-textfield.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.