Skip to content

Commit 0a8dd49

Browse files
authored
Merge pull request #906 from wger-project/fix/fix-debounce-time
Don't hammer the server with search requests
2 parents d1d6392 + af482ab commit 0a8dd49

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/widgets/exercises/autocompleter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class _ExerciseAutocompleterState extends State<ExerciseAutocompleter> {
3030
children: [
3131
TypeAheadField<Exercise>(
3232
key: const Key('field-typeahead'),
33+
debounceDuration: const Duration(milliseconds: 500),
3334
decorationBuilder: (context, child) {
3435
return Material(
3536
type: MaterialType.card,

lib/widgets/nutrition/widgets.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
113113
children: [
114114
TypeAheadField<IngredientApiSearchEntry>(
115115
controller: widget._ingredientController,
116+
debounceDuration: const Duration(milliseconds: 500),
116117
builder: (context, controller, focusNode) {
117118
return TextFormField(
118119
controller: controller,
@@ -124,11 +125,6 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
124125
}
125126
return null;
126127
},
127-
onChanged: (value) {
128-
widget.updateSearchQuery(value);
129-
// unselect to start a new search
130-
widget.unSelectIngredient();
131-
},
132128
decoration: InputDecoration(
133129
prefixIcon: const Icon(Icons.search),
134130
labelText: AppLocalizations.of(context).searchIngredient,
@@ -142,6 +138,10 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
142138
return null;
143139
}
144140

141+
widget.updateSearchQuery(pattern);
142+
// unselect to start a new search
143+
widget.unSelectIngredient();
144+
145145
return Provider.of<NutritionPlansProvider>(context, listen: false).searchIngredient(
146146
pattern,
147147
languageCode: Localizations.localeOf(context).languageCode,

0 commit comments

Comments
 (0)