Unverified Commit 0d2421d5 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Add defaults to `showGeneralDialog()` (#61503)

The function passes most of its arguments through to
`_DialogRoute`, but it wasn't providing the default
values that `_DialogRoute` was, causing it to override
the defaults will null values.
parent d009172f
...@@ -1799,10 +1799,10 @@ class _DialogRoute<T> extends PopupRoute<T> { ...@@ -1799,10 +1799,10 @@ class _DialogRoute<T> extends PopupRoute<T> {
Future<T> showGeneralDialog<T>({ Future<T> showGeneralDialog<T>({
@required BuildContext context, @required BuildContext context,
@required RoutePageBuilder pageBuilder, @required RoutePageBuilder pageBuilder,
bool barrierDismissible, bool barrierDismissible = false,
String barrierLabel, String barrierLabel,
Color barrierColor, Color barrierColor = const Color(0x80000000),
Duration transitionDuration, Duration transitionDuration = const Duration(milliseconds: 200),
RouteTransitionsBuilder transitionBuilder, RouteTransitionsBuilder transitionBuilder,
bool useRootNavigator = true, bool useRootNavigator = true,
RouteSettings routeSettings, RouteSettings routeSettings,
......
...@@ -1041,6 +1041,41 @@ void main() { ...@@ -1041,6 +1041,41 @@ void main() {
expect(nestedObserver.dialogCount, 1); expect(nestedObserver.dialogCount, 1);
}); });
testWidgets('showGeneralDialog default argument values', (WidgetTester tester) async {
final DialogObserver rootObserver = DialogObserver();
await tester.pumpWidget(MaterialApp(
navigatorObservers: <NavigatorObserver>[rootObserver],
home: Navigator(
onGenerateRoute: (RouteSettings settings) {
return MaterialPageRoute<dynamic>(
builder: (BuildContext context) {
return RaisedButton(
onPressed: () {
showGeneralDialog<void>(
context: context,
pageBuilder: (BuildContext innerContext, _, __) {
return const SizedBox();
},
);
},
child: const Text('Show Dialog'),
);
},
);
},
),
));
// Open the dialog.
await tester.tap(find.byType(RaisedButton));
expect(rootObserver.dialogRoutes.length, equals(1));
final ModalRoute<dynamic> route = rootObserver.dialogRoutes.last;
expect(route.barrierDismissible, isNotNull);
expect(route.barrierColor, isNotNull);
expect(route.transitionDuration, isNotNull);
});
testWidgets('reverseTransitionDuration defaults to transitionDuration', (WidgetTester tester) async { testWidgets('reverseTransitionDuration defaults to transitionDuration', (WidgetTester tester) async {
final GlobalKey containerKey = GlobalKey(); final GlobalKey containerKey = GlobalKey();
...@@ -1598,15 +1633,26 @@ class TestPageRouteBuilder extends PageRouteBuilder<void> { ...@@ -1598,15 +1633,26 @@ class TestPageRouteBuilder extends PageRouteBuilder<void> {
} }
class DialogObserver extends NavigatorObserver { class DialogObserver extends NavigatorObserver {
final List<ModalRoute<dynamic>> dialogRoutes = <ModalRoute<dynamic>>[];
int dialogCount = 0; int dialogCount = 0;
@override @override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) { void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
if (route.toString().contains('_DialogRoute')) { if (route.toString().contains('_DialogRoute')) {
dialogRoutes.add(route as ModalRoute<dynamic>);
dialogCount++; dialogCount++;
} }
super.didPush(route, previousRoute); super.didPush(route, previousRoute);
} }
@override
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
if (route.toString().contains('_DialogRoute')) {
dialogRoutes.removeLast();
dialogCount--;
}
super.didPop(route, previousRoute);
}
} }
class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> { class _TestDialogRouteWithCustomBarrierCurve<T> extends PopupRoute<T> {
......
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