onError method

  1. @override
  2. @mustCallSuper
void onError(
  1. FlutterErrorDetails details
)

Override if you like to customize error handling.

Implementation

@override
@mustCallSuper
void onError(FlutterErrorDetails details) {
  // Don't call this routine within itself.
  if (_inError) {
    return;
  }
  _inError = true;

  // If it involves the widgets library,
  // call the latest SateX object's error routine
  // Possibly the error occurred there.
  final library = details.library;
  if (library != null && library.contains('widgets library')) {
    final state = endState;
    if (state != null) {
      try {
        (state as StateX).onError(details);
      } catch (e, stack) {
        recordException(e, stack);
      }
      // Always test if there was an error in the error handler
      // Include it in the error reporting as well.
      if (hasError) {
        _onErrorInHandler();
      }
    }
  }

  // The base Error Handler
  super.onError(details);

  // Always test if there was an error in the error handler
  // Include it in the error reporting as well.
  if (hasError) {
    _onErrorInHandler();
  }

  // If there's any 'inline function' error handler.
  // It takes last precedence.
  if (inError != null) {
    try {
      inError!(details);
    } catch (e, stack) {
      recordException(e, stack);
    }
    // Always test if there was an error in the error handler
    // Include it in the error reporting as well.
    if (hasError) {
      _onErrorInHandler();
    }
  }

  _inError = false;
}