mirror of
https://github.com/flutter/flutter
synced 2024-08-24 18:36:03 +00:00
Fix for issue 140372 (#144947)
*Continuing work from the PR https://github.com/flutter/flutter/pull/140373* Add the ability to set route settings on PopupMenuButton Fixes https://github.com/flutter/flutter/issues/140372 Added UTs as requested
This commit is contained in:
parent
98369bdd50
commit
993f554e4c
|
@ -1150,6 +1150,7 @@ class PopupMenuButton<T> extends StatefulWidget {
|
||||||
this.clipBehavior = Clip.none,
|
this.clipBehavior = Clip.none,
|
||||||
this.useRootNavigator = false,
|
this.useRootNavigator = false,
|
||||||
this.popUpAnimationStyle,
|
this.popUpAnimationStyle,
|
||||||
|
this.routeSettings,
|
||||||
this.style,
|
this.style,
|
||||||
}) : assert(
|
}) : assert(
|
||||||
!(child != null && icon != null),
|
!(child != null && icon != null),
|
||||||
|
@ -1345,6 +1346,11 @@ class PopupMenuButton<T> extends StatefulWidget {
|
||||||
/// If this is null, then the default animation will be used.
|
/// If this is null, then the default animation will be used.
|
||||||
final AnimationStyle? popUpAnimationStyle;
|
final AnimationStyle? popUpAnimationStyle;
|
||||||
|
|
||||||
|
/// Optional route settings for the menu.
|
||||||
|
///
|
||||||
|
/// See [RouteSettings] for details.
|
||||||
|
final RouteSettings? routeSettings;
|
||||||
|
|
||||||
/// Customizes this icon button's appearance.
|
/// Customizes this icon button's appearance.
|
||||||
///
|
///
|
||||||
/// The [style] is only used for Material 3 [IconButton]s. If [ThemeData.useMaterial3]
|
/// The [style] is only used for Material 3 [IconButton]s. If [ThemeData.useMaterial3]
|
||||||
|
@ -1412,6 +1418,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
||||||
clipBehavior: widget.clipBehavior,
|
clipBehavior: widget.clipBehavior,
|
||||||
useRootNavigator: widget.useRootNavigator,
|
useRootNavigator: widget.useRootNavigator,
|
||||||
popUpAnimationStyle: widget.popUpAnimationStyle,
|
popUpAnimationStyle: widget.popUpAnimationStyle,
|
||||||
|
routeSettings: widget.routeSettings,
|
||||||
)
|
)
|
||||||
.then<void>((T? newValue) {
|
.then<void>((T? newValue) {
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
|
|
|
@ -926,6 +926,39 @@ void main() {
|
||||||
expect(tester.getTopLeft(popupFinder), buttonTopLeft);
|
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 {
|
testWidgets('PopupMenu positioning around display features', (WidgetTester tester) async {
|
||||||
final Key buttonKey = UniqueKey();
|
final Key buttonKey = UniqueKey();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue