Skip to content

How do I make a checked or disabled menu item? #4

Closed

Description

@pharan

In Windows.
I'm trying to make a context menu with disabled items and items with a checkmark.

  Widget testTextWithContextMenu({
    bool checked = true,
  }) {
    return GestureDetector(
      onSecondaryTap: () {
        final menu = Menu();

        final checkableItem = MenuItem("Checkable", MenuItemType.checkbox);
        checkableItem.state = checked
            ? MenuItemState.checked
            : MenuItemState.unchecked;

        final disabledItem = MenuItem("Disabled");
        disabledItem.enabled = false;

        menu.addItem(checkableItem);
        menu.addItem(disabledItem);

        menu.open(PositioningStrategy.cursorPosition());
      },
      child: Text("Right-click on me"),
    );
  }

I pass the default argument checked: true.

When I right-click on the text, the menu appears but...

There is no checkmark on the "Checkable" menu item.
And the "Disabled" menu item is not disabled.

Image

Activity

  1. lijy91 commented on May 12, 2026

    @lijy91
    Member

    Hey @pharan,

    The issue is that on Windows, state and enabled need to be set after adding the item to the menu. Here's the fix for your code:

    Widget testTextWithContextMenu({
        bool checked = true,
      }) {
        return GestureDetector(
          onSecondaryTap: () {
            final menu = Menu();
    
            final checkableItem = MenuItem("Checkable", MenuItemType.checkbox);
            final disabledItem = MenuItem("Disabled");
    
            menu.addItem(checkableItem);
            menu.addItem(disabledItem);
    
            // 👇 Set state and enabled AFTER addItem
            checkableItem.state = checked
                ? MenuItemState.checked
                : MenuItemState.unchecked;
            disabledItem.enabled = false;
    
            menu.open(PositioningStrategy.cursorPosition());
          },
          child: Text("Right-click on me"),
        );
      }

    Just move the property assignments after addItem() and it should work on Windows.

    We'll also fix the underlying issue in the Windows native implementation so that setting these properties before addItem() works as expected in a future release.

  2. lijy91 commented on May 12, 2026

    @lijy91
    Member

    The root cause has been documented in detail in issue #5, and a fix has been applied in the Windows native code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions