showMenu function

Route showMenu(
  1. BuildContext context,
  2. Widget menu, {
  3. Axis? menuAxis,
  4. Position? menuPosition,
  5. BuildContext? alignmentContext,
  6. dynamic menuStyle,
  7. MenuManagerController? menuManagerController,
  8. Color? barrierColor,
  9. Route? route,

Shows the menu at the menuPosition.

alignmentContext is a local space where positioning occurs. The menu may be outside this space depending on menuPosition value.

A barrier is built only for the centered menu.

An existing menu can be updated by providing its route.

Returns the route of a shown menu. The route's Route.popped future completes when the menu is dismissed.


Route showMenu(
  BuildContext context,
  Widget menu, {
  Axis? menuAxis,
  Position? menuPosition,
  BuildContext? alignmentContext,
  MenuStyle? menuStyle,
  MenuManagerController? menuManagerController,
  Color? barrierColor,
  Route? route
}) {
  menuPosition ??= const Position.centered();
  barrierColor ??= Theme.of(context).brightness == Brightness.light ?
    Colors.black54 :;

  Widget menuOverlay = MenuManager(
    menuAxis: menuAxis,
    menuStyle: menuStyle,
    targetContext: context,
    menu: menu,
    closeCallback: () {
      (route as MenuRoute).removeAndComplete(context);
    menuPosition: menuPosition,
    alignmentContext: alignmentContext,
    menuManagerController: menuManagerController,

  if (menuPosition.isCentered && alignmentContext == null) {
    menuOverlay = ColoredBox(
      color: barrierColor,
      child: menuOverlay

  if (route == null) {
    route = MenuRoute(menuOverlay);
    Navigator.push(context, route);
    return route;

  final overlayRoute = route as OverlayRouteBuilder;
  overlayRoute.widget = menuOverlay;
  if (!overlayRoute.isActive)
    Navigator.push(context, route);

  return route;