diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 5083add60bd..9fc7d80d543 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -1150,6 +1150,7 @@ class PopupMenuButton extends StatefulWidget { this.clipBehavior = Clip.none, this.useRootNavigator = false, this.popUpAnimationStyle, + this.routeSettings, this.style, }) : assert( !(child != null && icon != null), @@ -1345,6 +1346,11 @@ class PopupMenuButton extends StatefulWidget { /// If this is null, then the default animation will be used. final AnimationStyle? popUpAnimationStyle; + /// Optional route settings for the menu. + /// + /// See [RouteSettings] for details. + final RouteSettings? routeSettings; + /// Customizes this icon button's appearance. /// /// The [style] is only used for Material 3 [IconButton]s. If [ThemeData.useMaterial3] @@ -1412,6 +1418,7 @@ class PopupMenuButtonState extends State> { clipBehavior: widget.clipBehavior, useRootNavigator: widget.useRootNavigator, popUpAnimationStyle: widget.popUpAnimationStyle, + routeSettings: widget.routeSettings, ) .then((T? newValue) { if (!mounted) { diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index cfce4bc128a..435344a3eb5 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -926,6 +926,39 @@ void main() { expect(tester.getTopLeft(popupFinder), buttonTopLeft); }); + testWidgets('Popup menu with RouteSettings', (WidgetTester tester) async { + final Key buttonKey = UniqueKey(); + const RouteSettings popupRoute = RouteSettings(name: '/popup'); + late RouteSettings currentRouteSetting; + + await tester.pumpWidget( + MaterialApp( + navigatorObservers: [ + _ClosureNavigatorObserver(onDidChange: (Route newRoute) { + currentRouteSetting = newRoute.settings; + }), + ], + home: Scaffold( + body: PopupMenuButton( + key: buttonKey, + routeSettings: popupRoute, + itemBuilder: (_) => >[ + const PopupMenuItem(value: 1, child: Text('Item 1')), + const PopupMenuItem(value: 2, child: Text('Item 2')), + ], + child: const Text('Show Menu'), + ), + ), + ), + ); + + final Finder buttonFinder = find.byKey(buttonKey); + await tester.tap(buttonFinder); + await tester.pumpAndSettle(); + + expect(currentRouteSetting, popupRoute); + }); + testWidgets('PopupMenu positioning around display features', (WidgetTester tester) async { final Key buttonKey = UniqueKey();