To start using Firebase Crashlytics within your project, import it at the top of your project files:
Sending reports to Crashlytics
To send report data to Crashlytics, the application must be restarted. Crashlytics automatically sends any crash reports to Firebase the next time the application is launched.
Toggle Crashlytics collection
setCrashlyticsCollectionEnabled method to toggle Crashlytics collection status.
For example to ensure it is disabled when your app is in debug mode you can do the following:
You can additionally read the current collection enabled status:
Forcing a crash
You don't have to wait for a crash to know that Crashlytics is working. To force a crash, call the
Your app should exit immediately after calling this method. After opening your app again after the crash Firebase Crashlytics will upload the crash report to the Firebase Console.
The error will be show on the Firebase Crashlytics dashboard as an instance of
FirebaseCrashlyticsTestCrash, with a message of
This is a test crash caused by calling .crash() in Dart.
Add custom keys
To associate key/value pairs with your crash reports, you can use the
This accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or values that exceed 1024 characters are truncated.
Add custom log messages
To add custom Crashlytics log messages to your app, use the
Set user identifiers
To add user IDs to your reports, assign each user with a unique ID. This can be an ID number, token or hashed value:
Handling uncaught errors
FirebaseCrashlytics.instance.recordFlutterError, it will automatically
catch all errors that are thrown within the Flutter framework.
If you want to catch errors that occur in zones, you can pass
FirebaseCrashlytics.instance.recordError to the second
Errors outside of Flutter
To catch errors that happen outside of the Flutter context, install an error listener on the current Isolate:
Enable opt-in reporting
By default, Crashlytics will automatically collect crash reports for all your app's users. To give users more control over the data they send, you can enable opt-in reporting by disabling automatic collection and initializing Crashlytics only for selected users:
- Turn off automatic collection natively:
application block of your
AndroidManifest.xml file, add a
meta-data tags to turn off automatic collection:
Add a new key to your
- Enable collection for select users by calling the Crashlytics data collection override at runtime. To opt out of automatic
crash reporting, pass
falseas the override value. When set to
false, the new value does not apply until the next run of the app.