Skip to content

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

@pharan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions