Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable/disable Firebase Crashlytics in Flutter

I'm trying to implement an opt-in mechanism in my Flutter app wherein the user can choose to enable/disable sending Crashlytics data from their device to my Firebase console.

Reading from this article https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#enable-reporting, I found out that you can disable it initially via the AndroidManifest file and can be disabled on runtime through the code below:

FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)

However, I am having a hard time finding the comparable dart code to access the similar functionality.

Note: I am using the firebase_crashlytics plugin for Flutter by the way.

like image 468
AverageCoder Avatar asked Dec 06 '25 05:12

AverageCoder


1 Answers

Firstly, you need something like a global variable, for example enableCrashlytics to indicate whether this crash should be sent to Firebase or not. And then using that variable inside FlutterError.onError like this:

FlutterError.onError = (details){
    if(enableCrashlytics) {
      enableCrashlytic = false;
      Crashlytics.instance.recordFlutterError(details);
    } else{
      //Do nothing
    }
  };
like image 177
The Vinh Luong Avatar answered Dec 08 '25 20:12

The Vinh Luong