[EditableText] Fix TextField crashed with composing and maxLength set#63754
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
|
Hey I am very new to contributing , I have read documentations but I am still confused that how to proceed |
|
Looks like this change is causing some tests to fail: https://cirrus-ci.com/task/4806069081866240. This can either mean you're breaking existing functionality or the tests need to be updated. Can you please take a look at those? Also, in order to accept this PR you will have to write a test to ensure that we never regress and accidentally re-introduce the bug into our code base. Can you please add some tests? /cc @justinmc |
|
Yeah I just forgot to put this into WIP. |
|
@cv692001 I'm not sure if you're asking in relation to this PR, but if you're just asking about contributing in general, feel free to reach out to me via the contact info in my Github profile. |
|
@goderbauer @justinmc I have a question about using the tester to simulate the composing input. I wrote something like this: final EditableTextState state =
tester.state<EditableTextState>(find.byType(EditableText));
state.updateEditingValue(const TextEditingValue(text: '111 1'));
expect(state.currentTextEditingValue.composing, TextRange.empty);
state.updateEditingValue(const TextEditingValue(text: '111 1', composing: TextRange(start: 2, end: 4)));
expect(state.currentTextEditingValue.composing, const TextRange(start: 2, end: 4));
state.updateEditingValue(const TextEditingValue(text: '111 11', composing: TextRange(start: 2, end: 5)));
expect(state.currentTextEditingValue.composing, const TextRange(start: 2, end: 5));When I tried to add more text with composing like '111 11' (6 characters) it ends up nothing happened. How can I achieve the effect just like the real device's? (Like the screenshot below) |
|
Forget about it. I forgot that I run this on stable, now it works on the new one. |
justinmc
left a comment
There was a problem hiding this comment.
Thanks for fixing this! I confirmed that this fixes the problem for me locally and that the test fails without the fix.
Just one small change on a comment.
I had noticed this problem previously in #35106 and I imagined that something like this behavior would be the best solution. I've added that issue to the description of this PR, because I think it fixes that too.
We should watch out for this causing any undesirable behavior in any existing Flutter apps. For example, with this PR, it's now possible to get an invalid value from a TextField using textFieldController.text. That may cause some Flutter apps to receive invalid values when they previously could not, if they're not checking the valid state of the form.
LongCatIsLooong
left a comment
There was a problem hiding this comment.
IMO we shouldn't specialize LengthLimitingTextInputFormatter. The fix should be applied to the implementation of that formatter if possible.
@justinmc it makes sense to me for the length of the text to transiently surpass the limit if there's composing text. The user should be able to input the same thing using IME as they can with copy paste. But I think this is going to be an issue if the user submits the text without finalizing the composing text.
Other input formatters (even third party ones) may have this issue too, @AlexV525 did you by any chance look into why it crashes?
@justinmc I'll see if I can add a test to ensure it won't happened.
@LongCatIsLooong That make sense. But last night I was thinking about this, should we prevent all formatters update while composing?
Basically when the composing editing value is updated by the formatter, the composing Let's go back to the crashing screenshot. Such as |
It's done. |
|
Now the changes are both landed on |
The last thing is about this concern. For me, technically, it should be the current value whether it's composing or not. I added a test about form validation when the value composing. Although it can return |
|
I've updated the description for behavior changes. |
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍 Just a quick grammar fix in a comment below.
It looks like Windows_tool_tests is failing, but it seems unrelated. I tried rerunning it, but if it doesn't pass, it might be necessary to update the branch with master.
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
|
Oops, seems run into a CLA issue, can you check this out? @justinmc |
76bce4b to
4a750f5
Compare
|
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
…extfield-maxlength-crash
|
(knock knock...) |
justinmc
left a comment
There was a problem hiding this comment.
LGTM 👍
This should be merged when the build is green. Thanks for all the work on this!


Description
This is a fix for
EditableTextandLengthLimitingTextInputFormatter, several behaviors updated._formatAndSetValuenow detects the composing changes and update normally.maxLength(LengthLimitingTextInputFormatter) 's constraint will be temporary lifted if the value is composing.Without this fix, apps will crash if they triggered any strange composing delete. It happens from flutter
1.0.0until now.Related Issues
Resolves #63753
Resolves #35106
Resolves #25511
Tests
I added the following tests:
Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change