Firebase Crashlytics in 3 Steps - Flutter Tutorial
how to use crashlytics
in firebase in 3 Steps
Step 1: Create your Firebase Project in the Firebase console and enable crashlytics
Firebase console: https://console.firebase.google.com
Step 2: Install these 2 packages in our pubspec.yaml
https://pub.dev/packages/firebase_crashlytics
https://pub.dev/packages/firebase_core
Then let's go to main.dart and initialize FireBase
and add these 2 lines
.
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
.
Step 3: initialize Firebase Crashlytics
so let's add this line to main()
.
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
.
That is for overriding FlutterError.onError
with FirebaseCrashlytics.instance.recordFlutterError
which will automatically catch all errors that are thrown within the Flutter framework. and sent it to the Firebase dashboard
All Done!!
We don't have to wait for a crash
Let's Force a test crash to check if working or not!!
so let's add this line to a button or in the initState
.
FirebaseCrashlytics.instance.crash();
.
Stop and re-Run your app again, And wait 10 mins till the first data reach the Crashlytics dashboard of the Firebase console.
and as you see in the dash we are receiving crash errors
More details Read this:
go step by step with
https://firebase.google.com/docs/crashlytics/get-started?platform=flutter#add-sdk (use this last update)
-
That is it for this article, If you have any issues or questions
please message me on Instagram or WhatsApp and I will reply
-