Skip to content

Conversation

@AhmedLSayed9
Copy link
Contributor

This is a reland of #166645

fixes #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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jun 17, 2025
@dkwingsmt dkwingsmt requested a review from justinmc June 18, 2025 18:22
Copy link
Contributor

@justinmc justinmc left a 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!;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@AhmedLSayed9 AhmedLSayed9 requested a review from justinmc June 18, 2025 23:30
Copy link
Contributor

@justinmc justinmc left a 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!;
Copy link
Contributor

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),
);

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@AhmedLSayed9 AhmedLSayed9 requested a review from justinmc June 21, 2025 04:09
Copy link
Contributor

@justinmc justinmc left a 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.

@justinmc justinmc requested a review from bleroux June 24, 2025 17:17
github-merge-queue bot pushed a commit that referenced this pull request Jun 26, 2025
…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).
Copy link
Contributor

@bleroux bleroux left a 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 🙏

@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 27, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 27, 2025
Merged via the queue into flutter:master with commit 05add65 Jun 27, 2025
71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 27, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 7, 2025
mboetger pushed a commit to mboetger/flutter that referenced this pull request Jul 21, 2025
…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).
mboetger pushed a commit to mboetger/flutter that referenced this pull request Jul 21, 2025
…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.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
…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).
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DropdownButtonFormField can't be focused/unfocused when replacing FocusNode

3 participants