BaseSubmenu<T extends Object?> class

A widget that displays a hierarchical submenu when opened.

The BaseSubmenu widget is optimized specifically for nested submenus. It includes built-in hover delay timing (hoverOpenDelay and hoverCloseDelay), visual focus emulation across submenu levels, and orientation-aware keyboard navigation.

The child widget should only handle visual representation. Focus, activation, and hover interactions should be handled through the BaseSubmenu properties, which are then passed to the internal BaseMenuItem.

To customize the Actions for the submenu anchor, use the anchorActions property. The overlay's Actions can be customized by wrapping the menu in an Actions widget.

Scope

The optional type parameter T can be used to scope the internal BaseMenuItem state selectors to a specific type.

See also:

Inheritance

Constructors

BaseSubmenu({Key? key, required Widget child, required Widget menu, required MenuController controller, Duration hoverOpenDelay = Duration.zero, Duration hoverCloseDelay = Duration.zero, VoidCallback? onOpen, RawMenuAnchorOpenRequestedCallback onOpenRequest = BaseMenu.defaultOnOpenRequested, VoidCallback? onClose, RawMenuAnchorCloseRequestedCallback onCloseRequest = BaseMenu.defaultOnCloseRequested, bool useRootOverlay = false, bool consumeOutsideTaps = false, ValueChanged<bool>? onFocusChange, TraversalEdgeBehavior? traversalEdgeBehavior, SemanticsProperties semanticProperties = const SemanticsProperties(scopesRoute: true, role: SemanticsRole.menu), Axis orientation = Axis.vertical, MenuPositioningDelegate positionDelegate = const DefaultMenuPositioningDelegate(), MenuOverlayChildBuilder? overlayChildBuilder, FocusNode? focusNode, bool autofocus = false, VoidCallback? onPressed, VoidCallback? onActivate, PointerEnterEventListener? onPointerEnter, PointerHoverEventListener? onPointerHover, PointerExitEventListener? onPointerExit, HitTestBehavior behavior = HitTestBehavior.deferToChild, bool opaque = true, WidgetStateProperty<MouseCursor>? mouseCursor, SemanticsRole? role = SemanticsRole.menuItem, bool gestureSemanticsEnabled = true, SemanticsGestureDelegate? gestureSemantics, Map<ShortcutActivator, Intent>? shortcuts = BaseControl.activateOnEnterAndSpaceUpShortcuts, bool enabled = true, Map<Type, Action<Intent>>? anchorActions, bool requestFocusOnHover = true, bool requestCloseOnPointerExit = true, bool requestOpenOnPointerEnter = true})
Creates a BaseSubmenu.
const

Properties

anchorActions Map<Type, Action<Intent>>?
The Actions to be used for the submenu anchor when the submenu is open.
final
autofocus bool
True if this widget will be selected as the initial focus when no other node in its scope is currently focused.
final
behavior HitTestBehavior
How to behave during hit testing when deciding how the hit test propagates to children and whether to consider targets behind this one.
final
child Widget
The optional child to be passed to the builder.
final
consumeOutsideTaps bool
Whether or not a tap event that closes the menu will be permitted to continue on to the gesture arena.
final
controller MenuController
An optional MenuController that allows opening and closing of the menu from other widgets.
final
debugMenuFocusNodeLabel String
no setter
enabled bool
Whether the submenu is enabled. When false, the submenu will not open and the button will be disabled.
final
focusNode FocusNode?
An optional focus node to use as the focus node for this widget.
final
gestureSemantics SemanticsGestureDelegate?
The delegate that controls how this widget adds gestures to the semantics tree.
final
gestureSemanticsEnabled bool
Whether to exclude this widget's tap gestures from the semantics tree.
final
hashCode int
The hash code for this object.
no setterinherited
hoverCloseDelay Duration
The delay after which the submenu should close when no longer hovered.
final
hoverOpenDelay Duration
The delay after which the submenu should open after being hovered.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
A widget containing the contents of the menu. This widget will only be displayed when the menu is open.
final
mouseCursor WidgetStateProperty<MouseCursor>?
The mouse cursor to show when hovering over this menu item.
final
onActivate VoidCallback?
Called when the button is activated by a keyboard shortcut or other non-pointer input.
final
onClose VoidCallback?
Called when the menu overlay will be hidden.
final
onCloseRequest RawMenuAnchorCloseRequestedCallback
Called when a request is made to close the menu.
final
onFocusChange ValueChanged<bool>?
Called when focus enters or leaves the menu overlay and its descendants.
final
onOpen VoidCallback?
Called when the menu overlay is shown.
final
onOpenRequest RawMenuAnchorOpenRequestedCallback
Called when a request is made to open the menu.
final
onPointerEnter PointerEnterEventListener?
Called when a pointer enters this widget.
final
onPointerExit PointerExitEventListener?
Called when a pointer exits this widget.
final
onPointerHover PointerHoverEventListener?
Called when a pointer moves within the bounds of this widget.
final
onPressed VoidCallback?
Called when the button is tapped or otherwise activated.
final
opaque bool
Whether this widget should prevent other MouseRegions visually behind it from detecting the pointer.
final
orientation Axis
The orientation in which the menu's children should be traversed.
final
overlayChildBuilder MenuOverlayChildBuilder?
An optional builder that wraps the menu overlay.
final
positionDelegate MenuPositioningDelegate
A delegate that controls how the menu is positioned.
final
requestCloseOnActivate bool
Whether activating this menu item should request to close the menu.
no setter
requestCloseOnPointerExit bool
Whether the submenu should close when its anchor loses hover.
final
requestFocusOnHover bool
Whether hovering over this menu item should request focus.
final
requestOpenOnPointerEnter bool
Whether the submenu should open when its anchor gains hover.
final
role SemanticsRole?
The semantic role assigned to this menu item.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
semanticProperties SemanticsProperties
Properties used to annotate the menu overlay.
final
shortcuts Map<ShortcutActivator, Intent>?
The shortcuts that this control should respond to.
final
traversalEdgeBehavior TraversalEdgeBehavior?
The behavior to use when focus reaches the edge of the menu overlay while using directional focus traversal.
final
useRootOverlay bool
Whether the menu panel should be rendered in the root Overlay.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<BaseSubmenu<T>>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
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