Site icon Flutter Packages | Pub dev Packages – Flutter Mobile App World

Sentry SDK for Flutter

Sentry SDK for Flutter 

This package includes support to native crashes through Sentry’s native SDKs: (Android and iOS). It will capture errors in the native layer, including (Java/Kotlin/C/C++ for Android and Objective-C/Swift for iOS).

Usage

import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
  await SentryFlutter.init(
    (options) {
      options.dsn = 'https://example@sentry.io/add-your-dsn-here';
    },
    // Init your App.
    appRunner: () => runApp(MyApp()),
  );
}

Or, if you want to run your app in your own error zone runZonedGuarded:

import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

Future<void> main() async {
  runZonedGuarded(() async {
    await SentryFlutter.init(
      (options) {
        options.dsn = 'https://example@sentry.io/add-your-dsn-here';
      },
    );

    runApp(MyApp());
  }, (exception, stackTrace) async {
    await Sentry.captureException(exception, stackTrace: stackTrace);
  });
}
Tracking navigation events

In order to track navigation events you have to add the SentryNavigatorObserver to your MaterialAppWidgetsApp or CupertinoApp.

import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

// ...
MaterialApp(
  navigatorObservers: [
    SentryNavigatorObserver(),
  ],
  // other parameters
)
// ...

For a more throughout example see the example.

Known limitations
Uploading Debug Symbols (Android and iOS)
Tips for catching errors

Download Sentry SDK package source code on GitHub

https://github.com/getsentry/sentry-dart

Exit mobile version