set static method

bool set({
  1. FlutterExceptionHandler? handler,
  2. ErrorWidgetBuilder? screen,
  3. ReportErrorHandler? report,
  4. bool? allowNewErrorHandlers,
  5. bool? presentError,
  6. ParagraphStyle? paragraphStyle,
  7. TextStyle? textStyle,
  8. EdgeInsets? padding,
  9. double? minimumWidth,
  10. Color? backgroundColor,
})

Set a handler and the report

Implementation

static bool set({
  FlutterExceptionHandler? handler,
  ErrorWidgetBuilder? screen,
  ReportErrorHandler? report,
  bool? allowNewErrorHandlers,
  bool? presentError,
  i.ParagraphStyle? paragraphStyle,
  i.TextStyle? textStyle,
  EdgeInsets? padding,
  double? minimumWidth,
  Color? backgroundColor,
}) {
  // Any subsequent assignments are not permitted.
  _presentError ??= presentError;

  _paragraphStyle ??= paragraphStyle;

  _textStyle ??= textStyle;

  _padding ??= padding;

  _minimumWidth ??= minimumWidth;

  _backgroundColor ??= backgroundColor;

  // Once you're not allowed to set the handlers, they can't be changed.
  if (_givenErrorHandler && !AppErrorHandler.allowNewErrorHandlers) {
    return false;
  }

  // Are you allowed to reset a handler?
  // Only if an item was passed to reset.
  var reset = false;

  if (handler != null) {
    _errorHandler = handler;
    reset = true;
  }

  if (report != null) {
    _errorReport = report;
    reset = true;
  }

  if (screen != null) {
    // Record the current 'Error Widget'
    _oldBuilder ??= ErrorWidget.builder;
    // if not already assigned
    if (ErrorWidget.builder != screen) {
      ErrorWidget.builder = screen;
    }
    reset = true;
  }

  // Flag when something was assigned
  if (!_givenErrorHandler && reset) {
    // Set only once
    _givenErrorHandler = true;
  }

  /// Allow for a new Error handler in the future
  if (AppErrorHandler.allowNewErrorHandlers &&
      !(allowNewErrorHandlers ?? true)) {
    // Once set to false, it's unchangeable
    AppErrorHandler.allowNewErrorHandlers = false;
  }

  // Something was set;
  return reset;
}