MenuBar class
A menu bar that manages cascading child menus.
This is a Material Design menu bar that typically resides above the main body of an application (but can go anywhere) that defines a menu system for invoking callbacks in response to user selection of a menu item.
The menus can be opened with a click or tap. Once a menu is opened, it can be navigated by using the arrow and tab keys or via mouse hover. Selecting a menu item can be done by pressing enter, or by clicking or tapping on the menu item. Clicking or tapping on any part of the user interface that isn't part of the menu system controlled by the same controller will cause all of the menus controlled by that controller to close, as will pressing the escape key.
When a menu item with a submenu is clicked on, it toggles the visibility of the submenu. When the menu item is hovered over, the submenu will open, and hovering over other items will close the previous menu and open the newly hovered one. When those open/close transitions occur, SubmenuButton.onOpen, and SubmenuButton.onClose are called on the corresponding SubmenuButton child of the menu bar.
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.
To create a local project with this code sample, run:
flutter create --sample=material.MenuBar.1 mysample
To create a local project with this code sample, run:
flutter create --sample=material.MenuAcceleratorLabel.1 mysample
See also:
- MenuAnchor, a widget that creates a region with a submenu and shows it when requested.
- SubmenuButton, a menu item which manages a submenu.
- MenuItemButton, a leaf menu item which displays the label, an optional shortcut label, and optional leading and trailing icons.
- PlatformMenuBar, which creates a menu bar that is rendered by the host platform instead of by Flutter (on macOS, for example).
- ShortcutRegistry, a registry of shortcuts that apply for the entire application.
- VoidCallbackIntent, to define intents that will call a VoidCallback and work with the Actions and Shortcuts system.
- CallbackShortcuts, to define shortcuts that call a callback without involving Actions.
- Inheritance
Constructors
Properties
-
children
→ List<
Widget> -
The list of menu items that are the top level children of the MenuBar.
final
- clipBehavior → Clip
-
The content will be clipped (or not) according to this option.
final
- controller → MenuController?
-
The MenuController to use for this menu bar.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- style → MenuStyle?
-
The MenuStyle that defines the visual attributes of the menu bar.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
override
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited