Skip to content

Avoid using a Key whose only purpose is to be looked up in a test#170952

Merged
auto-submit[bot] merged 5 commits intoflutter:masterfrom
justinmc:no-keys
Jun 26, 2025
Merged

Avoid using a Key whose only purpose is to be looked up in a test#170952
auto-submit[bot] merged 5 commits intoflutter:masterfrom
justinmc:no-keys

Conversation

@justinmc
Copy link
Contributor

@justinmc justinmc commented Jun 20, 2025

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).

There is one more to get in snackbar.dart.
@justinmc justinmc self-assigned this Jun 20, 2025
@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 20, 2025
@AhmedLSayed9
Copy link
Contributor

This should also be updated at:

matching: find.byKey(const Key('menu item padding')),

As well, one more key time-picker-dial used for TimePickerDialog.

@justinmc justinmc marked this pull request as ready for review June 24, 2025 17:43
@justinmc
Copy link
Contributor Author

@jtmcdole proposed enforcing this via a lint rule or something like that. Issue here: #171099

@github-actions github-actions bot added the a: internationalization Supporting other languages or locales. (aka i18n) label Jun 24, 2025
@justinmc justinmc changed the title No Keys for tests? Avoid using a Key whose only purpose is to be looked up in a test Jun 25, 2025
@dkwingsmt dkwingsmt self-requested a review June 25, 2025 18:34
Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome change!

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Jun 25, 2025

Honestly I think we should forbid any key literals in our widget implementation. Considering how your title is phrased, are there any other key literals left?

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 26, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 26, 2025
@justinmc
Copy link
Contributor Author

@dkwingsmt Good point, I've opened #171249 to track this. It looks like there are a couple more that we could probably refactor.

Merged via the queue into flutter:master with commit 142cce6 Jun 26, 2025
71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 26, 2025
@justinmc justinmc deleted the no-keys branch June 26, 2025 23:54
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 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 1, 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).
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: internationalization Supporting other languages or locales. (aka i18n) 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.

3 participants