ensureInitialized static method

WidgetsBinding ensureInitialized()
override

Returns an instance of SentryWidgetsFlutterBinding. If no binding has yet been initialized, creates and initializes one.

If the binding was already initialized with a different implementation, returns the existing WidgetsBinding instance instead.

Implementation

static WidgetsBinding ensureInitialized() {
  try {
    // Try to get the existing binding instance
    return WidgetsBinding.instance;
  } catch (_) {
    Sentry.currentHub.options.logger(
        SentryLevel.info,
        'WidgetsFlutterBinding has not been initialized yet. '
        'Creating $SentryWidgetsFlutterBinding.');
    // No binding exists yet, create our custom one
    SentryWidgetsFlutterBinding();
    return WidgetsBinding.instance;
  }
}