pub struct ShowMenu<T: Clone + PartialEq + 'static> { /* private fields */ }Expand description
Show a popup menu that contains the items at position.
The items parameter must not be empty.
Only one of position or position_builder should be provided. Providing both throws an
assertion error. The position_builder is called whenever the menu’s overlay is laid out,
with the overlay’s constraints, and it should return the position of the menu.
If initial_value is specified then the first item with a matching value will be
highlighted and the value of position gives the rectangle whose vertical center will be
aligned with the vertical center of the highlighted item (when possible).
If initial_value is not specified then the top of the menu will be aligned with the top
of the position rectangle.
In both cases, the menu position will be adjusted if necessary to fit on the screen.
Horizontally, the menu is positioned so that it grows in the direction that has the most
room. For example, if the position describes a rectangle on the left edge of the screen,
then the left edge of the menu is aligned with the left edge of the position, and the
menu grows to the right. If both edges of the position are equidistant from the opposite
edge of the screen, then the ambient Directionality is used as a tie-breaker, preferring
to grow in the reading direction.
The positioning of the initial_value at the position is implemented by iterating over
the items to find the first whose PopupMenuEntry::represents method returns true for
initial_value, and then summing the values of PopupMenuEntry::height for all the
preceding widgets in the list.
The elevation argument specifies the z-coordinate at which to place the menu. The
elevation defaults to 8, the appropriate elevation for popup menus.
The context argument is used to look up the Navigator and Theme for the menu. It
is only used when the method is called. Its corresponding widget can be safely removed from
the tree before the popup menu is closed.
The use_root_navigator argument is used to determine whether to push the menu to the
Navigator furthest from or nearest to the given context. It is false by default.
The semantic_label argument is used by accessibility frameworks to announce screen
transitions when the menu is opened and closed. If this label is not provided, it will
default to MaterialLocalizations::popup_menu_label.
The clip_behavior argument is used to clip the shape of the menu. Defaults to
Clip::None.
The request_focus argument specifies whether the menu should request focus when it
appears. If it is None, Navigator::request_focus is used instead.
The future resolves to the item’s value the menu was popped with, erased as a route’s
result is, or None if the menu was dismissed.
See also:
PopupMenuItem, a popup menu entry for a single value.PopupMenuDivider, a popup menu entry that is just a horizontal line.CheckedPopupMenuItem, a popup menu item with a checkmark.PopupMenuButton, which provides anIconButtonthat shows a menu by calling this method automatically.SemanticsConfiguration::names_route, for a description of edge triggered semantics.
Implementations§
Source§impl<T: Clone + PartialEq + 'static> ShowMenu<T>
impl<T: Clone + PartialEq + 'static> ShowMenu<T>
Sourcepub fn new(items: Vec<PopupMenuEntryRef<T>>) -> ShowMenu<T>
pub fn new(items: Vec<PopupMenuEntryRef<T>>) -> ShowMenu<T>
Creates a builder for a popup menu; Dart’s showMenu required argument is the items,
and every other argument is a setter.
Sourcepub fn position(self, position: RelativeRect) -> ShowMenu<T>
pub fn position(self, position: RelativeRect) -> ShowMenu<T>
The rectangle the menu is positioned against.
Sourcepub fn position_builder(
self,
position_builder: PopupMenuPositionBuilder,
) -> ShowMenu<T>
pub fn position_builder( self, position_builder: PopupMenuPositionBuilder, ) -> ShowMenu<T>
A builder of the rectangle the menu is positioned against.
Sourcepub fn initial_value(self, initial_value: T) -> ShowMenu<T>
pub fn initial_value(self, initial_value: T) -> ShowMenu<T>
The value the menu opens with.
Sourcepub fn shadow_color(self, shadow_color: Color) -> ShowMenu<T>
pub fn shadow_color(self, shadow_color: Color) -> ShowMenu<T>
The color of the menu’s shadow.
Sourcepub fn surface_tint_color(self, surface_tint_color: Color) -> ShowMenu<T>
pub fn surface_tint_color(self, surface_tint_color: Color) -> ShowMenu<T>
The color of the menu’s surface tint.
Sourcepub fn semantic_label(self, semantic_label: impl Into<String>) -> ShowMenu<T>
pub fn semantic_label(self, semantic_label: impl Into<String>) -> ShowMenu<T>
The semantic label announced when the menu opens and closes.
Sourcepub fn shape(self, shape: impl Into<ShapeBorderRef>) -> ShowMenu<T>
pub fn shape(self, shape: impl Into<ShapeBorderRef>) -> ShowMenu<T>
The shape of the menu.
The padding inside the menu.
Whether to push the menu to the root navigator. Defaults to false.
Sourcepub fn constraints(self, constraints: BoxConstraints) -> ShowMenu<T>
pub fn constraints(self, constraints: BoxConstraints) -> ShowMenu<T>
The size constraints on the menu.
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> ShowMenu<T>
pub fn clip_behavior(self, clip_behavior: Clip) -> ShowMenu<T>
The clip behavior of the menu. Defaults to Clip::None.
Sourcepub fn route_settings(self, route_settings: RouteSettingsRef) -> ShowMenu<T>
pub fn route_settings(self, route_settings: RouteSettingsRef) -> ShowMenu<T>
The route settings passed to the menu’s route.
Sourcepub fn pop_up_animation_style(
self,
pop_up_animation_style: AnimationStyle,
) -> ShowMenu<T>
pub fn pop_up_animation_style( self, pop_up_animation_style: AnimationStyle, ) -> ShowMenu<T>
An animation style that overrides the menu’s animation.
Sourcepub fn request_focus(self, request_focus: bool) -> ShowMenu<T>
pub fn request_focus(self, request_focus: bool) -> ShowMenu<T>
Whether the menu’s route requests focus when it appears.
Sourcepub fn show(
self,
app: &mut App,
context: BuildContext,
) -> CompleterFuture<RouteResult> ⓘ
pub fn show( self, app: &mut App, context: BuildContext, ) -> CompleterFuture<RouteResult> ⓘ
Shows the menu and returns the value the menu was popped with.