Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Flutter's "red screen of death"

Is there a way to disable Flutter's "red screen of death"? I don't mind it during debug, but it seems to also appear in production builds - and I can't find any information about how to disable it, or catch the error myself.

I tried catching stray errors with FlutterError.onError and runZoned(onError), but both did not stop the red screen from appearing.

For reference, I'm talking about this screen:

rsod

like image 1000
Katai Avatar asked Dec 23 '18 13:12

Katai


3 Answers

You could override ErrorWidget.builder method.
I'm resolved this.

・Example code.

void main() {
    ErrorWidget.builder = (FlutterErrorDetails details) => Container();
    ...
}

・Default code

static ErrorWidgetBuilder builder = _defaultErrorWidgetBuilder;

I hoped its your help.


2019 12 21 updated

Or Change ErrorWidget backgroundColor and textStyle.

・Example code

import 'dart:ui' as ui;
void main() {
    RenderErrorBox.backgroundColor = Colors.transparent;
    RenderErrorBox.textStyle = ui.TextStyle(color: Colors.transparent);
}
like image 90
pepen Avatar answered Nov 18 '22 21:11

pepen


You can try to use Catcher which is a free flutter plugin which catches and handles errors in Flutter application. Catcher offers multiple report modes and handlers to cooperate with Flutter applications

just add catcher in your pubspec.yaml

catcher: ^0.1.2

For more info about catcher https://pub.dartlang.org/packages/catcher

A nice tutorial to get started with catcher https://medium.com/flutter-community/handling-flutter-errors-with-catcher-efce74397862

like image 31
André Abboud Avatar answered Nov 18 '22 20:11

André Abboud


void main() {
 bool isDev = true;
          ErrorWidget.builder = (FlutterErrorDetails errorDetails) {
            return AppErrorWidget(
              errorDetails: errorDetails,
              isDev: isDev,
            );
          };
}          

    class AppErrorWidget extends StatelessWidget {
      final FlutterErrorDetails errorDetails;
      final bool isDev;
      const AppErrorWidget({
        Key key,
        @required this.errorDetails,
        this.isDev = false,
      }) : super(key: key);
      @override
      Widget build(BuildContext context) {
        return Material(
          child: SafeArea(
            child: Container(
              decoration: BoxDecoration(border: Border.all(color: Colors.red)),
              child: ListView(
                children: <Widget>[
                  Container(
                    height: 20,
                  ),
                  Text(isDev ? errorDetails.toString() : '')
                ],
              ),
            ),
          ),
        );
      }
    }
like image 1
Kalyan Biswas Avatar answered Nov 18 '22 21:11

Kalyan Biswas