Flutter

Get the SDK from from pub.dev by adding the following to your pubspec.yaml:

Copied
dependencies:
  sentry: ">=3.0.0 <4.0.0"

Import SentryClient and initialize it:

Copied
import 'package:sentry/sentry.dart';

final sentry = SentryClient(dsn: "https://examplePublicKey@o0.ingest.sentry.io/0");

Run the whole app in a zone to capture all uncaught errors:

Copied
import 'dart:async'; 

// Wrap your 'runApp(MyApp())' as follows:

void main() async {
  runZonedGuarded(
    () => runApp(MyApp()),
    (error, stackTrace) {
      await sentry.captureException(
        exception: error,
        stackTrace: stackTrace,
      );
    },
  );
}

Catch Flutter specific errors by subscribing to FlutterError.onError:

Copied
FlutterError.onError = (details, {bool forceReport = false}) {
  sentry.captureException(
    exception: details.exception,
    stackTrace: details.stack,
  );
};

Capture a test exception:

Copied
// Throw an exception and capture it with the Sentry client:
try {
  throw null;
} catch (error, stackTrace) {
  await sentry.captureException(
    exception: error,
    stackTrace: stackTrace,
  );
}

Resources

Flutter has extensive documentation, which includes a cookbook on how to integrate with Sentry.

Source code

The Sentry Dart/Flutter SDK can be found on GitHub sentry-dart.

You can edit this page on GitHub.