Advanced use cases

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

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()));
}