Closed pranayairan closed 5 years ago
Umm yeah, this should most definitely be possible. Just give each autocomplete text field its own global key and you'll be fine.
GlobalKey<AutoCompleteTextFieldState<String>> key1 = new GlobalKey(); //Key for textfield one GlobalKey<AutoCompleteTextFieldState<String>> key2 = new GlobalKey(); //Key for textfield two
I tried this but it throws an exception
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: The following assertion was thrown building
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: FancyAutoCompleteTextField-[LabeledGlobalKey<AutoCompleteTextFieldState<String>>#809e7](state:
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: _FancyAutoCompleteTextFieldState#47758):
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: Multiple widgets used the same GlobalKey.
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: The key [LabeledGlobalKey<AutoCompleteTextFieldState<String>>#809e7] was used by multiple widgets.
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: The parents of those widgets were:
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: - Semantics(container: false, properties: SemanticsProperties, label: null, value: null, hint: null,
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: hintOverrides: null, renderObject: RenderSemanticsAnnotations#d5887 NEEDS-LAYOUT NEEDS-PAINT)
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: - Padding(padding: EdgeInsets(4.0, 0.0, 4.0, 0.0), renderObject: RenderPadding#e4d36 NEEDS-LAYOUT
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: NEEDS-PAINT)
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: A GlobalKey can only be specified on one widget at a time in the widget tree.
2018-10-22 07:30:43.149 28048-28064/dexterapps.bankifscflutter I/flutter: Multiple widgets used the same GlobalKey.
This line states multiple widgets are using the same key. here seems like a good overview of how globalkey works in Flutter.
thanks,
I am actually using it in a diff way, i created another widget on top of autoComplete widget, due to this i am not able to pass multiple global keys, since doing GlobalKey<AutoCompleteTextFieldState
If you're subclassing the AutoCompleteTextField, you'll need to implement the necessary implementations.
Hi thanks for this amazing library, I was having an issue while using it and want to check if anyone knows how to solve.
I want to use the 2-3 autocomplete text fields on the same screen. But when I add it and run the app, I get the error
Multiple widgets used the same GlobalKey.
This happens because the global key which is a required field cannot be used for more than 1 widget. There is a workaround by declaring our own key https://stackoverflow.com/questions/49862572/multiple-widgets-used-the-same-globalkey but autocomplete textfield do a type check and the above solution doesn't work.
For my use case, I am not using clear, is it possible to not make key required for such use cases? or is there any other suggestion.