forked from firka/flutter
expose route settings for showModalBottomSheet (#60640)
This commit is contained in:
@@ -583,6 +583,10 @@ class _BottomSheetSuspendedCurve extends ParametricCurve<double> {
|
||||
/// 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<T> showModalBottomSheet<T>({
|
||||
bool useRootNavigator = false,
|
||||
bool isDismissible = true,
|
||||
bool enableDrag = true,
|
||||
RouteSettings routeSettings,
|
||||
}) {
|
||||
assert(context != null);
|
||||
assert(builder != null);
|
||||
@@ -670,6 +675,7 @@ Future<T> showModalBottomSheet<T>({
|
||||
isDismissible: isDismissible,
|
||||
modalBarrierColor: barrierColor,
|
||||
enableDrag: enableDrag,
|
||||
settings: routeSettings,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
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<void>(
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user