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 aVoidCallbackand work with theActionsandShortcutssystem.CallbackShortcuts, to define shortcuts that call a callback without involvingActions.
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: ClipThe 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§
Trait Implementations§
Source§impl StatelessWidget for MenuBar
impl StatelessWidget for MenuBar
Source§fn debug_fill_properties(
&self,
__app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, __app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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
fn build(&self, app: &mut App, context: BuildContext) -> WidgetRef
Source§fn debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
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 MenuBarwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: 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,
NonZero<u32>: Freeze,
&'static MenuControllerVTable: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Rc<dyn Widget>>: Freeze,
impl Move for MenuBar
impl Unpin for MenuBarwhere
Rc<dyn Key>: Unpin,
Rc<dyn WidgetStateProperty<Option<Color>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<f64>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<EdgeInsetsGeometry>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Size>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<BorderSide>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<OutlinedBorderRef>>>: Unpin,
Rc<dyn WidgetStateProperty<Option<Rc<dyn MouseCursor>>>>: Unpin,
NonZero<u32>: Unpin,
&'static MenuControllerVTable: Unpin,
Rc<Keep>: Unpin,
*const u8 is !null: Unpin,
Rc<dyn Widget>: Unpin,
impl UnsafeUnpin for MenuBarwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: 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,
NonZeroU32Inner: UnsafeUnpin,
&'static MenuControllerVTable: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Rc<dyn Widget>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.