Skip to content

[CP-beta]Add ContextMenuButtonKind - #195922

Merged
auto-submit[bot] merged 3 commits into
flutter:flutter-3.50-candidate.0from
flutteractionsbot:cp-beta-306a914a74c5d57958c6a3dc693bda51f295401d
Nov 3, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:flutter-3.50-candidate.0from
flutteractionsbot:cp-beta-306a914a74c5d57958c6a3dc693bda51f295401d

Conversation

@flutteractionsbot

@flutteractionsbot flutteractionsbot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is created by automatic cherry pick workflow

Cherry-pick of #193528 (already cherry-picked to 3.47.9 stable in #195015, ensuring 3.50 does not regress public API shipped in 3.47.9).

Also includes e58c176fe4 / 7d0aca2908 (+12/-1, test-only) restoring the no-shuffle tag on packages/flutter/test/material/text_field_test.dart (reverting #193550 and restoring no-shuffle in packages/flutter/dart_test.yaml) because 3.50 branched before #194256 fixed #194008 (Theme._kFallbackTheme platform caching across shuffled TargetPlatformVariant tests).

Issue Link:

#193527
#194008

Impact Description:

ContextMenuButtonKind and ContextMenuButtonItem.kind shipped in Flutter 3.47.9 stable (#195015) after flutter-3.50-candidate.0 branched. Without cherry-picking #193528 into flutter-3.50-candidate.0, packages and apps adopting ContextMenuButtonKind on 3.47.9 stable (including cupertino_ui and material_ui for iOS Translate context menu support in #180021) would fail to compile on 3.50.0. The change itself is purely additive and does not deprecate ContextMenuButtonType or alter existing behavior. Restoring no-shuffle on text_field_test.dart unblocks framework_tests_libraries and Mac framework_tests_impeller on flutter-3.50-candidate.0 under daily shuffled test seeds.

Changelog Description:

  • flutter/193527 When building custom text selection menus, packages can't add new actions such as Translate without breaking exhaustive switches on ContextMenuButtonType; adds the extensible ContextMenuButtonKind.

Workaround:

No.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

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.dart and flutter test --test-randomize-ordering-seed=20261103 --fatal-warnings test/material/text_field_test.dart to verify ContextMenuButtonKind backwards compatibility and text_field_test.dart execution under shuffled seeds.

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.
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Nov 3, 2026
@flutteractionsbot

Copy link
Copy Markdown
Contributor Author

@reidbaker please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Nov 3, 2026
@flutter-dashboard

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +46 to +51
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);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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
justinmc previously approved these changes Nov 3, 2026

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah I guess we need this on beta too. LGTM similar to #195015 👍

reidbaker
reidbaker previously approved these changes Nov 3, 2026
@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 3, 2026
@reidbaker

Copy link
Copy Markdown
Member

@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

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 3, 2026
@auto-submit

auto-submit Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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.
@reidbaker
reidbaker dismissed stale reviews from justinmc and themself via e58c176 November 3, 2026 19:06
@reidbaker
reidbaker requested a review from justinmc November 3, 2026 19:07
// 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'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Nov 3, 2026
@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 3, 2026
@auto-submit
auto-submit Bot merged commit 063648e into flutter:flutter-3.50-candidate.0 Nov 3, 2026
8 checks passed
@flutteractionsbot
flutteractionsbot deleted the cp-beta-306a914a74c5d57958c6a3dc693bda51f295401d branch November 3, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants