Flutter 3.41 is live! Check out theFlutter 3.41 blog post!
Report errors to a service
How to keep track of errors that users encounter.
While one always tries to create apps that are free of bugs, they're sure to crop up from time to time. Since buggy apps lead to unhappy users and customers, it's important to understand how often your users experience bugs and where those bugs occur. That way, you can prioritize the bugs with the highest impact and work to fix them.
How can you determine how often your users experiences bugs? Whenever an error occurs, create a report containing the error that occurred and the associated stacktrace. You can then send the report to an error tracking service, such asBugsnag,Datadog,Firebase Crashlytics,Rollbar, or Sentry.
The error tracking service aggregates all of the crashes your users experience and groups them together. This allows you to know how often your app fails and where the users run into trouble.
In this recipe, learn how to report errors to theSentry crash reporting service using the following steps:
- Get a DSN from Sentry.
- Import the Flutter Sentry package
- Initialize the Sentry SDK
- Capture errors programmatically
1. Get a DSN from Sentry
#Before reporting errors to Sentry, you need a "DSN" to uniquely identify your app with the Sentry.io service.
To get a DSN, use the following steps:
- Create an account with Sentry.
- Log in to the account.
- Create a new Flutter project.
- Copy the code snippet that includes the DSN.
2. Import the Sentry package
# Import thesentry_flutter package into the app. The sentry package makes it easier to send error reports to the Sentry error tracking service.
To add thesentry_flutter package as a dependency, runflutter pub add:
flutter pub add sentry_flutter3. Initialize the Sentry SDK
#Initialize the SDK to capture different unhandled errors automatically:
import'package:flutter/widgets.dart';import'package:sentry_flutter/sentry_flutter.dart';Future<void>main()async{awaitSentryFlutter.init((options)=>options.dsn='https://example@sentry.io/example',appRunner:()=>runApp(constMyApp()),);}Alternatively, you can pass the DSN to Flutter using thedart-define tag:
--dart-define SENTRY_DSN=https://example@sentry.io/exampleWhat does that give me?
#This is all you need for Sentry to capture unhandled errors in Dart and native layers. This includes Swift, Objective-C, C, and C++ on iOS, and Java, Kotlin, C, and C++ on Android.
4. Capture errors programmatically
#Besides the automatic error reporting that Sentry generates by importing and initializing the SDK, you can use the API to report errors to Sentry:
awaitSentry.captureException(exception,stackTrace:stackTrace);For more information, see theSentry API docs on pub.dev.
Learn more
#Extensive documentation about using the Sentry SDK can be found onSentry's site.
Complete example
#To view a working example, see theSentry flutter example app.
Unless stated otherwise, the documentation on this site reflects Flutter 3.38.6. Page last updated on 2025-10-30.View source orreport an issue.