diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index 2fc161a639..e2c98c1736 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -349,14 +349,30 @@ class RenderObjectToWidgetElement extends RootRenderObje void mount(Element parent, dynamic newSlot) { assert(parent == null); super.mount(parent, newSlot); - _child = updateChild(_child, widget.child, _rootChildSlot); + _rebuild(); } @override void update(RenderObjectToWidgetAdapter newWidget) { super.update(newWidget); assert(widget == newWidget); - _child = updateChild(_child, widget.child, _rootChildSlot); + _rebuild(); + } + + void _rebuild() { + try { + _child = updateChild(_child, widget.child, _rootChildSlot); + assert(_child != null); + } catch (exception, stack) { + FlutterError.reportError(new FlutterErrorDetails( + exception: exception, + stack: stack, + library: 'widgets library', + context: 'attaching to the render tree' + )); + Widget error = new ErrorWidget(exception); + _child = updateChild(null, error, _rootChildSlot); + } } @override diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index 01de9f0af8..8fc2b429f9 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -525,14 +525,17 @@ abstract class ModalRoute extends TransitionRoute with LocalHistoryRoute()); expect('$exception', startsWith('openTransaction called with a context')); }); + + testWidgets('Missing settings in onGenerateRoute throws exception', (WidgetTester tester) async { + await tester.pumpWidget(new Navigator( + onGenerateRoute: (RouteSettings settings) { + return new MaterialPageRoute( + builder: (BuildContext context) => new Container() + ); + } + )); + Object exception = tester.takeException(); + expect(exception is FlutterError, isTrue); + }); }