pub struct SubmenuButton {Show 21 fields
pub key: Option<KeyRef>,
pub on_hover: Option<ValueChanged<bool>>,
pub on_focus_change: Option<ValueChanged<bool>>,
pub on_open: Option<VoidCallback>,
pub on_close: Option<VoidCallback>,
pub controller: Option<MenuControllerRef>,
pub style: Option<ButtonStyle>,
pub menu_style: Option<MenuStyle>,
pub alignment_offset: Option<Offset>,
pub clip_behavior: Clip,
pub focus_node: Option<FocusNodeRef>,
pub states_controller: Option<Ref<WidgetStatesController>>,
pub leading_icon: Option<WidgetRef>,
pub submenu_icon: Option<WidgetStatePropertyRef<Option<WidgetRef>>>,
pub trailing_icon: Option<WidgetRef>,
pub use_root_overlay: bool,
pub on_animation_status_changed: Option<ValueChanged<AnimationStatus>>,
pub menu_children: Vec<WidgetRef>,
pub hover_open_delay: Duration,
pub animated: bool,
pub child: Option<WidgetRef>,
}Expand description
A menu button that displays a cascading menu.
It can be used as part of a MenuBar, or as a standalone widget.
This widget represents a menu item that has a submenu. Like the leaf
MenuItemButton, it shows a label with an optional leading or trailing
icon, but additionally shows an arrow icon showing that it has a submenu.
By default the submenu will appear to the side of the controlling button.
The alignment and offset of the submenu can be controlled by setting
MenuStyle::alignment on the style and the
alignment_offset argument, respectively.
When activated (by being clicked, through keyboard navigation, or via
hovering with a mouse), it will open a submenu containing the
menu_children.
If menu_children is empty, then this menu item will appear
disabled.
See also:
MenuItemButton, a widget that represents a leaf menu item that does not host a submenu.MenuBar, a widget that renders menu items in a row in a Material Design style.MenuAnchor, a widget that creates a region with a submenu and shows it when requested.PlatformMenuBar, a widget that renders similar menu bar items from aPlatformMenuItemusing platform-native APIs instead of Flutter.
Fields§
§key: Option<KeyRef>See Widget::key.
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 this part of the button and false if a pointer has exited.
on_focus_change: Option<ValueChanged<bool>>Handler called when the focus changes.
Called with true if this widget’s focus_node gains focus, and
false if it loses focus.
on_open: Option<VoidCallback>A callback that is invoked when the menu is opened.
on_close: Option<VoidCallback>A callback that is invoked when the menu is closed.
controller: Option<MenuControllerRef>An optional MenuController for this submenu.
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.
The MenuStyle of the menu specified by menu_children.
Defaults to the value of MenuThemeData::style of the ambient MenuTheme.
alignment_offset: Option<Offset>The offset of the menu relative to the alignment origin determined by
MenuStyle::alignment on the style attribute.
Use this for fine adjustments of the menu placement.
Defaults to an offset that takes into account the padding of the menu so
that the top starting corner of the first menu item is aligned with the
top of the MenuAnchor region.
clip_behavior: ClipThe content will be clipped (or not) according to this option.
Defaults to Clip::HardEdge.
focus_node: Option<FocusNodeRef>An optional focus node to use as the focus node for this widget.
states_controller: Option<Ref<WidgetStatesController>>Represents the interactive “state” of this widget in terms of a set of
WidgetStates.
leading_icon: Option<WidgetRef>An optional icon to display before the child.
If provided, the widget replaces the default SubmenuButton arrow icon.
Resolves in the following states:
WidgetState::Disabled.WidgetState::Hovered.WidgetState::Focused.
If this is null, then the value of MenuThemeData::submenu_icon is used.
If that is also null, then defaults to a right arrow icon with the size
of 24 pixels.
trailing_icon: Option<WidgetRef>An optional icon to display after the child.
use_root_overlay: boolWhether the menu panel should be rendered in the root Overlay.
See RawMenuAnchor::use_root_overlay.
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.
Because the [MenuControllerLeaf::is_open] property is true while the menu is
opening, opened, and closing, it cannot be used to determine whether the
menu is in the process of closing or opening. As such, this callback
provides a way to determine when the menu is opening or closing.
Defaults to null.
The list of widgets that appear in the menu when it is opened.
These can be any widget, but are typically either MenuItemButton or
SubmenuButton widgets.
If menu_children is empty, then the button for this menu item
will be disabled.
hover_open_delay: DurationThe duration to wait before opening the menu when the button is hovered.
Because MenuBar children can only be opened by hover if a sibling
SubmenuButton is already open, providing a
hover_open_delay to direct children of a MenuBar will
panic in a debug build. This is to avoid the case where the
hover_open_delay for a SubmenuButton is longer than
the duration of a sibling’s closing animation, which leads to that menu never opening.
Defaults to Duration::ZERO.
animated: boolWhether the menu should open and close with an animation.
Defaults to false.
child: Option<WidgetRef>The widget displayed in the middle portion of this button.
Typically this is the button’s label, using a Text widget.
Implementations§
Sourcepub fn new<K>(
menu_children: Vec<WidgetRef>,
child: Option<impl IntoWidget<K>>,
) -> SubmenuButton
pub fn new<K>( menu_children: Vec<WidgetRef>, child: Option<impl IntoWidget<K>>, ) -> SubmenuButton
Creates a const SubmenuButton.
The child and menu_children attributes are
required.
Sourcepub fn key(self, key: KeyRef) -> SubmenuButton
pub fn key(self, key: KeyRef) -> SubmenuButton
Dart SubmenuButton(key:).
Sourcepub fn on_hover(self, on_hover: ValueChanged<bool>) -> SubmenuButton
pub fn on_hover(self, on_hover: ValueChanged<bool>) -> SubmenuButton
Dart SubmenuButton(onHover:).
Sourcepub fn on_focus_change(
self,
on_focus_change: ValueChanged<bool>,
) -> SubmenuButton
pub fn on_focus_change( self, on_focus_change: ValueChanged<bool>, ) -> SubmenuButton
Dart SubmenuButton(onFocusChange:).
Sourcepub fn on_open(self, on_open: VoidCallback) -> SubmenuButton
pub fn on_open(self, on_open: VoidCallback) -> SubmenuButton
Dart SubmenuButton(onOpen:).
Sourcepub fn on_close(self, on_close: VoidCallback) -> SubmenuButton
pub fn on_close(self, on_close: VoidCallback) -> SubmenuButton
Dart SubmenuButton(onClose:).
Sourcepub fn controller(self, controller: MenuControllerRef) -> SubmenuButton
pub fn controller(self, controller: MenuControllerRef) -> SubmenuButton
Dart SubmenuButton(controller:).
Sourcepub fn style(self, style: ButtonStyle) -> SubmenuButton
pub fn style(self, style: ButtonStyle) -> SubmenuButton
Dart SubmenuButton(style:).
Dart SubmenuButton(menuStyle:).
Sourcepub fn alignment_offset(self, alignment_offset: Offset) -> SubmenuButton
pub fn alignment_offset(self, alignment_offset: Offset) -> SubmenuButton
Dart SubmenuButton(alignmentOffset:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> SubmenuButton
pub fn clip_behavior(self, clip_behavior: Clip) -> SubmenuButton
Dart SubmenuButton(clipBehavior:).
Sourcepub fn focus_node(self, focus_node: FocusNodeRef) -> SubmenuButton
pub fn focus_node(self, focus_node: FocusNodeRef) -> SubmenuButton
Dart SubmenuButton(focusNode:).
Sourcepub fn states_controller(
self,
states_controller: Ref<WidgetStatesController>,
) -> SubmenuButton
pub fn states_controller( self, states_controller: Ref<WidgetStatesController>, ) -> SubmenuButton
Dart SubmenuButton(statesController:).
Sourcepub fn leading_icon<K>(self, leading_icon: impl IntoWidget<K>) -> SubmenuButton
pub fn leading_icon<K>(self, leading_icon: impl IntoWidget<K>) -> SubmenuButton
Dart SubmenuButton(leadingIcon:).
Sourcepub fn trailing_icon<K>(
self,
trailing_icon: impl IntoWidget<K>,
) -> SubmenuButton
pub fn trailing_icon<K>( self, trailing_icon: impl IntoWidget<K>, ) -> SubmenuButton
Dart SubmenuButton(trailingIcon:).
Dart SubmenuButton(submenuIcon:).
Sourcepub fn use_root_overlay(self, use_root_overlay: bool) -> SubmenuButton
pub fn use_root_overlay(self, use_root_overlay: bool) -> SubmenuButton
Dart SubmenuButton(useRootOverlay:).
Sourcepub fn hover_open_delay(self, hover_open_delay: Duration) -> SubmenuButton
pub fn hover_open_delay(self, hover_open_delay: Duration) -> SubmenuButton
Dart SubmenuButton(hoverOpenDelay:).
Sourcepub fn animated(self, animated: bool) -> SubmenuButton
pub fn animated(self, animated: bool) -> SubmenuButton
Dart SubmenuButton(animated:).
Sourcepub fn on_animation_status_changed(
self,
on_animation_status_changed: ValueChanged<AnimationStatus>,
) -> SubmenuButton
pub fn on_animation_status_changed( self, on_animation_status_changed: ValueChanged<AnimationStatus>, ) -> SubmenuButton
Dart SubmenuButton(onAnimationStatusChanged:).
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 SubmenuButton’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
SubmenuButton, as well as its overlay color, with all of the standard
opacity adjustments for the pressed, focused, and hovered states, one
could write:
SubmenuButton::new(menu_children, Some(Text::new("Button Label")))
.leading_icon(Icon::new(Some(Icons::pets())))
.style(SubmenuButton::style_from().foreground_color(Colors::GREEN.primary()).build())Trait Implementations§
Source§type State = SubmenuButtonState
type State = SubmenuButtonState
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) -> SubmenuButtonState
fn create_state(&self) -> SubmenuButtonState
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§
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.