RawMenuAnchor class

A widget that wraps a child and anchors a floating menu.

The child can be any widget, but is typically a button, a text field, or, in the case of context menus, the entire screen.

The menu overlay of a RawMenuAnchor is shown by calling MenuController.open on an attached MenuController.

When a RawMenuAnchor is opened, overlayBuilder is called to construct the menu contents within an Overlay. The Overlay allows the menu to "float" on top of other widgets. The info argument passed to overlayBuilder provides the anchor's Rect, the Size of the overlay, the TapRegion.groupId used by members of the menu system, and the position argument passed to MenuController.open.

If MenuController.open is called with a position argument, it will be passed to the info argument of the overlayBuilder function.

Users are responsible for managing the positioning, semantics, and focus of the menu.

This example uses a RawMenuAnchor to build an a basic select menu with four items.
link

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

Inheritance

Constructors

RawMenuAnchor.new({Key? key, FocusNode? childFocusNode, bool consumeOutsideTaps = false, VoidCallback? onOpen, VoidCallback? onClose, bool useRootOverlay = false, RawMenuAnchorChildBuilder? builder, required MenuController controller, required RawMenuAnchorOverlayBuilder overlayBuilder, Widget? child})
A RawMenuAnchor that delegates overlay construction to an overlayBuilder.
const

Properties

builder RawMenuAnchorChildBuilder?
A builder that builds the widget that this RawMenuAnchor surrounds.
final
child Widget?
The optional child to be passed to the builder.
final
childFocusNode FocusNode?
The FocusNode attached to the widget that takes focus when the menu is opened or closed.
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
A MenuController that allows opening and closing of the menu from other widgets.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onClose VoidCallback?
A callback that is invoked when the menu is closed.
final
onOpen VoidCallback?
A callback that is invoked when the menu is opened.
final
overlayBuilder RawMenuAnchorOverlayBuilder
The overlayBuilder function is passed a RawMenuOverlayInfo object that defines the anchor's Rect, the Size of the overlay, the TapRegion.groupId for the menu system, and the position Offset passed to MenuController.open.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
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<RawMenuAnchor>
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.
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