Skip to content

Commit

Permalink
[Presentation] Properly trigger the search changed event
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Nov 2, 2022
1 parent 138734d commit bd0b8b3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/presentation/shared/search_box.dart
Expand Up @@ -23,11 +23,13 @@ class SearchBox extends StatefulWidget {

class _SearchBoxState extends State<SearchBox> {
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);
}
Expand Down Expand Up @@ -86,7 +88,14 @@ class _SearchBoxState extends State<SearchBox> {
);
}

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();
Expand Down

0 comments on commit bd0b8b3

Please sign in to comment.