Skip to main content

MenuAnchor

Struct MenuAnchor 

Source
pub struct MenuAnchor {
Show 20 fields pub key: Option<KeyRef>, pub controller: Option<MenuControllerRef>, pub child_focus_node: Option<FocusNodeRef>, pub style: Option<MenuStyle>, pub alignment_offset: Option<Offset>, pub layer_link: Option<Ref<LayerLink>>, pub clip_behavior: Clip, pub anchor_tap_closes_menu: bool, pub consume_outside_tap: bool, pub on_open: Option<VoidCallback>, pub on_close: Option<VoidCallback>, pub cross_axis_unconstrained: bool, pub use_root_overlay: bool, pub animated: bool, pub on_animation_status_changed: Option<ValueChanged<AnimationStatus>>, pub menu_children: Vec<WidgetRef>, pub builder: Option<MenuAnchorChildBuilder>, pub semantic_label: Option<String>, pub child: Option<WidgetRef>, pub reserved_padding: Option<EdgeInsetsGeometry>,
}
Expand description

A widget used to mark the “anchor” for a set of submenus, defining the rectangle used to position the menu, which can be done either with an explicit location, or with an alignment.

When creating a menu with MenuBar or a SubmenuButton, a MenuAnchor is not needed, since they provide their own internally.

The MenuAnchor is meant to be a slightly lower level interface than MenuBar, used in situations where a MenuBar isn’t appropriate, or to construct widgets or screen regions that have submenus.

To programmatically control a MenuAnchor, like opening or closing it, or checking its state, you can get its associated MenuController. Use MenuController::maybe_of(app, context) to retrieve the controller for the closest MenuAnchor ancestor of a given BuildContext. More detailed usage of MenuController is available in its type documentation.

The MenuStyle::visual_density setting only affects horizontal padding, and it will never make it negative. Vertical padding is not affected at all.

Fields§

§key: Option<KeyRef>

See Widget::key.

§controller: Option<MenuControllerRef>

An optional controller that allows opening and closing of the menu from other widgets.

§child_focus_node: Option<FocusNodeRef>

The child_focus_node attribute is the optional FocusNode also associated to the child or builder widget that opens the menu.

The focus node should be attached to the widget that should receive focus if keyboard focus traversal moves the focus off of the submenu with the arrow keys.

If not supplied, then keyboard traversal from the menu back to the controlling button when the menu is open is disabled.

§style: Option<MenuStyle>

The MenuStyle that defines the visual attributes of the menu bar.

Colors and sizing of the menus is controllable via the MenuStyle.

Defaults to the ambient MenuThemeData::style.

§alignment_offset: Option<Offset>

The offset of the menu relative to the alignment origin determined by MenuStyle::alignment on the style attribute and the ambient Directionality.

Use this for adjustments of the menu placement.

Increasing Offset::dy values of alignment_offset move the menu position down.

If the MenuStyle::alignment from style is not an AlignmentDirectional (e.g. Alignment), then increasing Offset::dx values of alignment_offset move the menu position to the right.

If the MenuStyle::alignment from style is an AlignmentDirectional, then in a TextDirection::Ltr Directionality, increasing Offset::dx values of alignment_offset move the menu position to the right. In a TextDirection::Rtl directionality, increasing Offset::dx values of alignment_offset move the menu position to the left.

Defaults to Offset::ZERO.

§layer_link: Option<Ref<LayerLink>>

An optional LayerLink to attach the menu to the widget that this MenuAnchor surrounds.

When provided, the menu will follow the widget that this MenuAnchor surrounds if it moves because of view insets changes.

§clip_behavior: Clip

The content will be clipped (or not) according to this option.

Defaults to Clip::HardEdge.

§anchor_tap_closes_menu: bool
👎Deprecated:

Use consumeOutsideTap instead. This feature was deprecated after v3.16.0-8.0.pre.

Whether the menus will be closed if the anchor area is tapped.

For menus opened by buttons that toggle the menu, if the button is tapped when the menu is open, the button should close the menu. But if anchor_tap_closes_menu is true, then the menu will close, and (surprisingly) immediately re-open. This is because tapping on the button closes the menu before the on_pressed or on_tap handler is called because of it being considered to be “outside” the menu system, and then the button (seeing that the menu is closed) immediately reopens the menu. The result is that the user thinks that tapping on the button does nothing. So, for button-initiated menus, this value is typically false so that the menu anchor area is considered “inside” of the menu system and doesn’t cause it to close unless [MenuControllerLeaf::close] is called.

For menus that are positioned using [MenuControllerLeaf::open]’s position parameter, it is often desirable that clicking on the anchor always closes the menu since the anchor area isn’t usually considered part of the menu system by the user. In this case anchor_tap_closes_menu should be true.

Defaults to false.

§consume_outside_tap: bool

Whether or not a tap event that closes the menu will be permitted to continue on to the gesture arena.

If false, then tapping outside of a menu when the menu is open will both close the menu, and allow the tap to participate in the gesture arena. If true, then it will only close the menu, and the tap event will be consumed.

Defaults to false.

§on_open: Option<VoidCallback>

A callback that is invoked when the menu begins opening.

Defaults to null.

§on_close: Option<VoidCallback>

A callback that is invoked when the menu finishes closing.

Defaults to null.

§cross_axis_unconstrained: bool

Determine if the menu panel can be wrapped by a UnconstrainedBox which allows the panel to render at its “natural” size.

Defaults to true as it allows developers to render the menu panel at the size it should be. When it is set to false, it can be useful when the menu should be constrained in both main axis and cross axis, such as a DropdownMenu.

§use_root_overlay: bool

Whether the menu panel should be rendered in the root Overlay.

See RawMenuAnchor::use_root_overlay.

Defaults to false.

§animated: bool

Whether this widget should open or close a submenu with an animation.

Defaults to false.

§on_animation_status_changed: Option<ValueChanged<AnimationStatus>>

An optional callback that is invoked when the AnimationStatus of the menu changes during open and close animations.

If animated is false, this callback will only be invoked with AnimationStatus::Completed when the menu is opened, and AnimationStatus::Dismissed when the menu is closed.

This callback provides a way to determine when the menu is opening or closing. This is necessary because the [MenuControllerLeaf::is_open] property remains true throughout the opening, opened, and closing phases, and therefore cannot be used on its own to determine the current animation direction.

Defaults to null.

§menu_children: Vec<WidgetRef>

A list of children containing the menu items that are the contents of the menu surrounded by this 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.

§builder: Option<MenuAnchorChildBuilder>

The widget that this MenuAnchor surrounds.

Typically this is a button used to open the menu by calling [MenuControllerLeaf::open] on the controller passed to the builder.

If not supplied, then the MenuAnchor will be the size that its parent allocates for it.

If provided, the builder will be called each time the menu is opened or closed.

§semantic_label: Option<String>

The semantic label of the menu.

Defaults to null.

§child: Option<WidgetRef>

The optional child to be passed to the builder.

Supply this child if there is a portion of the widget tree built in builder that doesn’t depend on the controller or context supplied to the builder. It will be more efficient, since Flutter doesn’t then need to rebuild this child when those change.

§reserved_padding: Option<EdgeInsetsGeometry>

The padding between the edge of the safe area and the menu panel.

Defaults to EdgeInsets::all(8).

Implementations§

Source§

impl MenuAnchor

Source

pub fn new(menu_children: Vec<WidgetRef>) -> MenuAnchor

Creates a const MenuAnchor.

The menu_children argument is required.

Source

pub fn key(self, key: KeyRef) -> MenuAnchor

Dart MenuAnchor(key:).

Source

pub fn controller(self, controller: MenuControllerRef) -> MenuAnchor

Dart MenuAnchor(controller:).

Source

pub fn child_focus_node(self, child_focus_node: FocusNodeRef) -> MenuAnchor

Dart MenuAnchor(childFocusNode:).

Source

pub fn style(self, style: MenuStyle) -> MenuAnchor

Dart MenuAnchor(style:).

Source

pub fn alignment_offset(self, alignment_offset: Offset) -> MenuAnchor

Dart MenuAnchor(alignmentOffset:).

Source

pub fn reserved_padding( self, reserved_padding: impl Into<EdgeInsetsGeometry>, ) -> MenuAnchor

Dart MenuAnchor(reservedPadding:).

Dart MenuAnchor(layerLink:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> MenuAnchor

Dart MenuAnchor(clipBehavior:).

Source

pub fn anchor_tap_closes_menu(self, anchor_tap_closes_menu: bool) -> MenuAnchor

👎Deprecated:

Use consumeOutsideTap instead. This feature was deprecated after v3.16.0-8.0.pre.

Dart MenuAnchor(anchorTapClosesMenu:).

Source

pub fn consume_outside_tap(self, consume_outside_tap: bool) -> MenuAnchor

Dart MenuAnchor(consumeOutsideTap:).

Source

pub fn on_open(self, on_open: VoidCallback) -> MenuAnchor

Dart MenuAnchor(onOpen:).

Source

pub fn on_close(self, on_close: VoidCallback) -> MenuAnchor

Dart MenuAnchor(onClose:).

Source

pub fn cross_axis_unconstrained( self, cross_axis_unconstrained: bool, ) -> MenuAnchor

Dart MenuAnchor(crossAxisUnconstrained:).

Source

pub fn use_root_overlay(self, use_root_overlay: bool) -> MenuAnchor

Dart MenuAnchor(useRootOverlay:).

Source

pub fn animated(self, animated: bool) -> MenuAnchor

Dart MenuAnchor(animated:).

Source

pub fn on_animation_status_changed( self, on_animation_status_changed: ValueChanged<AnimationStatus>, ) -> MenuAnchor

Dart MenuAnchor(onAnimationStatusChanged:).

Source

pub fn builder( self, builder: impl Fn(&mut App, BuildContext, AnyMenuController, Option<&WidgetRef>) -> WidgetRef + 'static, ) -> MenuAnchor

Dart MenuAnchor(builder:).

Source

pub fn semantic_label(self, semantic_label: impl Into<String>) -> MenuAnchor

Dart MenuAnchor(semanticLabel:).

Source

pub fn child<K>(self, child: impl IntoWidget<K>) -> MenuAnchor

Dart MenuAnchor(child:).

Trait Implementations§

Source§

impl Debug for MenuAnchor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for MenuAnchor

Source§

type State = MenuAnchorState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn create_state(&self) -> MenuAnchorState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_check_constructor(&self)

Source§

fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for MenuAnchor

§

impl !Send for MenuAnchor

§

impl !Sync for MenuAnchor

§

impl !UnwindSafe for MenuAnchor

§

impl Forget for MenuAnchor

§

impl Freeze for MenuAnchor
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, NonZero<u32>: Freeze, &'static MenuControllerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, &'static FocusNodeVTable: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: Freeze, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: Freeze, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: Freeze, PhantomData<fn() -> LayerLink>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, *const RcInner<dyn Fn(&mut App, AnimationStatus)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnimationStatus)>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>>: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for MenuAnchor

§

impl Unpin for MenuAnchor

§

impl UnsafeUnpin for MenuAnchor
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static MenuControllerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, &'static FocusNodeVTable: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Color>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Color>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<f64>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<f64>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Size>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Size>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<BorderSide>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<BorderSide>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>>: UnsafeUnpin, *const RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>>: UnsafeUnpin, PhantomData<fn() -> LayerLink>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnimationStatus)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnimationStatus)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement, AnyMenuController, Option<&Rc<dyn Widget>>) -> Rc<dyn Widget>>>: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>