Comments (15)
I had to add this to the AutoCompleteTextField properties even though it's not marked as required:
onFocusChanged: (hasFocus) {},
from flutter-autocomplete-textfield.
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.
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.
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.
I got the same error.
from flutter-autocomplete-textfield.
Same here
from flutter-autocomplete-textfield.
I'm facing the same issue here.
from flutter-autocomplete-textfield.
Has anyone found a solution?
from flutter-autocomplete-textfield.
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.
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.
I'll look into it. Thanks.
from flutter-autocomplete-textfield.
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.
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.
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.
Before (dialog won't dismiss)
After using onFocusChanged: (hasFocus) {},
from flutter-autocomplete-textfield.
Related Issues (20)
- Close Keyboard Issue.
- Show suggestions on focus - without typing anything HOT 1
- How to use overflow?
- Is there a way to use Stream suggestions from firebase? HOT 2
- Scroll issue & Instance of issue.
- Where is the selected item stored? HOT 1
- Support null-safety HOT 10
- Suggestion's Position HOT 4
- how do i make thr text filtering non case sesitivite but the value remains the same in the suggestions i.e retains its case HOT 1
- Supports Null safety HOT 3
- Diable Field HOT 1
- Please mark this repository as Not Maintained as it is dead since 2019
- Error in example given on pub.dev HOT 1
- sufix icon on focus disappear HOT 2
- Cannot run with sound null safety for ios build in xcode 12.5.1 for Compile and run HOT 1
- Support Null Safety HOT 1
- Problems for flutter 3.7 on web HOT 2
- Controller is not getting updated on textsubmitted HOT 1
- Material 3
- textSubmitted, itemSubmitted is not calling in flutter web and desktop app.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter-autocomplete-textfield.