Rows
Spreadsheet with superpowers!

Desktop Context Menu

A package that spawns a context menu at the mouse coordinates.

Available for MacOS and Windows.

MacOS Windows
image image

Features

  • Native context menu
  • Separators between menu items
  • Specify shortcuts for menu items

Usage

To invoke the context menu you can do the following:

final selectedItem = await showContextMenu(menuItems: [...]);

In case an item is selected in the context menu, that item is returned. If no item is selected, null is returned.

A context menu item can be of type ContextMenuItem or ContextMenuSeparator.

To define a menu item of type ContextMenuItem, you can do the following:

...
ContextMenuItem(
  title: 'Menu item title',
  onTap: () {
    // do something...
  },
),
...

If you do not set the onTap callback, the menu item will be disabled.

To add a separator between menu items, you need to add a ContextMenuSeparator between ContextMenuItems:

...
menuItems: [
  ContextMenuItem(
    title: 'Menu item title',
    onTap: () {
      // do something...
    },
  ),
  ContextMenuSeparator(),
  ContextMenuItem(
    title: 'Disabled menu item',
  ),
],
...

To define a shortcut for a menu item, just specify the shortcut property of ContextMenuItem that takes a SingleActivator:

...
ContextMenuItem(
  title: 'Copy',
  onTap: () {
    // do something...
  },
  shortcut: SingleActivator(
    LogicalKeyboardKey.keyC,
    meta: Platform.isMacOS,
    control: Platform.isWindows,
  ),
),
...