showArnaMenu<T> function
- required BuildContext context,
- required RelativeRect position,
- required List<
ArnaPopupMenuEntry> items, - String? semanticLabel,
- Color? color,
Show a popup menu that contains the items
at position
.
items
should be non-null and not empty.
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 context
argument is used to look up the Navigator 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:
- ArnaPopupMenuItem, a popup menu entry for a single value.
- ArnaPopupMenuDivider, a popup menu entry that is just a horizontal line.
- ArnaPopupMenuButton, which provides an ArnaButton.icon that shows a menu by calling this method automatically.
- SemanticsConfiguration.namesRoute, for a description of edge triggered semantics.
Implementation
Future<T?> showArnaMenu<T>({
required BuildContext context,
required RelativeRect position,
required List<ArnaPopupMenuEntry> items,
String? semanticLabel,
Color? color,
bool useRootNavigator = false,
}) {
assert(items.isNotEmpty);
final NavigatorState navigator = Navigator.of(
context,
rootNavigator: useRootNavigator,
);
return navigator.push(
_ArnaPopupMenuRoute(
position: position,
items: items,
semanticLabel:
semanticLabel ?? MaterialLocalizations.of(context).popupMenuLabel,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
color: color,
),
);
}