obtainCacheStatus method

Future<ImageCacheStatus> obtainCacheStatus (
  1. {@required ImageConfiguration configuration,
  2. ImageErrorListener handleError}
)

Returns the cache location for the key that this ImageProvider creates.

The location may be ImageCacheStatus.untracked, indicating that this image provider's key is not available in the ImageCache.

The cache and configuration parameters must not be null. If the handleError parameter is null, errors will be reported to FlutterError.onError, and the method will return null.

A completed return value of null indicates that an error has occurred.

Implementation

Future<ImageCacheStatus> obtainCacheStatus({
  @required ImageConfiguration configuration,
  ImageErrorListener handleError,
}) {
  assert(configuration != null);
  final Completer<ImageCacheStatus> completer = Completer<ImageCacheStatus>();
  _createErrorHandlerAndKey(
    configuration,
    (T key, ImageErrorListener innerHandleError) {
      completer.complete(PaintingBinding.instance.imageCache.statusForKey(key));
    },
    (T key, dynamic exception, StackTrace stack) async {
      if (handleError != null) {
        handleError(exception, stack);
      } else {
        InformationCollector collector;
        assert(() {
          collector = () sync* {
            yield DiagnosticsProperty<ImageProvider>('Image provider', this);
            yield DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration);
            yield DiagnosticsProperty<T>('Image key', key, defaultValue: null);
          };
          return true;
        }());
        FlutterError.onError(FlutterErrorDetails(
          context: ErrorDescription('while checking the cache location of an image'),
          informationCollector: collector,
          exception: exception,
          stack: stack,
        ));
        completer.complete(null);
      }
    },
  );
  return completer.future;
}