From da58f5e6fe034f8edfa1adc08debcb92d42e2a68 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 13 Oct 2020 00:53:54 +0200 Subject: [PATCH] Pass RouteSettings to the internal Route in showCupertinoModalPopup (#56024) --- packages/flutter/lib/src/cupertino/route.dart | 5 +++ .../flutter/test/cupertino/route_test.dart | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 73669d02ab..ace6af939c 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart @@ -1031,6 +1031,9 @@ class _CupertinoModalPopupRoute extends PopupRoute { /// 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 showCupertinoModalPopup({ 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 showCupertinoModalPopup({ builder: builder, filter: filter, semanticsDismissible: semanticsDismissible, + settings: routeSettings, ), ); } diff --git a/packages/flutter/test/cupertino/route_test.dart b/packages/flutter/test/cupertino/route_test.dart index 69df6707c6..1c22012500 100644 --- a/packages/flutter/test/cupertino/route_test.dart +++ b/packages/flutter/test/cupertino/route_test.dart @@ -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: [routeSettingsObserver], + home: Navigator( + onGenerateRoute: (RouteSettings settings) { + return PageRouteBuilder( + pageBuilder: (BuildContext context, Animation _, + Animation __) { + return GestureDetector( + onTap: () async { + await showCupertinoModalPopup( + 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 route, Route previousRoute) { + if (route.toString().contains('_CupertinoModalPopupRoute')) { + routeName = route.settings.name; + } + super.didPush(route, previousRoute); + } +} + class TransitionDetector extends DefaultTransitionDelegate { bool hasTransition = false; @override