-
-
Save rcdevgames/e98793c9fa7f9f4cce7a32119066c698 to your computer and use it in GitHub Desktop.
Show user-friendly error page instead of exception in Flutter
This file contains 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