获取更多动态,关注公众号:黑客下午茶

Flutter

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

pubspec.yaml
Copied
dependencies:
  sentry_flutter: ^4.0.1

Import 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.