Crashlytics helps you to collect analytics and details about crashes and errors that occur in your app. It does this through three aspects:
- Logs: Log events in your app to be sent with the crash report for context if your app crashes.
- Crash reports: Every crash is automatically turned into a crash report and sent when the application next opens.
- Stack traces: Even when an error is caught and your app recovers, the Dart stack trace can still be sent.
Usage in Flutter
import 'package:flutter/foundation.dart' show kDebugMode;
// …
if (kDebugMode) {
// Force disable Crashlytics collection while doing every day development.
// Temporarily toggle this to true if you want to test crash reporting in your app.
await FirebaseCrashlytics.instance
.setCrashlyticsCollectionEnabled(false);
} else {
// Handle Crashlytics enabled status when not in Debug,
// e.g. allow your users to opt-in to crash reporting.
}
if (FirebaseCrashlytics.instance.isCrashlyticsCollectionEnabled) {
// Collection is enabled.
}
FirebaseCrashlytics.instance.crash();