attach method

Future<void> attach({
  1. List<BugsnagOnErrorCallback> onError = const [],
})

Attach Bugsnag to an already initialised native notifier, optionally adding to its existing configuration. Use start if your application is entirely built in Flutter.

Typical hybrid Flutter applications with Bugsnag will start with

Future<void> main() async {
 await bugsnag.attach(
  // configuration here
  );
  runApp(MyApplication());
}

Use this method to initialize Flutter when developing a Hybrid app, where Bugsnag is being started by the native part of the app. For more information on starting Bugsnag natively, see our platform guides for:

See also:

Implementation

Future<void> attach({
  List<BugsnagOnErrorCallback> onError = const [],
}) async {
  // make sure we can use Channels
  WidgetsFlutterBinding.ensureInitialized();

  final result = await ChannelClient._channel.invokeMethod('attach', {
    'notifier': _notifier,
  });

  final autoDetectErrors =
      result['config']['enabledErrorTypes']['dartErrors'] as bool;

  final client = ChannelClient(autoDetectErrors);
  client._onErrorCallbacks.addAll(onError);
  this.client = client;
}