Skip to content

Commit

Permalink
Fix for issue 140372 (flutter#144947)
Browse files Browse the repository at this point in the history
*Continuing work from the PR flutter#140373

Add the ability to set route settings on PopupMenuButton

Fixes flutter#140372

Added UTs as requested
  • Loading branch information
prasadsunny1 committed Mar 18, 2024
1 parent 98369bd commit 993f554
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/flutter/lib/src/material/popup_menu.dart
Expand Up @@ -1150,6 +1150,7 @@ class PopupMenuButton<T> extends StatefulWidget {
this.clipBehavior = Clip.none,
this.useRootNavigator = false,
this.popUpAnimationStyle,
this.routeSettings,
this.style,
}) : assert(
!(child != null && icon != null),
Expand Down Expand Up @@ -1345,6 +1346,11 @@ class PopupMenuButton<T> 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]
Expand Down Expand Up @@ -1412,6 +1418,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
clipBehavior: widget.clipBehavior,
useRootNavigator: widget.useRootNavigator,
popUpAnimationStyle: widget.popUpAnimationStyle,
routeSettings: widget.routeSettings,
)
.then<void>((T? newValue) {
if (!mounted) {
Expand Down
33 changes: 33 additions & 0 deletions packages/flutter/test/material/popup_menu_test.dart
Expand Up @@ -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: <NavigatorObserver>[
_ClosureNavigatorObserver(onDidChange: (Route<dynamic> newRoute) {
currentRouteSetting = newRoute.settings;
}),
],
home: Scaffold(
body: PopupMenuButton<int>(
key: buttonKey,
routeSettings: popupRoute,
itemBuilder: (_) => <PopupMenuItem<int>>[
const PopupMenuItem<int>(value: 1, child: Text('Item 1')),
const PopupMenuItem<int>(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();

Expand Down

0 comments on commit 993f554

Please sign in to comment.