reportError method

  1. @protected
void reportError (
  1. {DiagnosticsNode context,
  2. dynamic exception,
  3. StackTrace stack,
  4. InformationCollector informationCollector,
  5. bool silent: false}
)
@protected, inherited

Calls all the registered error listeners to notify them of an error that occurred while resolving the image.

If no error listeners (listeners with an ImageStreamListener.onError specified) are attached, a FlutterError will be reported instead.

The context should be a string describing where the error was caught, in a form that will make sense in English when following the word "thrown", as in "thrown while obtaining the image from the network" (for the context "while obtaining the image from the network").

The exception is the error being reported; the stack is the StackTrace associated with the exception.

The informationCollector is a callback (of type InformationCollector) that is called when the exception is used by FlutterError.reportError. It is used to obtain further details to include in the logs, which may be expensive to collect, and thus should only be collected if the error is to be logged in the first place.

The silent argument causes the exception to not be reported to the logs in release builds, if passed to FlutterError.reportError. (It is still sent to error handlers.) It should be set to true if the error is one that is expected to be encountered in release builds, for example network errors. That way, logs on end-user devices will not have spurious messages, but errors during development will still be reported.

See FlutterErrorDetails for further details on these values.

Implementation

@protected
void reportError({
  DiagnosticsNode context,
  dynamic exception,
  StackTrace stack,
  InformationCollector informationCollector,
  bool silent = false,
}) {
  _currentError = FlutterErrorDetails(
    exception: exception,
    stack: stack,
    library: 'image resource service',
    context: context,
    informationCollector: informationCollector,
    silent: silent,
  );

  // Make a copy to allow for concurrent modification.
  final List<ImageErrorListener> localErrorListeners = _listeners
      .map<ImageErrorListener>((ImageStreamListener listener) => listener.onError)
      .where((ImageErrorListener errorListener) => errorListener != null)
      .toList();

  if (localErrorListeners.isEmpty) {
    FlutterError.reportError(_currentError);
  } else {
    for (final ImageErrorListener errorListener in localErrorListeners) {
      try {
        errorListener(exception, stack);
      } catch (exception, stack) {
        FlutterError.reportError(
          FlutterErrorDetails(
            context: ErrorDescription('when reporting an error to an image listener'),
            library: 'image resource service',
            exception: exception,
            stack: stack,
          ),
        );
      }
    }
  }
}