-
Notifications
You must be signed in to change notification settings - Fork 28.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make DropdownMenu
TextField reactive to label changes
#162062
base: master
Are you sure you want to change the base?
Make DropdownMenu
TextField reactive to label changes
#162062
Conversation
492f6e4
to
2ad98b7
Compare
2ad98b7
to
c589b11
Compare
Sorry for the late response! I will take a look at this change asap! |
@QuncCccccc Is this PR still on the radar? |
Yes! Will take a look this week! Really appreciate your patience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really appreciated your patience and thanks so much for helping add the fix. I just added my thoughts and comments below:)
expect(controller.text, 'Updated label 1'); | ||
}); | ||
|
||
testWidgets('Do not rematch selection if its value maps to multiple entries', ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may happen rarely because I think usually the entry values are unique? We can match the first matching value or do not rematch. I'm okay with either way:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could match against the first entry only, and it would be the same behavior as initialSelection
.
The only downfall would be not being able to show different labels for the same value. It doesn't seem like a big deal because it's not how we normally use 'DropdownMenu` but it may break what some people expect, and some golden tests too.
Edit:
I would opt for rematching the first occurrence of a valid label but keeping the flag and specifying such behavior in its description.
c589b11
to
54a0dc2
Compare
DropdownMenu
automatic matchingDropdownMenu
TextField reactive to label changes
54a0dc2
to
e583b75
Compare
Hello @QuncCccccc, I made changes based on your notes, check 'em out. |
e583b75
to
854c11a
Compare
The current behavior of Flutter regarding
DropdownMenu
text field is very basic:DropdownMenu
updates the text field once a selection has been made with its coordinatinglabel
, and nothing more.If the selection's
label
changes, the text field will still show the old value, although the menu buttons have been updated.This not only results in the need to write a lot of boilerplate code to match the label to the current selection, but it's also counterintuitive. The
DropdownMenu
should handle rematching by itself.Issue #155660, touched on this, and a solution was introduced in #155757. It was later reverted due to it restricting some use cases. That issue & solution, however, only address
initialSelection
. If another selection was made and its correspondinglabel
was changed, the text field would still show the old value, bringing us back to square one.Proposal
We need to add a new variable to store additional information.
_lastLocalTextEditingValueObject
: stores the lastTextEditingValue
that was created by making a new selection. This is necessary to not overwrite the text filed when modified by an external controller or searching.Logic
This PR should not conflict with any previous behavior of
DropdownMenu
: any new value provided byinitialSelection
or via controller would not be overwritten by rematching. However, entries with the same value will be mapped to a single label (the first matched entry's label).If no matching was found
_lastLocalTextEditingValueObject
would be set tonull
.Related Issues
Tests
Added 3 tests.
Pre-launch Checklist
///
).