Skip to content

Commit

Permalink
In the search field, when a suggestion is selected, the loader should…
Browse files Browse the repository at this point in the history
… not be visible
  • Loading branch information
g123k committed Jan 29, 2024
1 parent acbe694 commit e7b7a1b
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class _SmoothAutocompleteTextFieldState
extends State<SmoothAutocompleteTextField> {
final Map<String, _SearchResults> _suggestions = <String, _SearchResults>{};
bool _loading = false;
String? _selectedSearch;

late _DebouncedTextEditingController _debouncedController;

Expand Down Expand Up @@ -71,6 +72,7 @@ class _SmoothAutocompleteTextFieldState
VoidCallback onFieldSubmitted) =>
TextField(
controller: widget.controller,
onChanged: (_) => setState(() => _selectedSearch = null),
decoration: InputDecoration(
filled: true,
border: const OutlineInputBorder(
Expand All @@ -97,6 +99,10 @@ class _SmoothAutocompleteTextFieldState
autofocus: false,
focusNode: focusNode,
),
onSelected: (String search) {
_selectedSearch = search;
_setLoading(false);
},
optionsViewBuilder: (
BuildContext lContext,
AutocompleteOnSelected<String> onSelected,
Expand Down Expand Up @@ -140,6 +146,10 @@ class _SmoothAutocompleteTextFieldState
}

Future<_SearchResults> _getSuggestions(String search) async {
if (search == _selectedSearch) {
return _SearchResults.empty();
}

final DateTime start = DateTime.now();

if (_suggestions[search] != null) {
Expand Down

0 comments on commit e7b7a1b

Please sign in to comment.