obtainKey method

  1. @override
Future<_SizeAwareCacheKey> obtainKey (
  1. ImageConfiguration configuration

Converts an ImageProvider's settings plus an ImageConfiguration to a key that describes the precise image to load.

The type of the key is determined by the subclass. It is a value that unambiguously identifies the image (including its scale) that the load method will fetch. Different ImageProviders given the same constructor arguments and ImageConfiguration objects should return keys that are '==' to each other (possibly by using a class for the key that itself implements ==).


Future<_SizeAwareCacheKey> obtainKey(ImageConfiguration configuration) {
  Completer<_SizeAwareCacheKey> completer;
  // If the imageProvider.obtainKey future is synchronous, then we will be able to fill in result with
  // a value before completer is initialized below.
  SynchronousFuture<_SizeAwareCacheKey> result;
  imageProvider.obtainKey(configuration).then((Object key) {
    if (completer == null) {
      // This future has completed synchronously (completer was never assigned),
      // so we can directly create the synchronous result to return.
      result = SynchronousFuture<_SizeAwareCacheKey>(_SizeAwareCacheKey(key, width, height));
    } else {
      // This future did not synchronously complete.
      completer.complete(_SizeAwareCacheKey(key, width, height));
  if (result != null) {
    return result;
  // If the code reaches here, it means the imageProvider.obtainKey was not
  // completed sync, so we initialize the completer for completion later.
  completer = Completer<_SizeAwareCacheKey>();
  return completer.future;