Advanced use cases

Find out about advanced ways to configure BugSnag in Flutter apps.

This documentation is for version 2 of the BugSnag Flutter library. We recommend upgrading to the latest release using our Upgrade guide. Documentation for the current release can be found here.

Detecting errors in other zones

Often when spawning new zones you want any unhandled errors that occur to be reported to BugSnag. While you can do this manually with:

runZonedGuarded(
  () {
    // possibly crashy code
  },
  bugsnag.errorHandler,
);

BugSnag Flutter includes a small utility method to simplify this for you:

bugsnag.runZoned(() {
  // possibly crashy code
});

Advanced startup

When it’s not possible to pass your application startup to BugSnag, you can await bugsnag.start instead of passing a runApp parameter.

In these cases, you should use bugsnag.runZoned to ensure any unhandled startup errors are still reported.

Future<void> main() async {
  await bugsnag.start(apiKey: 'your-api-key-here');
  // other startup logic
  bugsnag.runZoned(() => runApp(const MyApplication()));
}