Sentry for Flutter: setup that catches everything
Add the sentry_flutter package (or run npx @sentry/wizard@latest -i flutter), call SentryFlutter.init in main() with your DSN, and start the app through its appRunner. That alone captures Flutter framework errors, uncaught async errors and native iOS and Android crashes. If you build with --obfuscate and --split-debug-info, run sentry_dart_plugin after every release build to upload the debug symbols and obfuscation map, or your stack traces and issue titles will be unreadable.
Steps
- Add sentry_flutterRun the wizard or add sentry_flutter to pubspec.yaml and wrap runApp in SentryFlutter.init's appRunner.
- Report caught errorsCall Sentry.captureException(error, stackTrace: stackTrace) where you catch exceptions you still want to know about.
- Upload symbols per releaseAfter each obfuscated release build, run sentry_dart_plugin with SENTRY_AUTH_TOKEN and the obfuscation map path.
- Name your routesAdd SentryNavigatorObserver and give every route a name so screens show up in performance data.
Install sentry_flutter and call SentryFlutter.init
The wizard (npx @sentry/wizard@latest -i flutter) adds the dependency and patches main.dart. By hand, add the package to pubspec.yaml:
dependencies:
sentry_flutter: ^10.7.0As of November 2026 Sentry Flutter SDK v10 needs Flutter 3.44.0 and Dart 3.12.0 or later, Android API 24+, and iOS 15.0 / macOS 12.0+. Then initialise in main():
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = 'https://<key>@o<orgId>.ingest.sentry.io/<projectId>';
options.sendDefaultPii = true;
options.tracesSampleRate = 1.0; // lower in production
options.replay.onErrorSampleRate = 1.0;
options.replay.sessionSampleRate = 0.1;
},
appRunner: () => runApp(SentryWidget(child: MyApp())),
);
}Keep the SentryWidget wrapper: attachScreenshot requires it, and the replay options above turn on Session Replay. You can pass SENTRY_DSN, SENTRY_RELEASE, SENTRY_DIST and SENTRY_ENVIRONMENT with --dart-define instead of hard-coding them. Without an explicit release, the plugin below uses name@version from pubspec.yaml and the build number after + as dist.
How the SDK catches Flutter, platform and zone errors
Flutter has two error paths, and you need both. FlutterError.onError receives errors the framework catches during build, layout, paint and its own callbacks. Errors with no Flutter callback on the stack, such as an exception in an async button handler after an await, go to PlatformDispatcher.instance.onError, which by default only prints them.
| Error | Handler | Captured by sentry_flutter |
|---|---|---|
Exception in build, layout or paint | FlutterError.onError | Yes, automatically |
| Uncaught async error (Flutter 3.3+) | PlatformDispatcher.onError | Yes: the SDK runs your appRunner under it |
| Uncaught async error (before Flutter 3.3) | runZonedGuarded | Yes: the SDK used a guarded zone |
Error thrown before SentryFlutter.init | none | No |
Exception you catch yourself | your code | Only if you report it |
So you don't write your own runZonedGuarded any more. If you need a custom zone, use Sentry.runZonedGuarded, which wraps Dart's version and still reports to Sentry. For errors you handle, report them with the stack trace:
try {
await api.checkout(cart);
} catch (error, stackTrace) {
await Sentry.captureException(error, stackTrace: stackTrace);
showRetry();
}Passing stackTrace matters: without it the event's trace points at the captureException call, not where the error was thrown. print() calls are recorded as breadcrumbs (enablePrintBreadcrumbs).
Obfuscation and debug symbols with sentry_dart_plugin
A release built with --obfuscate --split-debug-info sends Sentry renamed symbols and frames without file names. Sentry needs the files that build produced. The Sentry Dart Plugin uploads them for iOS, Android and web:
dev_dependencies:
sentry_dart_plugin: ^3.6.0
sentry:
project: web
org: acme
upload_debug_symbols: true # default
upload_sources: true # source context, default false
dart_symbol_map_path: build/app/obfuscation.map.jsonflutter build ipa --obfuscate --split-debug-info=build/symbols \
--extra-gen-snapshot-options=--save-obfuscation-map=build/app/obfuscation.map.json
SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN dart run sentry_dart_plugindart_symbol_map_path is what makes obfuscated issue titles (the exception type) readable; the debug symbols fix the frames. Environment variables override --sentry-define, which overrides pubspec.yaml, which overrides sentry.properties. On Android you only need Sentry's Gradle plugin as well if R8 or ProGuard is on.
Web is different: Flutter web can't be obfuscated, only minified. Build with flutter build web --release --source-maps and set upload_source_maps: true. With plugin 3.0.0 or later, web source maps need sentry_flutter 9.1.0+ (older SDKs: legacy_web_symbolication: true); apps not served from the site root also need url_prefix.
The mistake people make next: uploading symbols from a different build than the one shipped. Run the plugin in the same CI job, right after the build, and keep the symbol files; Flutter's docs warn you need them to de-obfuscate later, and a rebuild produces different ones.
Native crashes and ANRs
Crashes in Kotlin, Java, Swift, Objective-C or C code (a plugin, the engine) are captured from the native layer; enableNativeCrashHandling defaults to true. On Android, ANR detection is on by default (anrEnabled, anrTimeoutInterval 5000 ms); see ANRs on Android. Uploading all debug files with the plugin also lets Sentry symbolicate native frames on iOS that are otherwise unreadable. Use beforeSend to drop or scrub events, and attachViewHierarchy or attachScreenshot (both off by default) when you need to see the screen state.
Performance: navigation, TTID and TTFD
Set tracesSampleRate (or tracesSampler) to enable tracing, and add the navigator observer:
MaterialApp(
navigatorObservers: [SentryNavigatorObserver()],
// GoRouter: observers: [SentryNavigatorObserver()]
);Each named route becomes a transaction with a Time to Initial Display span, on by default. Routes need names: with Navigator, set RouteSettings(name: '/cart'); GoRouter uses the path. Without a name the SDK creates no transaction, breadcrumb or display span, which is the usual reason screens are missing from performance data. For Time to Full Display, set options.enableTimeToFullDisplayTracing = true and call SentryFlutter.currentDisplay()?.reportFullyDisplayed() when data has loaded; an unfinished TTFD span ends after 30 seconds with DEADLINE_EXCEEDED.
Questions
Do I still need runZonedGuarded with sentry_flutter?
No. On Flutter 3.3 and later the SDK uses PlatformDispatcher.onError to catch uncaught errors. Use Sentry.runZonedGuarded only if you need a custom zone.
Why are my Flutter issue titles obfuscated in Sentry?
The exception type was renamed by --obfuscate. Save the obfuscation map at build time and point dart_symbol_map_path at it so sentry_dart_plugin uploads it.
Does sentry_flutter catch native crashes?
Yes. Hard crashes in the native Android and iOS layer are captured, and enableNativeCrashHandling is true by default.
Sources
- Manual Setupdocs.sentry.io
- Sentry Dart Plugindocs.sentry.io
- Routing Instrumentationdocs.sentry.io
- Handling errors in Flutterdocs.flutter.dev