handleUncaughtErrors<R> static method

void handleUncaughtErrors<R>(
  1. R body()
)

Helper method to allow Bugfender to detect uncaught exceptions and report them.

This method should be used inside main() method and must wrap the call to runApp():

void main() {
  FlutterBugfender.handleUncaughtErrors(() async {
    runApp(new MyApp());
  });
}

Implementation

static void handleUncaughtErrors<R>(R body()) async {
  FlutterError.onError = (FlutterErrorDetails details) async {
    FlutterError.presentError(details);

    await FlutterBugfender.sendCrash(
        details.exception.toString(), details.stack?.toString() ?? "");
  };
  runZonedGuarded(() {
    body();
  }, (Object error, StackTrace stack) async {
    await FlutterBugfender.sendCrash(error.toString(), stack.toString());
  });
}