initialize static method

Future<void> initialize({
  1. UCrashListener? onCrash,
})

Starts catching errors; previous handlers (console, other reporters) keep working. Call it in main() after initU().

Implementation

static Future<void> initialize({UCrashListener? onCrash}) async {
  _crashListener = onCrash;
  // Chain the previous handlers so errors still reach the console / other reporters.
  final bool Function(Object, StackTrace)? previousPlatform = PlatformDispatcher.instance.onError;
  PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
    _recordError(error, stack);
    previousPlatform?.call(error, stack);
    return true;
  };
  final FlutterExceptionHandler? previousFlutter = FlutterError.onError;
  FlutterError.onError = (FlutterErrorDetails details) {
    _recordFlutterError(details);
    previousFlutter?.call(details);
  };
}