Skip to content

Commit

Permalink
add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanschaller committed May 14, 2024
1 parent 50d9278 commit 47b8ee3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/text_field/base_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ class BaseTextFieldState extends State<BaseTextField>
@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
Expand Down Expand Up @@ -241,6 +250,10 @@ class BaseTextFieldState extends State<BaseTextField>
}

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

0 comments on commit 47b8ee3

Please sign in to comment.