Firebase Crashlytics — Flutter

firebase-crashlytics — flutter

Firebase Crashlytics — Flutter 💙💛

Who will use an app with crashes? How will you be able to know the crashes faced by your users? It’s always good to integrate a crash reporting tool!

Even if we try to make our app crash-free, no one knows when your app will crash 🤯

There’s nothing like perfect, crash-free code!

So, to keep ourselves safe from banging our heads over tracking bugs and crashes, integrating any crash reporting tools with your application is always a good idea.

Firebase Crashlytics is one such tool provided by Firebase. Its integration is straightforward, and the crashes reported are the same as we see while debugging the app, making it easier for us to track and solve them!

Step 1: Enable Crashlytics

Go to Firebase Console and in the left panel, under Release & Monitor , go to Crashlytics and click on Add SDK button.

Step 2: Add Crashlytics SDK to your project

Add firebase_crashlytics to your pubspec.yaml file and run flutter pub get. The next step is to run flutterfire configure so that your Flutter app’s Firebase configuration is up-to-date and, for Android, it adds the required Crashlytics Gradle plugin to your app.

Step 3: Add crash logging code

So, we don’t know when and where the crash will occur. We need to find a way which will allow us to catch all the unhandled exceptions! Flutter SDK has blessed us with a great method for it 🥳

You can automatically catch all errors that are thrown within the Flutter framework by overriding FlutterError.onError with FirebaseCrashlytics.instance.recordFlutterFatalError:

void main() async {
runZonedGuarded>(() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

FlutterError.onError =
FirebaseCrashlytics.instance.recordFlutterFatalError;

runApp(MyApp());
}, (error, stack) =>
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true));
}

Now, that’s all we need to log any crashes or exceptions that might break your head for solving 😉

https://medium.com/media/a1daadfd5e12b5d239a5ca97850fa797/href

Hope you enjoyed this article!

Doubts? Feel free to drop a message @AbhishekDoshi26

Don’t stop, until you are breathing!💙
– Abhishek Doshi


Firebase Crashlytics — Flutter 💙💛 was originally published in Google Developer Experts on Medium, where people are continuing the conversation by highlighting and responding to this story.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
15-productivity-hacks-for-a-successful-2023

15 Productivity Hacks for a Successful 2023

Next Post
ai,-generally-speaking …

AI, generally speaking …

Related Posts