call method
A Callable method for the Integration interface
Implementation
@override
void call(Hub hub, SentryFlutterOptions options) {
_defaultOnError = FlutterError.onError;
_integrationOnError = (FlutterErrorDetails errorDetails) async {
dynamic exception = errorDetails.exception;
options.logger(
SentryLevel.debug,
'Capture from onError $exception',
);
if (errorDetails.silent != true || options.reportSilentFlutterErrors) {
// FlutterError doesn't crash the App.
final mechanism = Mechanism(type: 'FlutterError', handled: true);
final throwableMechanism = ThrowableMechanism(mechanism, exception);
var event = SentryEvent(
throwable: throwableMechanism,
level: SentryLevel.fatal,
);
await hub.captureEvent(event, stackTrace: errorDetails.stack);
// call original handler
if (_defaultOnError != null) {
_defaultOnError!(errorDetails);
}
// we don't call Zone.current.handleUncaughtError because we'd like
// to set a specific mechanism for FlutterError.onError.
} else {
options.logger(
SentryLevel.debug,
'Error not captured due to [FlutterErrorDetails.silent], '
'Enable [SentryFlutterOptions.reportSilentFlutterErrors] '
'if you wish to capture silent errors');
}
};
FlutterError.onError = _integrationOnError;
options.sdk.addIntegration('flutterErrorIntegration');
}