Unverified Commit fef2d6cc authored by Darren Austin's avatar Darren Austin Committed by GitHub

Pass RouteSettings into all callers of showGeneralDialog. (#51525)

parent 4fb9ce84
...@@ -976,6 +976,7 @@ Future<T> showCupertinoDialog<T>({ ...@@ -976,6 +976,7 @@ Future<T> showCupertinoDialog<T>({
@required BuildContext context, @required BuildContext context,
@required WidgetBuilder builder, @required WidgetBuilder builder,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings,
}) { }) {
assert(builder != null); assert(builder != null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
...@@ -990,5 +991,6 @@ Future<T> showCupertinoDialog<T>({ ...@@ -990,5 +991,6 @@ Future<T> showCupertinoDialog<T>({
}, },
transitionBuilder: _buildCupertinoDialogTransitions, transitionBuilder: _buildCupertinoDialogTransitions,
useRootNavigator: useRootNavigator, useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
); );
} }
...@@ -223,8 +223,8 @@ class AboutListTile extends StatelessWidget { ...@@ -223,8 +223,8 @@ class AboutListTile extends StatelessWidget {
/// The licenses shown on the [LicensePage] are those returned by the /// The licenses shown on the [LicensePage] are those returned by the
/// [LicenseRegistry] API, which can be used to add more licenses to the list. /// [LicenseRegistry] API, which can be used to add more licenses to the list.
/// ///
/// The [context] and [useRootNavigator] arguments are passed to [showDialog], /// The [context], [useRootNavigator] and [routeSettings] arguments are passed to
/// the documentation for which discusses how it is used. /// [showDialog], the documentation for which discusses how it is used.
void showAboutDialog({ void showAboutDialog({
@required BuildContext context, @required BuildContext context,
String applicationName, String applicationName,
...@@ -233,6 +233,7 @@ void showAboutDialog({ ...@@ -233,6 +233,7 @@ void showAboutDialog({
String applicationLegalese, String applicationLegalese,
List<Widget> children, List<Widget> children,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings,
}) { }) {
assert(context != null); assert(context != null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
...@@ -248,6 +249,7 @@ void showAboutDialog({ ...@@ -248,6 +249,7 @@ void showAboutDialog({
children: children, children: children,
); );
}, },
routeSettings: routeSettings,
); );
} }
......
...@@ -1086,8 +1086,8 @@ typedef SelectableDayPredicate = bool Function(DateTime day); ...@@ -1086,8 +1086,8 @@ typedef SelectableDayPredicate = bool Function(DateTime day);
/// provided by [Directionality]. If both [locale] and [textDirection] are not /// provided by [Directionality]. If both [locale] and [textDirection] are not
/// null, [textDirection] overrides the direction chosen for the [locale]. /// null, [textDirection] overrides the direction chosen for the [locale].
/// ///
/// The [context] and [useRootNavigator] arguments are passed to [showDialog], /// The [context], [useRootNavigator] and [routeSettings] arguments are passed to
/// the documentation for which discusses how it is used. /// [showDialog], the documentation for which discusses how it is used.
/// ///
/// The [builder] parameter can be used to wrap the dialog widget /// The [builder] parameter can be used to wrap the dialog widget
/// to add inherited widgets like [Theme]. /// to add inherited widgets like [Theme].
...@@ -1137,6 +1137,7 @@ Future<DateTime> showDatePicker({ ...@@ -1137,6 +1137,7 @@ Future<DateTime> showDatePicker({
TextDirection textDirection, TextDirection textDirection,
TransitionBuilder builder, TransitionBuilder builder,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings,
}) async { }) async {
assert(initialDate != null); assert(initialDate != null);
assert(firstDate != null); assert(firstDate != null);
...@@ -1182,5 +1183,6 @@ Future<DateTime> showDatePicker({ ...@@ -1182,5 +1183,6 @@ Future<DateTime> showDatePicker({
builder: (BuildContext context) { builder: (BuildContext context) {
return builder == null ? child : builder(context, child); return builder == null ? child : builder(context, child);
}, },
routeSettings: routeSettings,
); );
} }
...@@ -872,6 +872,9 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a ...@@ -872,6 +872,9 @@ Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> a
/// By default, `useRootNavigator` is `true` and the dialog route created by /// By default, `useRootNavigator` is `true` and the dialog route created by
/// this method is pushed to the root navigator. /// this method is pushed to the root navigator.
/// ///
/// The `routeSettings` argument is passed to [showGeneralDialog],
/// see [RouteSettings] for details.
///
/// If the application has multiple [Navigator] objects, it may be necessary to /// If the application has multiple [Navigator] objects, it may be necessary to
/// call `Navigator.of(context, rootNavigator: true).pop(result)` to close the /// call `Navigator.of(context, rootNavigator: true).pop(result)` to close the
/// dialog rather than just `Navigator.pop(context, result)`. /// dialog rather than just `Navigator.pop(context, result)`.
...@@ -900,6 +903,7 @@ Future<T> showDialog<T>({ ...@@ -900,6 +903,7 @@ Future<T> showDialog<T>({
Widget child, Widget child,
WidgetBuilder builder, WidgetBuilder builder,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings,
}) { }) {
assert(child == null || builder == null); assert(child == null || builder == null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
...@@ -926,5 +930,6 @@ Future<T> showDialog<T>({ ...@@ -926,5 +930,6 @@ Future<T> showDialog<T>({
transitionDuration: const Duration(milliseconds: 150), transitionDuration: const Duration(milliseconds: 150),
transitionBuilder: _buildMaterialDialogTransitions, transitionBuilder: _buildMaterialDialogTransitions,
useRootNavigator: useRootNavigator, useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
); );
} }
...@@ -1749,8 +1749,8 @@ class _TimePickerDialogState extends State<_TimePickerDialog> { ...@@ -1749,8 +1749,8 @@ class _TimePickerDialogState extends State<_TimePickerDialog> {
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// The [context] and [useRootNavigator] arguments are passed to [showDialog], /// The [context], [useRootNavigator] and [routeSettings] arguments are passed to
/// the documentation for which discusses how it is used. /// [showDialog], the documentation for which discusses how it is used.
/// ///
/// The [builder] parameter can be used to wrap the dialog widget /// The [builder] parameter can be used to wrap the dialog widget
/// to add inherited widgets like [Localizations.override], /// to add inherited widgets like [Localizations.override],
...@@ -1799,6 +1799,7 @@ Future<TimeOfDay> showTimePicker({ ...@@ -1799,6 +1799,7 @@ Future<TimeOfDay> showTimePicker({
@required TimeOfDay initialTime, @required TimeOfDay initialTime,
TransitionBuilder builder, TransitionBuilder builder,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings,
}) async { }) async {
assert(context != null); assert(context != null);
assert(initialTime != null); assert(initialTime != null);
...@@ -1812,6 +1813,7 @@ Future<TimeOfDay> showTimePicker({ ...@@ -1812,6 +1813,7 @@ Future<TimeOfDay> showTimePicker({
builder: (BuildContext context) { builder: (BuildContext context) {
return builder == null ? dialog : builder(context, dialog); return builder == null ? dialog : builder(context, dialog);
}, },
routeSettings: routeSettings,
); );
} }
......
...@@ -1727,6 +1727,9 @@ class _DialogRoute<T> extends PopupRoute<T> { ...@@ -1727,6 +1727,9 @@ class _DialogRoute<T> extends PopupRoute<T> {
/// and leaves off the screen. By default, the transition is a linear fade of /// and leaves off the screen. By default, the transition is a linear fade of
/// the page's contents. /// the page's contents.
/// ///
/// The `routeSettings` will be used in the construction of the dialog's route.
/// See [RouteSettings] for more details.
///
/// Returns a [Future] that resolves to the value (if any) that was passed to /// Returns a [Future] that resolves to the value (if any) that was passed to
/// [Navigator.pop] when the dialog was closed. /// [Navigator.pop] when the dialog was closed.
/// ///
...@@ -1743,6 +1746,7 @@ Future<T> showGeneralDialog<T>({ ...@@ -1743,6 +1746,7 @@ Future<T> showGeneralDialog<T>({
Duration transitionDuration, Duration transitionDuration,
RouteTransitionsBuilder transitionBuilder, RouteTransitionsBuilder transitionBuilder,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings,
}) { }) {
assert(pageBuilder != null); assert(pageBuilder != null);
assert(useRootNavigator != null); assert(useRootNavigator != null);
...@@ -1754,6 +1758,7 @@ Future<T> showGeneralDialog<T>({ ...@@ -1754,6 +1758,7 @@ Future<T> showGeneralDialog<T>({
barrierColor: barrierColor, barrierColor: barrierColor,
transitionDuration: transitionDuration, transitionDuration: transitionDuration,
transitionBuilder: transitionBuilder, transitionBuilder: transitionBuilder,
settings: routeSettings,
)); ));
} }
......
...@@ -1170,6 +1170,60 @@ void main() { ...@@ -1170,6 +1170,60 @@ void main() {
expect(content.localToGlobal(Offset.zero), equals(contentOriginalOffset)); expect(content.localToGlobal(Offset.zero), equals(contentOriginalOffset));
}); });
}); });
testWidgets('Dialog with RouteSettings', (WidgetTester tester) async {
RouteSettings currentRouteSetting;
await tester.pumpWidget(
MaterialApp(
navigatorObservers: <NavigatorObserver>[
_ClosureNavigatorObserver(onDidChange: (Route<dynamic> newRoute) {
currentRouteSetting = newRoute?.settings;
})
],
home: const Material(
child: Center(
child: RaisedButton(
onPressed: null,
child: Text('Go'),
),
),
),
),
);
final BuildContext context = tester.element(find.text('Go'));
const RouteSettings exampleSetting = RouteSettings(name: 'simple');
final Future<int> result = showDialog<int>(
context: context,
builder: (BuildContext context) {
return SimpleDialog(
title: const Text('Title'),
children: <Widget>[
SimpleDialogOption(
child: const Text('X'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
routeSettings: exampleSetting,
);
await tester.pumpAndSettle();
expect(find.text('Title'), findsOneWidget);
expect(currentRouteSetting, exampleSetting);
await tester.tap(find.text('X'));
await tester.pumpAndSettle();
expect(await result, isNull);
await tester.pumpAndSettle();
expect(currentRouteSetting?.name, '/');
});
} }
class DialogObserver extends NavigatorObserver { class DialogObserver extends NavigatorObserver {
...@@ -1183,3 +1237,21 @@ class DialogObserver extends NavigatorObserver { ...@@ -1183,3 +1237,21 @@ class DialogObserver extends NavigatorObserver {
super.didPush(route, previousRoute); super.didPush(route, previousRoute);
} }
} }
class _ClosureNavigatorObserver extends NavigatorObserver {
_ClosureNavigatorObserver({@required this.onDidChange});
final void Function(Route<dynamic> newRoute) onDidChange;
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) => onDidChange(route);
@override
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) => onDidChange(previousRoute);
@override
void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) => onDidChange(previousRoute);
@override
void didReplace({Route<dynamic> newRoute, Route<dynamic> oldRoute}) => onDidChange(newRoute);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment