From bd0b8b32879d8e6aaf41a439b50e976e8630ab44 Mon Sep 17 00:00:00 2001 From: Efrain Bastidas Date: Tue, 1 Nov 2022 21:18:00 -0500 Subject: [PATCH] [Presentation] Properly trigger the search changed event --- lib/presentation/shared/search_box.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/presentation/shared/search_box.dart b/lib/presentation/shared/search_box.dart index 6da03e099..244a81120 100644 --- a/lib/presentation/shared/search_box.dart +++ b/lib/presentation/shared/search_box.dart @@ -23,11 +23,13 @@ class SearchBox extends StatefulWidget { class _SearchBoxState extends State { final _searchFocusNode = FocusNode(); + late String? _currentValue; late TextEditingController _searchBoxTextController; @override void initState() { super.initState(); + _currentValue = widget.value ?? ''; _searchBoxTextController = TextEditingController(text: widget.value); _searchBoxTextController.addListener(_onSearchTextChanged); } @@ -86,7 +88,14 @@ class _SearchBoxState extends State { ); } - void _onSearchTextChanged() => widget.searchChanged(_searchBoxTextController.text); + void _onSearchTextChanged() { + //Focusing the text field triggers text changed, that why we used it like this + if (_currentValue == _searchBoxTextController.text) { + return; + } + _currentValue = _searchBoxTextController.text; + widget.searchChanged(_searchBoxTextController.text); + } void _cleanSearchText() { _searchFocusNode.requestFocus();