pub struct MenuItemButton {Show 17 fields
pub key: Option<KeyRef>,
pub on_pressed: Option<Listener>,
pub on_hover: Option<ValueChanged<bool>>,
pub request_focus_on_hover: bool,
pub on_focus_change: Option<ValueChanged<bool>>,
pub focus_node: Option<FocusNodeRef>,
pub autofocus: bool,
pub shortcut: Option<MenuSerializableShortcutRef>,
pub semantics_label: Option<String>,
pub style: Option<ButtonStyle>,
pub states_controller: Option<Ref<WidgetStatesController>>,
pub clip_behavior: Clip,
pub leading_icon: Option<WidgetRef>,
pub trailing_icon: Option<WidgetRef>,
pub close_on_activate: bool,
pub overflow_axis: Axis,
pub child: Option<WidgetRef>,
}Expand description
A button for use in a MenuBar, in a menu created with MenuAnchor, or on
its own, that can be activated by click or keyboard navigation.
This widget represents a leaf entry in a menu hierarchy that is typically
part of a MenuBar, but may be used independently, or as part of a menu
created with a MenuAnchor.
Menus using MenuItemButton can have a SingleActivator or CharacterActivator
assigned to them as their 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.
See also:
MenuBar, a class that creates a top level menu bar in a Material Design style.MenuAnchor, a widget that creates a region with a submenu and shows it when requested.SubmenuButton, a menu item similar to this one which manages a submenu.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.CallbackShortcutsto define shortcuts that call a callback without involvingActions.
Fields§
§key: Option<KeyRef>See Widget::key.
on_pressed: Option<Listener>Called when the button is tapped or otherwise activated.
If this callback is null, then the button will be disabled.
See also:
enabled, which is true if the button is enabled.
on_hover: Option<ValueChanged<bool>>Called when a pointer enters or exits the button response area.
The value passed to the callback is true if a pointer has entered button area and false if a pointer has exited.
request_focus_on_hover: boolDetermine if hovering can request focus.
Defaults to true.
on_focus_change: Option<ValueChanged<bool>>Handler called when the focus changes.
Called with true if this widget’s node gains focus, and false if it loses focus.
focus_node: Option<FocusNodeRef>An optional focus node to use as the focus node for this widget.
autofocus: boolTrue if this widget will be selected as the initial focus when no other node in its scope is currently focused.
shortcut: Option<MenuSerializableShortcutRef>The optional shortcut that selects this MenuItemButton.
Even though the shortcut label is displayed in the menu, the shortcut is not
automatically handled; see MenuBar.
semantics_label: Option<String>An optional Semantics label, applied to the entire MenuItemButton.
A screen reader will default to reading the derived text on the
MenuItemButton itself, which is not guaranteed to be readable.
(For some shortcuts, such as comma, semicolon, and other
punctuation, screen readers read silence).
Setting this label overwrites the semantics properties of the entire
Widget, including its children. Consider wrapping this widget in
Semantics if you want to customize other properties besides just
the label.
Null by default.
style: Option<ButtonStyle>Customizes this button’s appearance.
Non-null properties of this style override the corresponding properties in
theme_style_of and default_style_of.
WidgetStatePropertys that resolve to non-null values will similarly override the
corresponding WidgetStatePropertys in theme_style_of and
default_style_of.
Null by default.
states_controller: Option<Ref<WidgetStatesController>>Represents the interactive “state” of this widget in terms of a set of
WidgetStates, including WidgetState::Pressed, WidgetState::Hovered,
WidgetState::Focused.
clip_behavior: ClipThe content will be clipped (or not) according to this option.
Defaults to Clip::None.
leading_icon: Option<WidgetRef>An optional icon to display before the child label.
trailing_icon: Option<WidgetRef>An optional icon to display after the child label.
close_on_activate: boolDetermines if the menu will be closed when a MenuItemButton
is pressed.
Defaults to true.
overflow_axis: AxisThe direction in which the menu item expands.
If the menu item button is a descendant of MenuAnchor or MenuBar, then
this property is ignored.
If overflow_axis is Axis::Vertical, the menu will be
expanded vertically. If overflow_axis is Axis::Horizontal,
then the menu will be expanded horizontally.
Defaults to Axis::Horizontal.
child: Option<WidgetRef>The widget displayed in the center of this button.
Typically this is the button’s label, using a Text widget.
Implementations§
Source§impl MenuItemButton
impl MenuItemButton
Sourcepub fn new() -> MenuItemButton
pub fn new() -> MenuItemButton
Creates a const MenuItemButton.
Sourcepub fn key(self, key: KeyRef) -> MenuItemButton
pub fn key(self, key: KeyRef) -> MenuItemButton
Dart MenuItemButton(key:).
Sourcepub fn on_pressed(self, on_pressed: Listener) -> MenuItemButton
pub fn on_pressed(self, on_pressed: Listener) -> MenuItemButton
Dart MenuItemButton(onPressed:).
Sourcepub fn on_hover(self, on_hover: ValueChanged<bool>) -> MenuItemButton
pub fn on_hover(self, on_hover: ValueChanged<bool>) -> MenuItemButton
Dart MenuItemButton(onHover:).
Sourcepub fn request_focus_on_hover(
self,
request_focus_on_hover: bool,
) -> MenuItemButton
pub fn request_focus_on_hover( self, request_focus_on_hover: bool, ) -> MenuItemButton
Dart MenuItemButton(requestFocusOnHover:).
Sourcepub fn on_focus_change(
self,
on_focus_change: ValueChanged<bool>,
) -> MenuItemButton
pub fn on_focus_change( self, on_focus_change: ValueChanged<bool>, ) -> MenuItemButton
Dart MenuItemButton(onFocusChange:).
Sourcepub fn focus_node(self, focus_node: FocusNodeRef) -> MenuItemButton
pub fn focus_node(self, focus_node: FocusNodeRef) -> MenuItemButton
Dart MenuItemButton(focusNode:).
Sourcepub fn autofocus(self, autofocus: bool) -> MenuItemButton
pub fn autofocus(self, autofocus: bool) -> MenuItemButton
Dart MenuItemButton(autofocus:).
Sourcepub fn shortcut(self, shortcut: MenuSerializableShortcutRef) -> MenuItemButton
pub fn shortcut(self, shortcut: MenuSerializableShortcutRef) -> MenuItemButton
Dart MenuItemButton(shortcut:).
Sourcepub fn semantics_label(
self,
semantics_label: impl Into<String>,
) -> MenuItemButton
pub fn semantics_label( self, semantics_label: impl Into<String>, ) -> MenuItemButton
Dart MenuItemButton(semanticsLabel:).
Sourcepub fn style(self, style: ButtonStyle) -> MenuItemButton
pub fn style(self, style: ButtonStyle) -> MenuItemButton
Dart MenuItemButton(style:).
Sourcepub fn states_controller(
self,
states_controller: Ref<WidgetStatesController>,
) -> MenuItemButton
pub fn states_controller( self, states_controller: Ref<WidgetStatesController>, ) -> MenuItemButton
Dart MenuItemButton(statesController:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> MenuItemButton
pub fn clip_behavior(self, clip_behavior: Clip) -> MenuItemButton
Dart MenuItemButton(clipBehavior:).
Sourcepub fn leading_icon<K>(self, leading_icon: impl IntoWidget<K>) -> MenuItemButton
pub fn leading_icon<K>(self, leading_icon: impl IntoWidget<K>) -> MenuItemButton
Dart MenuItemButton(leadingIcon:).
Sourcepub fn trailing_icon<K>(
self,
trailing_icon: impl IntoWidget<K>,
) -> MenuItemButton
pub fn trailing_icon<K>( self, trailing_icon: impl IntoWidget<K>, ) -> MenuItemButton
Dart MenuItemButton(trailingIcon:).
Sourcepub fn close_on_activate(self, close_on_activate: bool) -> MenuItemButton
pub fn close_on_activate(self, close_on_activate: bool) -> MenuItemButton
Dart MenuItemButton(closeOnActivate:).
Sourcepub fn overflow_axis(self, overflow_axis: Axis) -> MenuItemButton
pub fn overflow_axis(self, overflow_axis: Axis) -> MenuItemButton
Dart MenuItemButton(overflowAxis:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> MenuItemButton
pub fn child<K>(self, child: impl IntoWidget<K>) -> MenuItemButton
Dart MenuItemButton(child:).
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Whether the button is enabled or disabled.
To enable a button, set its on_pressed property to a non-null
value.
Sourcepub fn default_style_of(
&self,
app: &mut App,
context: BuildContext,
) -> Box<dyn ButtonStyleGetters>
pub fn default_style_of( &self, app: &mut App, context: BuildContext, ) -> Box<dyn ButtonStyleGetters>
Defines the button’s default appearance.
The button child’s Text and Icon widgets are rendered with the ButtonStyle’s
foreground color. The button’s InkWell adds the style’s overlay color when the button
is focused, hovered or pressed. The button’s background color becomes its Material
color and is transparent by default.
Sourcepub fn theme_style_of(
&self,
app: &mut App,
context: BuildContext,
) -> Option<ButtonStyle>
pub fn theme_style_of( &self, app: &mut App, context: BuildContext, ) -> Option<ButtonStyle>
Returns the MenuButtonThemeData::style of the
closest MenuButtonTheme ancestor.
Sourcepub fn style_from() -> MenuButtonStyleFromBuilder
pub fn style_from() -> MenuButtonStyleFromBuilder
A static convenience method that constructs a MenuItemButton’s
ButtonStyle given simple values.
The foreground_color color is used to create a WidgetStateProperty
ButtonStyle::foreground_color value. Specify a value for foreground_color
to specify the color of the button’s icons. Use background_color for the
button’s background fill color. Use disabled_foreground_color and
disabled_background_color to specify the button’s disabled icon and fill
color.
Similarly, the enabled_mouse_cursor and disabled_mouse_cursor
parameters are used to construct ButtonStyle::mouse_cursor.
The icon_color, disabled_icon_color are used to construct
ButtonStyle::icon_color and icon_size is used to construct
ButtonStyle::icon_size.
All of the other parameters are either used directly or used to create a
WidgetStateProperty with a single value for all states.
All parameters default to null, by default this method returns a
ButtonStyle that doesn’t override anything.
For example, to override the default foreground color for a
MenuItemButton, as well as its overlay color, with all of the standard
opacity adjustments for the pressed, focused, and hovered states, one
could write:
MenuItemButton::new()
.leading_icon(Icon::new(Some(Icons::pets())))
.style(MenuItemButton::style_from().foreground_color(Colors::GREEN.primary()).build())
.on_pressed(Listener::new(|_app| {
// ...
}))
.child(Text::new("Button Label"))Trait Implementations§
Source§impl Debug for MenuItemButton
impl Debug for MenuItemButton
Source§impl Default for MenuItemButton
impl Default for MenuItemButton
Source§fn default() -> MenuItemButton
fn default() -> MenuItemButton
Source§impl StatefulWidget for MenuItemButton
impl StatefulWidget for MenuItemButton
Source§type State = MenuItemButtonState
type State = MenuItemButtonState
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 create_state(&self) -> MenuItemButtonState
fn create_state(&self) -> MenuItemButtonState
Source§fn as_preferred_size_widget(
&self,
) -> Option<&(dyn PreferredSizeWidget + 'static)>
fn as_preferred_size_widget( &self, ) -> Option<&(dyn PreferredSizeWidget + 'static)>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
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 MenuItemButton
impl !Send for MenuItemButton
impl !Sync for MenuItemButton
impl !UnwindSafe for MenuItemButton
impl Forget for MenuItemButton
impl Freeze for MenuItemButtonwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
*const RcInner<dyn Fn(&mut App)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze,
NonZero<u32>: Freeze,
*const (): Freeze,
*const RcInner<dyn Fn(&mut App, bool)> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, bool)>>: Freeze,
&'static FocusNodeVTable: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
*const RcInner<dyn MenuSerializableShortcut> is !null: Freeze,
PhantomData<RcInner<dyn MenuSerializableShortcut>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: Freeze,
PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: 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,
*const RcInner<dyn InteractiveInkFeatureFactory> is !null: Freeze,
PhantomData<RcInner<dyn InteractiveInkFeatureFactory>>: Freeze,
*const RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>>: Freeze,
PhantomData<fn() -> WidgetStatesController>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for MenuItemButton
impl Unpin for MenuItemButtonwhere
Rc<dyn Key>: Unpin,
Rc<dyn Fn(&mut App)>: Unpin,
NonZero<u32>: Unpin,
*const (): Unpin,
Rc<dyn Fn(&mut App, bool)>: Unpin,
&'static FocusNodeVTable: Unpin,
Rc<Keep>: Unpin,
Rc<dyn MenuSerializableShortcut>: Unpin,
*const u8 is !null: Unpin,
Rc<dyn WidgetStateProperty<Option<TextStyle>>>: 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,
Rc<dyn InteractiveInkFeatureFactory>: Unpin,
Rc<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>: Unpin,
Rc<dyn Widget>: Unpin,
impl UnsafeUnpin for MenuItemButtonwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, bool)> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, bool)>>: UnsafeUnpin,
&'static FocusNodeVTable: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
*const RcInner<dyn MenuSerializableShortcut> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn MenuSerializableShortcut>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const RcInner<dyn WidgetStateProperty<Option<TextStyle>>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn WidgetStateProperty<Option<TextStyle>>>>: 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,
*const RcInner<dyn InteractiveInkFeatureFactory> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn InteractiveInkFeatureFactory>>: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, AnyElement, &HashSet<WidgetState>, Option<Rc<dyn Widget>>) -> Rc<dyn Widget>>>: UnsafeUnpin,
PhantomData<fn() -> WidgetStatesController>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<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<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.