There is a little static error builder hidden in the documentation.
When an error occurs while building a widget, the broken widget is replaced by the widget returned by this function. By default, an ErrorWidget is returned.
You can define in the the builder method of the MaterialApp widget.
builder
Widget buildError(BuildContext context, FlutterErrorDetails error) { return Scaffold( body: Center( child: Text( "Error appeared.", style: Theme.of(context).textTheme.title, ), ) ); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( primarySwatch: Colors.blue, ), builder: (BuildContext context, Widget widget) { ErrorWidget.builder = (FlutterErrorDetails errorDetails) { return buildError(context, errorDetails); }; return widget; }, title: 'Flutter Demo', home: MyHomePage(title: 'Flutter Demo Home Page'), ); } }
Last updated 4 years ago