Skip to content

Instantly share code, notes, and snippets.

@rcdevgames
Forked from putraxor/custom_error_widget.dart
Created February 16, 2019 15:30
Show Gist options
  • Save rcdevgames/e98793c9fa7f9f4cce7a32119066c698 to your computer and use it in GitHub Desktop.
Save rcdevgames/e98793c9fa7f9f4cce7a32119066c698 to your computer and use it in GitHub Desktop.
Show user-friendly error page instead of exception in Flutter
Widget getErrorWidget(BuildContext context, FlutterErrorDetails error) {
return Center(
child: Text(
"Error appeared.",
style: Theme.of(context).textTheme.title.copyWith(color: Colors.white),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
return getErrorWidget(context, errorDetails);
};
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment