-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Reland [#166645] Fix DropdownButtonFormField focusing when replacing FocusNode #170761
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
Reland [#166645] Fix DropdownButtonFormField focusing when replacing FocusNode #170761
Conversation
…xternal FocusNode
justinmc
left a comment
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.
Thanks for following up after this was reverted. Looks like CI is indeed catching a failure here that will need to be fixed before we can reland.
| ); | ||
|
|
||
| await tester.pumpWidget(buildFormField()); | ||
| final FocusNode internalNode = tester.widget<Focus>(find.byType(Focus).last).focusNode!; |
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.
Actually the failure seems to be coming from here.
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.
That’s true. I’m not sure what changed that caused it to fail.
Anyway, I’ve updated it to use find.byKey to access the DropdownButton’s focusNode.
justinmc
left a comment
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.
What do you think about looking up via descendant instead of key? Otherwise looks good.
|
|
||
| await tester.pumpWidget(buildFormField()); | ||
| final FocusNode internalNode = | ||
| tester.widget<Focus>(find.byKey(const Key('dropdown-focus'))).focusNode!; |
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.
My gut says we should avoid this pattern so we don't end up having key collisions with keys in people's app codebases. Though searching through the codebase it looks like we do use this pattern in a few places, e.g. in PopupMenu.
But I think something like this is a better approach:
find.descendant(
of: find.byType(DropdownButton),
matching: find.byType(Focus),
);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.
Maybe we shouldn't do this in the framework at all? #170952
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.
Yes, I totally agree since using descendant is safe and reliable enough.
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.
Well, there are two things to note here:
1- We should specify the type as DropdownButton<String>.
2- We have to use .first because there are multiple Focus widgets under DropdownButton.
I'll push the update anyway, and if using .first turns out to be unreliable, we can revert it.
justinmc
left a comment
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.
LGTM 👍 . Thanks for changing the key thing. I agree the .first is not ideal but I think it's better than the key. I'll follow up on my #170952 PR.
…70952) This PR investigates moving away from the few places where we rely on Keys to instead solely look up a widget in a test. Reasons: * No extra stuff in users' apps that they don't need for production. * Avoid collisions between Keys in users' apps that might have the same identifier string. I'm definitely still up for discussion on whether or not this is a good idea! Written in response to the discussion on #170761 (comment).
bleroux
left a comment
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.
LGTM! Thanks for this reland 🙏
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…utter#170952) This PR investigates moving away from the few places where we rely on Keys to instead solely look up a widget in a test. Reasons: * No extra stuff in users' apps that they don't need for production. * Avoid collisions between Keys in users' apps that might have the same identifier string. I'm definitely still up for discussion on whether or not this is a good idea! Written in response to the discussion on flutter#170761 (comment).
…lacing FocusNode (flutter#170761) This is a reland of flutter#166645 fixes flutter#166642 **The newly added tests verify the following behaviors:** 1. DropdownButtonFormField can be focused if it was unfocused and we replaced FocusNode. 2. DropdownButtonFormField can be unfocused if it was focused and we replaced FocusNode. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…replacing FocusNode (flutter/flutter#170761)
…utter#170952) This PR investigates moving away from the few places where we rely on Keys to instead solely look up a widget in a test. Reasons: * No extra stuff in users' apps that they don't need for production. * Avoid collisions between Keys in users' apps that might have the same identifier string. I'm definitely still up for discussion on whether or not this is a good idea! Written in response to the discussion on flutter#170761 (comment).
…lacing FocusNode (flutter#170761) This is a reland of flutter#166645 fixes flutter#166642 **The newly added tests verify the following behaviors:** 1. DropdownButtonFormField can be focused if it was unfocused and we replaced FocusNode. 2. DropdownButtonFormField can be unfocused if it was focused and we replaced FocusNode. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
This is a reland of #166645
fixes #166642
The newly added tests verify the following behaviors:
Pre-launch Checklist
///).