shortcut property

MenuSerializableShortcut? shortcut

The optional shortcut that selects this MenuItemButton.

Menus using MenuItemButton can have a SingleActivator or CharacterActivator assigned to them as their MenuItemButton.shortcut, which will display an appropriate shortcut hint. Even though the shortcut labels are displayed in the menu, shortcuts are not automatically handled. They must be available in whatever context they are appropriate, and handled via another mechanism.

If shortcuts should be generally enabled, but are not easily defined in a context surrounding the menu bar, consider registering them with a ShortcutRegistry (one is already included in the WidgetsApp, and thus also MaterialApp and CupertinoApp), as shown in the example below. To be sure that selecting a menu item and triggering the shortcut do the same thing, it is recommended that they call the same callback.

This example shows a MenuBar that contains a single top level menu, containing three items: "About", a checkbox menu item for showing a message, and "Quit". The items are identified with an enum value, and the shortcuts are registered globally with the ShortcutRegistry.

To create a local project with this code sample, run:
flutter create --sample=material.MenuBar.1 mysample


final MenuSerializableShortcut? shortcut;