showMongolMenu<T> function
- required BuildContext context,
- required RelativeRect position,
- required List<
MongolPopupMenuEntry< items,T> > - T? initialValue,
- double? elevation,
- String? semanticLabel,
- ShapeBorder? shape,
- Color? color,
Show a popup menu that contains the items
at position
.
items
should be non-null and not empty.
If initialValue
is specified then the first item with a matching value
will be highlighted and the value of position
gives the rectangle whose
horizontal center will be aligned with the horizontal center of the highlighted
item (when possible).
If initialValue
is not specified then the right side of the menu will be aligned
with the right side of the position
rectangle.
In both cases, the menu position will be adjusted if necessary to fit on the screen.
Vertically, 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 top edge of the screen, then the top edge of the menu is aligned with
the top edge of the position
, and the menu grows to the bottom. If both
edges of the position
are equidistant from the opposite edge of the
screen, then it grows down.
The positioning of the initialValue
at the position
is implemented by
iterating over the items
to find the first whose
MongolPopupMenuEntry.represents method returns true for initialValue
, and then
summing the values of MongolPopupMenuEntry.width 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 useRootNavigator
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 semanticLabel
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.popupMenuLabel.
See also:
- MongolPopupMenuItem, a popup menu entry for a single value.
- MongolPopupMenuDivider, a popup menu entry that is just a vertical line.
- MongolPopupMenuButton, which provides an IconButton that shows a menu by calling this method automatically.
- SemanticsConfiguration.namesRoute, for a description of edge triggered semantics.
Implementation
Future<T?> showMongolMenu<T>({
required BuildContext context,
required RelativeRect position,
required List<MongolPopupMenuEntry<T>> items,
T? initialValue,
double? elevation,
String? semanticLabel,
ShapeBorder? shape,
Color? color,
bool useRootNavigator = false,
}) {
assert(items.isNotEmpty);
semanticLabel ??= MaterialLocalizations.of(context).popupMenuLabel;
final NavigatorState navigator =
Navigator.of(context, rootNavigator: useRootNavigator);
return navigator.push(_PopupMenuRoute<T>(
position: position,
items: items,
initialValue: initialValue,
elevation: elevation,
semanticLabel: semanticLabel,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
shape: shape,
color: color,
capturedThemes:
InheritedTheme.capture(from: context, to: navigator.context),
));
}