diff --git a/lib/src/text_field/base_text_field.dart b/lib/src/text_field/base_text_field.dart index 5fd797e..ba0046b 100644 --- a/lib/src/text_field/base_text_field.dart +++ b/lib/src/text_field/base_text_field.dart @@ -118,6 +118,15 @@ class BaseTextFieldState extends State @visibleForTesting FocusNode get focusNode => _focusNode; + // We previous used the onChange event from the [TextFormField], since adding a listener to the [TextEditingController] is also called + // when we focus / unfocus the [TextFormField]. + // 💾 This was the previous documentation: + // 💾 use onChange instead of [TextEditingController.addListener] + // 💾 because this will notify a text change when we loose focus + // 💾 when routing back. This will trigger a new search which is wrong. + // Since we now use the listener, we need to distinct the value by ourself. + late String _previousTextValue = widget.text; + bool _textFieldIsValid = true; @override @@ -241,6 +250,10 @@ class BaseTextFieldState extends State } void _onChanged(String value) { + if (_previousTextValue == value) return; + + _previousTextValue = value; + // we always want to validate the new input when the current state is invalid if (!_textFieldIsValid) { _formFieldKey.currentState?.validate();