Flutter: Crashlytics Plugin throwing Bad State error on crash

Viewed 1557

I have followed the steps on https://pub.dev/packages/firebase_crashlytics to install the plugin. However, when I force a crash using Crashlytics.instance.crash(); I get the following error:

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following StateError was thrown while handling a gesture:
Bad state: Error thrown by Crashlytics plugin

When the exception was thrown, this was the stack: 
#0      Crashlytics.crash (package:firebase_crashlytics/src/firebase_crashlytics.dart:54:5)
#1      _ProfileScreenState.build.<anonymous closure> (package:genchi_app/screens/profile_screen.dart:93:44)
#2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
#3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)

Why is it not catching the error and showing the following?

flutter: Flutter error caught by Crashlytics plugin:

EDIT:

Android crashes are being sent to the console, but iOS is not. Neither android or iOS show that the Crashlytics plugin is catching the errors during development.

2 Answers

Well, I got to know about your problem.

What you are getting is exactly what you are doing in your code. I have checked the firebase_crashLytics.dart line 54(see code below)

void crash() {
    throw StateError('Error thrown by Crashlytics plugin');
  }

So the crash function you are calling throws the error because it is meant to throw error.

It seems that Flutter catches a lot of errors in debug mode, and prints them on the console without rethrowing them. So the method FlutterError.onError is not called in this cases.

I solved this problem by disabling the "Flutter Structured Errors" feature as suggested here.

For VS Code I just added the following line in .vscode/settings.json:

"dart.flutterStructuredErrors": false
Related