Installation

SDK Installation

Install Bugsee plugin into your dart project by adding it to dependencies in your pubspec.yaml

dependencies:
  bugsee_flutter: ^8.0.0

Initialization

In order to allow Bugsee to properly intercept and report unhandled exceptions, it is best to first initialize Bugsee and then the rest of the app. This approach will guarantee that the app is running in a Zone, binding channel, etc. The following example also assume you are using different apps in Bugsee for Android and iOS deployments, this is very typical.

import 'package:bugsee_flutter/bugsee.dart';

String getApplicationToken() {
  return Platform.isAndroid
      ? '<android-app-token>'
      : (Platform.isIOS ? '<ios-app-token>' : '');
}

Future<void> launchBugsee(
    void Function(bool isBugseeLaunched) appRunner) async {
  await Bugsee.launch(getApplicationToken(), appRunCallback: appRunner);
}

Future<void> main() async {
  // This is required to let Bugsee intercept network requests. You can
  // remove the line below if you don't want/need to intercept them.
  HttpOverrides.global = Bugsee.defaultHttpOverrides;

  await launchBugsee((bool isBugseeLaunched) async {
    runApp(const MyApp());
  });
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // ....
}

See configuration to learn more on Bugsee launch options and customizations.

Important tips to ensure all errors are captured

void throwAndCatch() {
  try {
    throw FormatException('Expected at least 1 section');
  } catch (ex, st) {
    Bugsee.logException(ex, st);
  }
}
 
// Example of adding an error listener to an Isolate
void startIsolate() async {
  // According to the Dart documentation:
  // ------------------------------------
  // Since isolates run concurrently, it's possible for it to
  // exit before the error listener is established. To avoid
  // this, start the isolate paused, add the listener and
  // then resume the isolate.

  Isolate isolate = await Isolate.spawn((message) {
    // Your code here
  }, "", paused: true, errorsAreFatal: false);
  isolate.addBugseeErrorListener();
  if (isolate.pauseCapability != null) {
    isolate.resume(isolate.pauseCapability!);
  }
}

// Example of starting an Isolate with BugseeIsolate.spawn()
void spawnIsolate() async {
  await BugseeIsolate.spawn((message) {
    // Your code here
  }, null);
}