AppErrorHandler constructor

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

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? builder,
  ReportErrorHandler? report,
  bool? allowNewHandlers,
}) {
  _this ??= AppErrorHandler._(builder);

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

  // Allow for null. Simply allow new handles by default
  allowNewHandlers ??= 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 (!allowNewHandlers && reassigned) {
    _allowNewHandlers = false;
  }
  return _this!;
}