MenuItemButton class

A button for use in a MenuBar, in a menu created with MenuAnchor, or on its own, that can be activated by click or keyboard navigation.

This widget represents a leaf entry in a menu hierarchy that is typically part of a MenuBar, but may be used independently, or as part of a menu created with a MenuAnchor.

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

See also:



Creates a const MenuItemButton.


child Widget?
The widget displayed in the center of this button.
clipBehavior Clip
The content will be clipped (or not) according to this option.
closeOnActivate bool
Determines if the menu will be closed when a MenuItemButton is pressed.
enabled bool
Whether the button is enabled or disabled.
no setter
focusNode FocusNode?
An optional focus node to use as the focus node for this widget.
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
leadingIcon Widget?
An optional icon to display before the child label.
onFocusChange ValueChanged<bool>?
Handler called when the focus changes.
onHover ValueChanged<bool>?
Called when a pointer enters or exits the button response area.
onPressed VoidCallback?
Called when the button is tapped or otherwise activated.
requestFocusOnHover bool
Determine if hovering can request focus.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shortcut MenuSerializableShortcut?
The optional shortcut that selects this MenuItemButton.
statesController MaterialStatesController?
Represents the interactive "state" of this widget in terms of a set of MaterialStates, like MaterialState.pressed and MaterialState.focused.
style ButtonStyle?
Customizes this button's appearance.
trailingIcon Widget?
An optional icon to display after the child label.


createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
createState() State<MenuItemButton>
Creates the mutable state for this widget at a given location in the tree.
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
defaultStyleOf(BuildContext context) ButtonStyle
Defines the button's default appearance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
themeStyleOf(BuildContext context) ButtonStyle?
Returns the of the closest MenuButtonTheme ancestor.
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
toString({DiagnosticLevel minLevel =}) String
A string representation of this object.
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator.

Static Methods

styleFrom({Color? foregroundColor, Color? backgroundColor, Color? disabledForegroundColor, Color? disabledBackgroundColor, Color? shadowColor, Color? surfaceTintColor, Color? iconColor, TextStyle? textStyle, double? elevation, EdgeInsetsGeometry? padding, Size? minimumSize, Size? fixedSize, Size? maximumSize, MouseCursor? enabledMouseCursor, MouseCursor? disabledMouseCursor, BorderSide? side, OutlinedBorder? shape, VisualDensity? visualDensity, MaterialTapTargetSize? tapTargetSize, Duration? animationDuration, bool? enableFeedback, AlignmentGeometry? alignment, InteractiveInkFeatureFactory? splashFactory}) ButtonStyle
A static convenience method that constructs a MenuItemButton's ButtonStyle given simple values.