Is there a way to display (in production) a custom error widget instead of the red screen of death? I will not change the framework code, plus even though we are trying to progr
Use ErrorWidget.builder
instead main()
function, like this
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
ErrorWidget.builder = (FlutterErrorDetails details) => SomethingWrong();
runApp(YourApp());
}
And if you want to show Certain Widget only on Production app, then you can use kReleaseMode
-
if (kReleaseMode) {
ErrorWidget.builder = (FlutterErrorDetails details) => SomethingWrong();
}
Note: The top-level kReleaseMode constant is use to determine whether the app was compiled in release mode.
It is possible to change the default error rendering by changing ErrorWidget.builder
ErrorWidget.builder = (errorDetails) {
return Container(color: Colors.red);
}