diff --git a/packages/flutter/lib/src/material/bottom_sheet.dart b/packages/flutter/lib/src/material/bottom_sheet.dart index 5252f51190..1a2da99ba9 100644 --- a/packages/flutter/lib/src/material/bottom_sheet.dart +++ b/packages/flutter/lib/src/material/bottom_sheet.dart @@ -583,6 +583,10 @@ class _BottomSheetSuspendedCurve extends ParametricCurve { /// parameters can be passed in to customize the appearance and behavior of /// modal bottom sheets. /// +/// The optional `routeSettings` parameter sets the [RouteSettings] of the modal bottom sheet +/// sheet. This is particularly useful in the case that a user wants to observe +/// [PopupRoute]s within a [NavigatorObserver]. +/// /// Returns a `Future` that resolves to the value (if any) that was passed to /// [Navigator.pop] when the modal bottom sheet was closed. /// @@ -648,6 +652,7 @@ Future showModalBottomSheet({ bool useRootNavigator = false, bool isDismissible = true, bool enableDrag = true, + RouteSettings routeSettings, }) { assert(context != null); assert(builder != null); @@ -670,6 +675,7 @@ Future showModalBottomSheet({ isDismissible: isDismissible, modalBarrierColor: barrierColor, enableDrag: enableDrag, + settings: routeSettings, )); } diff --git a/packages/flutter/test/material/bottom_sheet_test.dart b/packages/flutter/test/material/bottom_sheet_test.dart index ca29faf79c..6df0203301 100644 --- a/packages/flutter/test/material/bottom_sheet_test.dart +++ b/packages/flutter/test/material/bottom_sheet_test.dart @@ -696,6 +696,38 @@ void main() { // the BottomNavigationBar. expect(tester.getBottomLeft(find.byType(BottomSheet)).dy, 600.0); }); + + testWidgets('Verify that route settings can be set in the showModalBottomSheet', + (WidgetTester tester) async { + final GlobalKey scaffoldKey = GlobalKey(); + const RouteSettings routeSettings = + RouteSettings(name: 'route_name', arguments: 'route_argument'); + + await tester.pumpWidget(MaterialApp( + home: Scaffold( + key: scaffoldKey, + body: const Center(child: Text('body')), + ), + )); + + RouteSettings retrievedRouteSettings; + + showModalBottomSheet( + context: scaffoldKey.currentContext, + routeSettings: routeSettings, + builder: (BuildContext context) { + retrievedRouteSettings = ModalRoute.of(context).settings; + return Container( + child: const Text('BottomSheet'), + ); + }, + ); + + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + expect(retrievedRouteSettings, routeSettings); + }); } class _TestPage extends StatelessWidget {