fix!: InputFilter
clears TextField
when an invalid character is entered
#3779
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3769
A custom
FilteringTextInputFormatter
has been created to prevent non-matching characters from causing the deletion of the whole field content.Breaking Change
Solving this issue resulted to a breaking change: most of the
regex_string
s must be updated to use anchors.Why?
This is caused by
RegExp.hasMatch()
allowing non-matching characters to be entered/visible (without replacement), as long as the field content contains a matching substring.Migration
Use start(
^
) and end($
) anchors in the pattern/regexString:r"[a-zA-Z]"
->r"^[a-zA-Z]*$"
r"[0-9]"
->r"^[0-9]*$"
In the above cases, the
*
is important, else it will be impossible to delete the last character in the field.AI Prompt
To ease migration, below is a simple prompt that can be useful:
Test Code
Type of change
Summary by Sourcery
Fix issue where
InputFilter
clearsTextField
when an invalid character is entered by introducingCustomFilteringTextInputFormatter
. This change requires updating mostregex_string
s to use start (^
) and end ($
) anchors to ensure proper matching.Bug Fixes:
InputFilter
from clearing the entireTextField
content when an invalid character is entered.Enhancements:
CustomFilteringTextInputFormatter
to handle input filtering with more control over regex patterns and matching behavior.