Disable Flutter's "red screen of death"

7,584

Solution 1

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);
}

Solution 2

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

Solution 3

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() : '')
                ],
              ),
            ),
          ),
        );
      }
    }
Share:
7,584
Katai
Author by

Katai

Updated on December 08, 2022

Comments

  • Katai
    Katai over 1 year

    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