call method
A Callable method for the Integration interface
Implementation
@override
void call(Hub hub, SentryFlutterOptions options) {
_options = options;
final binding = BindingUtils.getWidgetsBindingInstance();
if (binding == null) {
return;
}
// WidgetsBinding works with WidgetsFlutterBinding and other custom bindings
final wrapper = dispatchWrapper ??
PlatformDispatcherWrapper(binding.platformDispatcher);
_defaultOnError = wrapper.onError;
_integrationOnError = (Object exception, StackTrace stackTrace) {
_options!.logger(
SentryLevel.error,
"Uncaught Platform Error",
logger: 'sentry.platformError',
exception: exception,
stackTrace: stackTrace,
);
final handled = _defaultOnError?.call(exception, stackTrace) ?? true;
// As per docs, the app might crash on some platforms
// after this is called.
// https://master-api.flutter.dev/flutter/dart-ui/PlatformDispatcher/onError.html
// https://master-api.flutter.dev/flutter/dart-ui/ErrorCallback.html
final mechanism = Mechanism(
type: 'PlatformDispatcher.onError',
handled: handled,
);
final throwableMechanism = ThrowableMechanism(mechanism, exception);
var event = SentryEvent(
throwable: throwableMechanism,
level: SentryLevel.fatal,
// ignore: invalid_use_of_internal_member
timestamp: options.clock(),
);
// unawaited future
hub.captureEvent(event, stackTrace: stackTrace);
return handled;
};
wrapper.onError = _integrationOnError;
dispatchWrapper = wrapper;
options.sdk.addIntegration('OnErrorIntegration');
}