Skip to content

Instantly share code, notes, and snippets.

@putraxor
Created January 25, 2019 09:08
Show Gist options
  • Save putraxor/409364780f232dce049283b4bf6bcfe0 to your computer and use it in GitHub Desktop.
Save putraxor/409364780f232dce049283b4bf6bcfe0 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