Skip to main content

MenuBar

Struct MenuBar 

Source
pub struct MenuBar {
    pub key: Option<KeyRef>,
    pub style: Option<MenuStyle>,
    pub clip_behavior: Clip,
    pub controller: Option<MenuControllerRef>,
    pub children: Vec<WidgetRef>,
}
Expand description

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::on_open, and SubmenuButton::on_close 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). 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.

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.

Fields§

§key: Option<KeyRef>

See Widget::key.

§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.

§clip_behavior: Clip

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

Defaults to Clip::None.

§controller: Option<MenuControllerRef>

The MenuController to use for this menu bar.

§children: Vec<WidgetRef>

The list of menu items that are the top level children of the MenuBar.

A Widget in Flutter is immutable, so directly modifying the children with Vec APIs will result in incorrect behaviors. Whenever the menus list is modified, a new list object must be provided.

Implementations§

Source§

impl MenuBar

Source

pub fn new(children: Vec<WidgetRef>) -> MenuBar

Creates a const MenuBar.

The children argument is required.

Source

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

Dart MenuBar(key:).

Source

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

Dart MenuBar(style:).

Source

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

Dart MenuBar(clipBehavior:).

Source

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

Dart MenuBar(controller:).

Trait Implementations§

Source§

impl Debug for MenuBar

Source§

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

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

impl StatelessWidget for MenuBar

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 build(&self, app: &mut App, context: BuildContext) -> WidgetRef

Describes the part of the user interface represented by this widget. Read more
Source§

fn debug_check_constructor(&self)

Dart’s constructor asserts that relate two or more arguments. Read more
Source§

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

Dart’s this is PreferredSizeWidget: a widget that implements PreferredSizeWidget answers with itself, which is what a parent asking an erased child for its preferred size reads.

Auto Trait Implementations§

§

impl !RefUnwindSafe for MenuBar

§

impl !Send for MenuBar

§

impl !Sync for MenuBar

§

impl !UnwindSafe for MenuBar

§

impl Forget for MenuBar

§

impl Freeze for MenuBar

§

impl Move for MenuBar

§

impl Unpin for MenuBar

§

impl UnsafeUnpin for MenuBar

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<StatelessKind> for W
where W: StatelessWidget,

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>