desktop_context_menu 0.1.1 desktop_context_menu: ^0.1.1 copied to clipboard
A plugin that opens a context menu on the cursor position.
Desktop Context Menu #
A package that spawns a context menu at the mouse coordinates.
Available for MacOS and Windows.
MacOS | Windows |
---|---|
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 ContextMenuItem
s:
...
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,
),
),
...