Repository navigation
[CP-beta]Add ContextMenuButtonKind - #195922
Conversation
part of flutter#193527 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [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 in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [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.
|
@reidbaker please fill out the PR description above, afterwards the release team will review this request. |
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request introduces ContextMenuButtonKind to replace ContextMenuButtonType, allowing new button kinds to be added without breaking exhaustive switches. It updates ContextMenuButtonItem to support both type and kind, migrating existing usages across EditableText, SelectableRegion, and SystemContextMenu. Feedback recommends refining ContextMenuButtonItem.copyWith to prevent losing precision when copying with an existing type on a custom kind (such as translate), and adding a corresponding test case to verify this behavior.
| test('copyWith accepts type or kind', () { | ||
| const item = ContextMenuButtonItem(onPressed: null, kind: ContextMenuButtonKind.copy); | ||
| expect(item.copyWith(kind: ContextMenuButtonKind.paste).kind, ContextMenuButtonKind.paste); | ||
| expect(item.copyWith(type: ContextMenuButtonType.cut).kind, ContextMenuButtonKind.cut); | ||
| expect(item.copyWith(label: 'hi').kind, ContextMenuButtonKind.copy); | ||
| }); |
There was a problem hiding this comment.
Add a test case to verify that copyWith preserves custom kinds (like translate) when called with the existing type.
test('copyWith accepts type or kind', () {
const item = ContextMenuButtonItem(onPressed: null, kind: ContextMenuButtonKind.copy);
expect(item.copyWith(kind: ContextMenuButtonKind.paste).kind, ContextMenuButtonKind.paste);
expect(item.copyWith(type: ContextMenuButtonType.cut).kind, ContextMenuButtonKind.cut);
expect(item.copyWith(label: 'hi').kind, ContextMenuButtonKind.copy);
const translateItem = ContextMenuButtonItem(onPressed: null, kind: ContextMenuButtonKind.translate);
expect(translateItem.copyWith(type: translateItem.type).kind, ContextMenuButtonKind.translate);
});|
@justinmc this was found by asking an agent to audit if we were ready to cut a stable and it found that we had different public api surfaces |
|
autosubmit label was removed for flutter/flutter/195922, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…lutter#194008) Reverts flutter#193550 and restores the no-shuffle tag definition in packages/flutter/dart_test.yaml on flutter-3.50-candidate.0, where Theme._kFallbackTheme platform caching (flutter#194008, fixed after branch cut in flutter#194256) causes 56 tests in text_field_test.dart to fail under shuffled test seeds such as 20261103.
| // fixed on master after the 3.50 branch cut in | ||
| // https://github.com/flutter/flutter/pull/194256), breaking theme-less | ||
| // TextField tests under shuffled seeds such as 20261103. | ||
| @Tags(<String>['reduced-test-set', 'no-shuffle']) |
There was a problem hiding this comment.
Bundling a 3.50-only revert of #193550 (plus the no-shuffle tag definition removed in #191499) to unblock framework_tests_libraries and framework_tests_impeller on flutter-3.50-candidate.0.
Under today's daily shuffle seed (--test-randomize-ordering-seed=20261103), Theme._kFallbackTheme caches the first test variant's defaultTargetPlatform (#194008, fixed on master after the 3.50 branch cut in #194256), breaking 56 theme-less TextField tests in this file.
063648e
into
flutter:flutter-3.50-candidate.0
This pull request is created by automatic cherry pick workflow
Cherry-pick of #193528 (already cherry-picked to
3.47.9stable in #195015, ensuring3.50does not regress public API shipped in3.47.9).Also includes
e58c176fe4/7d0aca2908(+12/-1, test-only) restoring theno-shuffletag onpackages/flutter/test/material/text_field_test.dart(reverting #193550 and restoringno-shuffleinpackages/flutter/dart_test.yaml) because3.50branched before #194256 fixed #194008 (Theme._kFallbackThemeplatform caching across shuffledTargetPlatformVarianttests).Issue Link:
#193527
#194008
Impact Description:
ContextMenuButtonKindandContextMenuButtonItem.kindshipped in Flutter3.47.9stable (#195015) afterflutter-3.50-candidate.0branched. Without cherry-picking#193528intoflutter-3.50-candidate.0, packages and apps adoptingContextMenuButtonKindon3.47.9stable (includingcupertino_uiandmaterial_uifor iOS Translate context menu support in#180021) would fail to compile on3.50.0. The change itself is purely additive and does not deprecateContextMenuButtonTypeor alter existing behavior. Restoringno-shuffleontext_field_test.dartunblocksframework_tests_librariesandMac framework_tests_impelleronflutter-3.50-candidate.0under daily shuffled test seeds.Changelog Description:
ContextMenuButtonType; adds the extensibleContextMenuButtonKind.Workaround:
No.
Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
Run
flutter test test/widgets/context_menu_button_item_test.dart test/widgets/editable_text_test.dart test/widgets/selectable_region_test.dart test/widgets/system_context_menu_test.dartandflutter test --test-randomize-ordering-seed=20261103 --fatal-warnings test/material/text_field_test.dartto verifyContextMenuButtonKindbackwards compatibility andtext_field_test.dartexecution under shuffled seeds.