Unverified Commit 6c04a2a1 authored by Albertus Angga Raharja's avatar Albertus Angga Raharja Committed by GitHub

Properly throw error when CupertinoPageRoute builder returns null (#42602)

parent a35c874f
......@@ -253,17 +253,18 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
@override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
final Widget child = builder(context);
final Widget result = Semantics(
scopesRoute: true,
explicitChildNodes: true,
child: builder(context),
child: child,
);
assert(() {
if (result == null) {
throw FlutterError(
'The builder for route "${settings.name}" returned null.\n'
'Route builders must never return null.'
);
if (child == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('The builder for route "${settings.name}" returned null.'),
ErrorDescription('Route builders must never return null.'),
]);
}
return true;
}());
......
......@@ -15,6 +15,34 @@ void main() {
navigatorObserver = MockNavigatorObserver();
});
testWidgets(
'Throws FlutterError with correct message when route builder returns null',
(WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
home: Placeholder(),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
title: 'Route 1',
builder: (_) => null,
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
final dynamic error = tester.takeException();
expect(error, isFlutterError);
expect(error.toStringDeep(), equalsIgnoringHashCodes(
'FlutterError\n'
' The builder for route "null" returned null.\n'
' Route builders must never return null.\n'
));
});
testWidgets('Middle auto-populates with title', (WidgetTester tester) async {
await tester.pumpWidget(
const CupertinoApp(
......
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