Skip to main content

PopupMenuButton

Struct PopupMenuButton 

Source
pub struct PopupMenuButton<T: 'static> {
Show 31 fields pub key: Option<KeyRef>, pub item_builder: PopupMenuItemBuilder<T>, pub initial_value: Option<T>, pub on_opened: Option<Listener>, pub on_selected: Option<PopupMenuItemSelected<T>>, pub on_canceled: Option<PopupMenuCanceled>, pub tooltip: Option<String>, pub elevation: Option<f64>, pub shadow_color: Option<Color>, pub surface_tint_color: Option<Color>, pub padding: EdgeInsetsGeometry, pub menu_padding: Option<EdgeInsetsGeometry>, pub splash_radius: Option<f64>, pub child: Option<WidgetRef>, pub border_radius: Option<BorderRadius>, pub icon: Option<WidgetRef>, pub offset: Offset, pub enabled: bool, pub shape: Option<ShapeBorderRef>, pub color: Option<Color>, pub icon_color: Option<Color>, pub enable_feedback: Option<bool>, pub icon_size: Option<f64>, pub constraints: Option<BoxConstraints>, pub position: Option<PopupMenuPosition>, pub clip_behavior: Clip, pub use_root_navigator: bool, pub pop_up_animation_style: Option<AnimationStyle>, pub route_settings: Option<RouteSettingsRef>, pub style: Option<ButtonStyle>, pub request_focus: Option<bool>,
}
Expand description

Displays a menu when pressed and calls on_selected when the menu is dismissed because an item was selected. The value passed to on_selected is the value of the selected menu item.

One of child or icon may be provided, but not both. If icon is provided, then PopupMenuButton behaves like an IconButton.

If both are None, then a standard overflow icon is created (depending on the platform).

§Updating to MenuAnchor

There is a Material 3 component, MenuAnchor that is preferred for applications that are configured for Material 3 (see ThemeData::use_material3). The MenuAnchor widget’s visuals are a little bit different, see the Material 3 spec at https://m3.material.io/components/menus/guidelines for more details.

The MenuAnchor widget’s API is also slightly different. MenuAnchor can be used to wrap any widget that should have a menu associated with it, and it uses MenuItemButton for the items it shows.

See also:

Fields§

§key: Option<KeyRef>§item_builder: PopupMenuItemBuilder<T>

Called when the button is pressed to create the items to show in the menu.

§initial_value: Option<T>

The value of the menu item, if any, that should be highlighted when the menu opens.

§on_opened: Option<Listener>

Called when the popup menu is shown.

§on_selected: Option<PopupMenuItemSelected<T>>

Called when the user selects a value from the popup menu created by this button.

If the popup menu is dismissed without selecting a value, on_canceled is called instead.

§on_canceled: Option<PopupMenuCanceled>

Called when the user dismisses the popup menu without selecting an item.

If the user selects a value, on_selected is called instead.

§tooltip: Option<String>

Text that describes the action that will occur when the button is pressed.

This text is displayed when the user long-presses on the button and is used for accessibility.

§elevation: Option<f64>

The z-coordinate at which to place the menu when open. This controls the size of the shadow below the menu.

Defaults to 8, the appropriate elevation for popup menus.

§shadow_color: Option<Color>

The color used to paint the shadow below the menu.

If None then the ambient PopupMenuThemeData::shadow_color is used. If that is None too, then the overall theme’s ThemeData::shadow_color (default black) is used.

§surface_tint_color: Option<Color>

The color used as an overlay on color to indicate elevation.

This is not recommended for use. Material 3 spec introduced a set of tone-based surfaces and surface containers in its ColorScheme, which provide more flexibility. The intention is to eventually remove surface tint color from the framework.

If None, PopupMenuThemeData::surface_tint_color is used. If that is also None, the default value is Colors::TRANSPARENT.

See Material::surface_tint_color for more details on how this overlay is applied.

§padding: EdgeInsetsGeometry

Matches IconButton’s 8 dps padding by default. In some cases, notably where this button appears as the trailing element of a list item, it’s useful to be able to set the padding to zero.

§menu_padding: Option<EdgeInsetsGeometry>

If provided, menu padding is used for empty space around the outside of the popup menu.

If this property is None, then PopupMenuThemeData::menu_padding is used. If PopupMenuThemeData::menu_padding is also None, then vertical padding of 8 pixels is used.

§splash_radius: Option<f64>

The splash radius.

If None, default splash radius of InkWell or IconButton is used.

§child: Option<WidgetRef>

If provided, child is the widget used for this button and the button will utilize an InkWell for taps.

§border_radius: Option<BorderRadius>

The border radius for the InkWell that wraps the child.

Defaults to None, which indicates no border radius should be applied.

§icon: Option<WidgetRef>

If provided, the icon is used for this button and the button will behave like an IconButton.

§offset: Offset

The offset is applied relative to the initial position set by the position.

When not set, the offset defaults to Offset::ZERO.

§enabled: bool

Whether this popup menu button is interactive.

Defaults to true.

If true, the button will respond to presses by displaying the menu.

If false, the button is styled with the disabled color from the current Theme and will not respond to presses or show the popup menu and on_selected, on_canceled and item_builder will not be called.

This can be useful in situations where the app needs to show the button, but doesn’t currently have anything to show in the menu.

§shape: Option<ShapeBorderRef>

If provided, the shape used for the menu.

If this property is None, then PopupMenuThemeData::shape is used. If PopupMenuThemeData::shape is also None, then the default shape for MaterialType::Card is used. This default shape is a rectangle with rounded edges of BorderRadius::circular(2.0).

§color: Option<Color>

If provided, the background color used for the menu.

If this property is None, then PopupMenuThemeData::color is used. If PopupMenuThemeData::color is also None, then ThemeData::card_color is used in Material 2. In Material3, defaults to ColorScheme::surface_container.

§icon_color: Option<Color>

If provided, this color is used for the button icon.

If this property is None, then PopupMenuThemeData::icon_color is used. If PopupMenuThemeData::icon_color is also None then defaults to IconThemeData::color.

§enable_feedback: Option<bool>

Whether detected gestures should provide acoustic and/or haptic feedback.

For example, on Android a tap will produce a clicking sound and a long-press will produce a short vibration, when feedback is enabled.

See also:

  • Feedback for providing platform-specific feedback to certain actions.
§icon_size: Option<f64>

If provided, the size of the Icon.

If this property is None, then IconThemeData::size is used. If IconThemeData::size is also None, then default size is 24.0 pixels.

§constraints: Option<BoxConstraints>

Optional size constraints for the menu.

When unspecified, defaults to:

BoxConstraints::new().min_width(2.0 * 56.0).max_width(5.0 * 56.0)

The default constraints ensure that the menu width matches maximum width recommended by the Material Design guidelines. Specifying this parameter enables creation of menu wider than the default maximum width.

§position: Option<PopupMenuPosition>

Whether the popup menu is positioned over or under the popup menu button.

offset is used to change the position of the popup menu relative to the position set by this parameter.

If this property is None, then PopupMenuThemeData::position is used. If PopupMenuThemeData::position is also None, then the position defaults to PopupMenuPosition::Over which makes the popup menu appear directly over the button that was used to create it.

§clip_behavior: Clip

{@macro cupertino_ui.Material.clipBehavior}

The clip_behavior argument is used the clip shape of the menu.

Defaults to Clip::None.

§use_root_navigator: bool

Used to determine whether to push the menu to the Navigator furthest from or nearest to the given context.

Defaults to false.

§pop_up_animation_style: Option<AnimationStyle>

Used to override the default animation curves and durations of the popup menu’s open and close transitions.

If AnimationStyle::curve is provided, it will be used to override the default popup animation curve. Otherwise, defaults to Curves::linear.

If AnimationStyle::reverse_curve is provided, it will be used to override the default popup animation reverse curve. Otherwise, defaults to Interval(0.0, 2.0 / 3.0).

If AnimationStyle::duration is provided, it will be used to override the default popup animation duration. Otherwise, defaults to 300ms.

To disable the theme animation, use AnimationStyle::NO_ANIMATION.

If this is None, then the default animation will be used.

§route_settings: Option<RouteSettingsRef>

Optional route settings for the menu.

See RouteSettings for details.

§style: Option<ButtonStyle>

Customizes this icon button’s appearance.

The style is only used for Material 3 IconButtons. If ThemeData::use_material3 is set to true, style is preferred for icon button customization, and any parameters defined in style will override the same parameters in IconButton.

None by default.

§request_focus: Option<bool>

Whether to request focus when the menu appears.

If None, Navigator::request_focus will be used instead.

Implementations§

Source§

impl<T: Clone + PartialEq + 'static> PopupMenuButton<T>

Source

pub fn new( item_builder: impl Fn(&mut App, BuildContext) -> Vec<PopupMenuEntryRef<T>> + 'static, ) -> PopupMenuButton<T>

Creates a button that shows a popup menu.

Source

pub fn key(self, key: KeyRef) -> PopupMenuButton<T>

Dart PopupMenuButton(key:).

Source

pub fn initial_value(self, initial_value: T) -> PopupMenuButton<T>

Dart PopupMenuButton(initialValue:).

Source

pub fn on_opened(self, on_opened: Listener) -> PopupMenuButton<T>

Dart PopupMenuButton(onOpened:).

Source

pub fn on_canceled(self, on_canceled: PopupMenuCanceled) -> PopupMenuButton<T>

Dart PopupMenuButton(onCanceled:).

Source

pub fn elevation(self, elevation: f64) -> PopupMenuButton<T>

Dart PopupMenuButton(elevation:).

Source

pub fn shadow_color(self, shadow_color: Color) -> PopupMenuButton<T>

Dart PopupMenuButton(shadowColor:).

Source

pub fn surface_tint_color(self, surface_tint_color: Color) -> PopupMenuButton<T>

Dart PopupMenuButton(surfaceTintColor:).

Source

pub fn menu_padding( self, menu_padding: EdgeInsetsGeometry, ) -> PopupMenuButton<T>

Dart PopupMenuButton(menuPadding:).

Source

pub fn border_radius(self, border_radius: BorderRadius) -> PopupMenuButton<T>

Dart PopupMenuButton(borderRadius:).

Source

pub fn splash_radius(self, splash_radius: f64) -> PopupMenuButton<T>

Dart PopupMenuButton(splashRadius:).

Source

pub fn icon_size(self, icon_size: f64) -> PopupMenuButton<T>

Dart PopupMenuButton(iconSize:).

Source

pub fn color(self, color: Color) -> PopupMenuButton<T>

Dart PopupMenuButton(color:).

Source

pub fn icon_color(self, icon_color: Color) -> PopupMenuButton<T>

Dart PopupMenuButton(iconColor:).

Source

pub fn enable_feedback(self, enable_feedback: bool) -> PopupMenuButton<T>

Dart PopupMenuButton(enableFeedback:).

Source

pub fn constraints(self, constraints: BoxConstraints) -> PopupMenuButton<T>

Dart PopupMenuButton(constraints:).

Source

pub fn position(self, position: PopupMenuPosition) -> PopupMenuButton<T>

Dart PopupMenuButton(position:).

Source

pub fn pop_up_animation_style( self, pop_up_animation_style: AnimationStyle, ) -> PopupMenuButton<T>

Dart PopupMenuButton(popUpAnimationStyle:).

Source

pub fn route_settings( self, route_settings: RouteSettingsRef, ) -> PopupMenuButton<T>

Dart PopupMenuButton(routeSettings:).

Source

pub fn style(self, style: ButtonStyle) -> PopupMenuButton<T>

Dart PopupMenuButton(style:).

Source

pub fn request_focus(self, request_focus: bool) -> PopupMenuButton<T>

Dart PopupMenuButton(requestFocus:).

Source

pub fn on_selected( self, on_selected: impl Fn(&mut App, T) + 'static, ) -> PopupMenuButton<T>

Dart PopupMenuButton(onSelected:).

Source

pub fn tooltip(self, tooltip: impl Into<String>) -> PopupMenuButton<T>

Dart PopupMenuButton(tooltip:).

Source

pub fn padding( self, padding: impl Into<EdgeInsetsGeometry>, ) -> PopupMenuButton<T>

Dart PopupMenuButton(padding:).

Source

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

Dart PopupMenuButton(child:).

Source

pub fn icon<K>(self, icon: impl IntoWidget<K>) -> PopupMenuButton<T>

Dart PopupMenuButton(icon:).

Source

pub fn offset(self, offset: Offset) -> PopupMenuButton<T>

Dart PopupMenuButton(offset:).

Source

pub fn enabled(self, enabled: bool) -> PopupMenuButton<T>

Dart PopupMenuButton(enabled:).

Source

pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> PopupMenuButton<T>

Dart PopupMenuButton(shape:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> PopupMenuButton<T>

Dart PopupMenuButton(clipBehavior:).

Source

pub fn use_root_navigator(self, use_root_navigator: bool) -> PopupMenuButton<T>

Dart PopupMenuButton(useRootNavigator:).

Trait Implementations§

Source§

impl<T: 'static> Debug for PopupMenuButton<T>

Source§

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

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

impl<T: Clone + PartialEq + 'static> StatefulWidget for PopupMenuButton<T>

Source§

type State = PopupMenuButtonState<T>

The state this widget creates.
Source§

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

Source§

fn debug_check_constructor(&self)

Source§

fn create_state(&self) -> PopupMenuButtonState<T>

Creates the mutable state for this widget at a given location in the tree. Read more
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 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<T> !RefUnwindSafe for PopupMenuButton<T>

§

impl<T> !Send for PopupMenuButton<T>

§

impl<T> !Sync for PopupMenuButton<T>

§

impl<T> !UnwindSafe for PopupMenuButton<T>

§

impl<T> Forget for PopupMenuButton<T>

§

impl<T> Freeze for PopupMenuButton<T>
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyElement) -> Vec<PopupMenuEntryRef<T>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyElement) -> Vec<PopupMenuEntryRef<T>>>>: Freeze, T: 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, T)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, T)>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const RcInner<dyn ShapeBorder> is !null: Freeze, PhantomData<RcInner<dyn ShapeBorder>>: Freeze, *const RcInner<dyn Curve> is !null: Freeze, PhantomData<RcInner<dyn Curve>>: Freeze, *const RcInner<dyn Any> is !null: Freeze, PhantomData<RcInner<dyn Any>>: Freeze, *const RcInner<dyn Page> is !null: Freeze, PhantomData<RcInner<dyn Page>>: 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,

§

impl<T> Move for PopupMenuButton<T>

§

impl<T> Unpin for PopupMenuButton<T>

§

impl<T> UnsafeUnpin for PopupMenuButton<T>
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyElement) -> Vec<PopupMenuEntryRef<T>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyElement) -> Vec<PopupMenuEntryRef<T>>>>: UnsafeUnpin, T: 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, T)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, T)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin, *const RcInner<dyn ShapeBorder> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ShapeBorder>>: UnsafeUnpin, *const RcInner<dyn Curve> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Curve>>: UnsafeUnpin, *const RcInner<dyn Any> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Any>>: UnsafeUnpin, *const RcInner<dyn Page> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Page>>: 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,

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>