Created
January 25, 2019 09:08
-
-
Save putraxor/409364780f232dce049283b4bf6bcfe0 to your computer and use it in GitHub Desktop.
Show user-friendly error page instead of exception in Flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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