Fix for "Pass RouteSettings to the internal Route in showCupertinoModalPopup" (#67990)
This commit is contained in:
parent
4982555982
commit
1aaa455f1b
@ -1031,6 +1031,9 @@ class _CupertinoModalPopupRoute<T> extends PopupRoute<T> {
|
||||
/// The `semanticsDismissible` argument is used to determine whether the
|
||||
/// semantics of the modal barrier are included in the semantics tree.
|
||||
///
|
||||
/// The `routeSettings` argument is used to provide [RouteSettings] to the
|
||||
/// created Route.
|
||||
///
|
||||
/// The `builder` argument typically builds a [CupertinoActionSheet] widget.
|
||||
/// Content below the widget is dimmed with a [ModalBarrier]. The widget built
|
||||
/// by the `builder` does not share a context with the location that
|
||||
@ -1054,6 +1057,7 @@ Future<T> showCupertinoModalPopup<T>({
|
||||
bool barrierDismissible = true,
|
||||
bool useRootNavigator = true,
|
||||
bool? semanticsDismissible,
|
||||
RouteSettings? routeSettings,
|
||||
}) {
|
||||
assert(useRootNavigator != null);
|
||||
return Navigator.of(context, rootNavigator: useRootNavigator)!.push(
|
||||
@ -1064,6 +1068,7 @@ Future<T> showCupertinoModalPopup<T>({
|
||||
builder: builder,
|
||||
filter: filter,
|
||||
semanticsDismissible: semanticsDismissible,
|
||||
settings: routeSettings,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1345,6 +1345,38 @@ void main() {
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('showCupertinoModalPopup passes RouteSettings to PopupRoute', (WidgetTester tester) async {
|
||||
final RouteSettingsObserver routeSettingsObserver = RouteSettingsObserver();
|
||||
|
||||
await tester.pumpWidget(CupertinoApp(
|
||||
navigatorObservers: <NavigatorObserver>[routeSettingsObserver],
|
||||
home: Navigator(
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
return PageRouteBuilder<dynamic>(
|
||||
pageBuilder: (BuildContext context, Animation<double> _,
|
||||
Animation<double> __) {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
await showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => const SizedBox(),
|
||||
routeSettings: const RouteSettings(name: '/modal'),
|
||||
);
|
||||
},
|
||||
child: const Text('tap'),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
// Open the dialog.
|
||||
await tester.tap(find.text('tap'));
|
||||
|
||||
expect(routeSettingsObserver.routeName, '/modal');
|
||||
});
|
||||
|
||||
testWidgets('showCupertinoModalPopup transparent barrier color is transparent', (WidgetTester tester) async {
|
||||
const Color _kTransparentColor = Color(0x00000000);
|
||||
|
||||
@ -1657,6 +1689,18 @@ class DialogObserver extends NavigatorObserver {
|
||||
}
|
||||
}
|
||||
|
||||
class RouteSettingsObserver extends NavigatorObserver {
|
||||
String? routeName;
|
||||
|
||||
@override
|
||||
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
||||
if (route.toString().contains('_CupertinoModalPopupRoute')) {
|
||||
routeName = route.settings.name;
|
||||
}
|
||||
super.didPush(route, previousRoute);
|
||||
}
|
||||
}
|
||||
|
||||
class TransitionDetector extends DefaultTransitionDelegate<void> {
|
||||
bool hasTransition = false;
|
||||
@override
|
||||
|
Loading…
x
Reference in New Issue
Block a user