captureErrors static method
Configures Flutter to send errors to Fullstory for handling.
Registers for errors from the widget build face
(via FlutterError.onError)and non-widget errors
(via PlatformDispatcher.instance.onError
).
If you would prefer to handle errors yourself, use crashEvent to report errors to Fullstory in your crash handling logic.
Once an error is captured, Fullstory will end the session and shut down.
Set errorHandler
to run any graceful shutdown or user notification
logic you would like to run after the crash has been captured.
errorHandler
is called for both widget and non-widget errors.
Since errorHandler
is called after the crash has been captured and
Fullstory has shut down, most Fullstory APIs will not work here.
Any previously registered error handlers for either FlutterError.onError
or PlatformDispatcher.instance.onError
will be called after
errorHandler
completes.
Implementation
static void captureErrors({
void Function(Object? exception, StackTrace? stack)? errorHandler,
}) {
WidgetsFlutterBinding.ensureInitialized();
final flutterHandler = FlutterError.onError;
FlutterError.onError = (details) async {
await FS.crashEvent(
name: 'Flutter error',
exception: details.exception,
stackTrace: details.stack,
);
errorHandler?.call(details.exception, details.stack);
flutterHandler?.call(details);
};
final platformHandler = PlatformDispatcher.instance.onError;
PlatformDispatcher.instance.onError = (error, stack) {
FS.crashEvent(
name: 'Platform error',
exception: error,
stackTrace: stack,
);
errorHandler?.call(error, stack);
return platformHandler?.call(error, stack) ?? false;
};
}