AppErrorHandler constructor

AppErrorHandler({
  1. FlutterExceptionHandler? handler,
  2. ErrorWidgetBuilder? screen,
  3. ReportErrorHandler? report,
  4. bool? newErrorHandlers,
})

Singleton Pattern with only one instance of this Error Handler. Optionally supply the Error handler, Builder, and Report routines.

Implementation

factory AppErrorHandler({
  FlutterExceptionHandler? handler,
  ErrorWidgetBuilder? screen,
  ReportErrorHandler? report,
  bool? newErrorHandlers,
}) {
  //
  _this ??= AppErrorHandler._();

  /// Allows you to set an error handler more than once.
  final reassigned = set(handler: handler, screen: screen, report: report);

  // Allow for null. Simply allow new handles by default
  newErrorHandlers ??= true;

  // Once set to false, you can't assign different handlers anymore.
  // However, it's set to false only if one of the handlers was reassigned.
  if (!newErrorHandlers && reassigned) {
    _allowNewHandlers = false;
  }
  return _this!;
}