Flutter
Sentry's Flutter SDK enables capturing sessions for Release Health, offline caching as well as reporting messages and errors.
Sentry's Flutter SDK depends on the Dart SDK and includes support to native crashes through Sentry's native SDKs (Android and iOS), It'll capture errors in the native layer, including Java, Kotlin, C and C++ code for Android and ObjC, Swift and C for iOS.
Get the SDK from pub.dev by adding the following to your pubspec.yaml:
pubspec.yamlCopied
dependencies:
sentry_flutter: ^4.0.0Import Sentry and initialize it:
Copied
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0',
appRunner: () => runApp(MyApp()),
);
// or define SENTRY_DSN via Dart environment variable (--dart-define)
}Capture a test exception:
Copied
import 'package:sentry/sentry.dart';
try {
aMethodThatMightFail();
} catch (exception, stackTrace) {
await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
}Resources
The Flutter website has extensive documentation, including a cookbook on integrating with a Sentry version earlier than 4.0.0.
Source code
The Sentry Dart/Flutter SDK can be found on GitHub sentry-dart.
You can edit this page on GitHub.