Skip to content

Commit c19756f

Browse files
Suggestion box should close on selectionj
1 parent 6c0cf93 commit c19756f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/reactive_flutter_typeahead/lib/src/reactive_typeahead.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class ReactiveTypeAhead<T, V> extends ReactiveFormField<T, V> {
136136

137137
state._setFocusNode(focusNode);
138138
final controller = textEditingController ?? state._textController;
139+
final fieldSuggestionsController =
140+
suggestionsController ?? state._suggestionsController;
139141
if (field.value != null) {
140142
controller.text = stringify(field.value as V);
141143
}
@@ -147,6 +149,7 @@ class ReactiveTypeAhead<T, V> extends ReactiveFormField<T, V> {
147149
controller.text = stringify(value);
148150
field.didChange(value);
149151
onSuggestionSelected?.call(value);
152+
fieldSuggestionsController.close(); // close the suggestions box
150153
},
151154
builder: (context, controller, focusNode) {
152155
// Keep the selected value in the text field
@@ -186,7 +189,7 @@ class ReactiveTypeAhead<T, V> extends ReactiveFormField<T, V> {
186189
},
187190
decorationBuilder: decorationBuilder,
188191
debounceDuration: debounceDuration,
189-
suggestionsController: suggestionsController,
192+
suggestionsController: fieldSuggestionsController,
190193
loadingBuilder: loadingBuilder,
191194
emptyBuilder: emptyBuilder,
192195
errorBuilder: errorBuilder,
@@ -217,6 +220,8 @@ class ReactiveTypeAhead<T, V> extends ReactiveFormField<T, V> {
217220

218221
class _ReactiveTypeaheadState<T, V> extends ReactiveFormFieldState<T, V> {
219222
late TextEditingController _textController;
223+
late SuggestionsController<V> _suggestionsController;
224+
220225
FocusNode? _focusNode;
221226
late FocusController _focusController;
222227

@@ -226,6 +231,7 @@ class _ReactiveTypeaheadState<T, V> extends ReactiveFormFieldState<T, V> {
226231
@override
227232
void initState() {
228233
super.initState();
234+
_suggestionsController = SuggestionsController<V>();
229235

230236
final initialValue = value;
231237
_textController = TextEditingController(

0 commit comments

Comments
 (0)