obtainCacheStatus method
- required ImageConfiguration configuration,
- 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.
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,
}) {
final Completer<ImageCacheStatus?> completer = Completer<ImageCacheStatus?>();
_createErrorHandlerAndKey(
configuration,
(T key, ImageErrorListener innerHandleError) {
completer.complete(PaintingBinding.instance.imageCache.statusForKey(key));
},
(T? key, Object exception, StackTrace? stack) async {
if (handleError != null) {
handleError(exception, stack);
} else {
InformationCollector? collector;
assert(() {
collector = () => <DiagnosticsNode>[
DiagnosticsProperty<ImageProvider>('Image provider', this),
DiagnosticsProperty<ImageConfiguration>('Image configuration', configuration),
DiagnosticsProperty<T>('Image key', key, defaultValue: null),
];
return true;
}());
FlutterError.reportError(FlutterErrorDetails(
context: ErrorDescription('while checking the cache location of an image'),
informationCollector: collector,
exception: exception,
stack: stack,
));
completer.complete();
}
},
);
return completer.future;
}