Skip to content

fix: explain why ContextMenu.open is unavailable on iOS - #71

Merged
AdamMusa merged 1 commit into
codex/engine-initializationfrom
fix/cupertino-context-menu-open
Nov 2, 2026
Merged

AdamMusa merged 1 commit into
codex/engine-initializationfrom
fix/cupertino-context-menu-open

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Wave-3 item 3. Engine-only.

Problem

On iOS and macOS, context_menu.open waited for the whole Ruby timeout, because the Cupertino ContextMenu registered no invoke listener.

Why there is no native implementation

Flutter 3.41.2's CupertinoContextMenu opens only from its own long-press gesture:

  • The open routine _CupertinoContextMenuState._openContextMenu() is private.
  • The only public API is actions, child/builder and enableHapticFeedback. There is no controller.

This mirrors UIKit: a UIContextMenuInteraction cannot be presented from code either. Simulating a long press with synthetic pointer events would be fragile, so I did not do it.

Fix

The Cupertino renderer now registers a listener that replies immediately with:

UnsupportedError: ContextMenu.open is not supported on iOS and macOS: the native context menu opens only from the user's long press, and Flutter's CupertinoContextMenu has no API to open it programmatically. Use an action_sheet to present the same actions from code.

Other method names get the usual Unknown ContextMenu method: <name> error. Material is unchanged and keeps opening its popup at the given or center position.

Relation to #59: the generic fail-fast fix would also stop the timeout here, but only with a generic "not supported" message. This PR adds the reason and the alternative. The two merge cleanly, and when both are in, this listener's message is the one Ruby sees.

Tests

test/widgets/ruby_context_menu_open_test.dart (3 tests):

  • iOS open: settles within one frame while the Ruby timeout is 30 s and fake time is not advanced. The UnsupportedError mentions ContextMenu.open, long press and action_sheet, and no menu is presented.
  • iOS other names: close gets Unknown ContextMenu method: close.
  • Material open: still presents the menu (the Copy action appears).

Before the fix, iOS open did not settle, and the second test hung for 10 minutes (the real-time limit).

verify_pr.sh (Flutter 3.41.2):

PASS engine:ruflet flutter test         +698: All tests passed!
PASS engine:ruflet analyze              No issues found!
RESULT: PASS

The Cupertino ContextMenu registered no invoke listener, so a Ruby
context_menu.open waited out its whole timeout. Flutter's
CupertinoContextMenu opens only from its own long-press gesture (the
open routine is private, there is no controller), matching UIKit where
context menus cannot be presented from code. Reply immediately with an
UnsupportedError that says so and points to action_sheet; other method
names get the usual unknown-method error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant