obtainKey method

  1. @override
Future<PocketBaseImageProvider> obtainKey(
  1. ImageConfiguration configuration
)
override

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 loadImage 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 ==).

If the result can be determined synchronously, this function should return a SynchronousFuture. This allows image resolution to progress synchronously during a frame rather than delaying image loading.

Implementation

@override
Future<PocketBaseImageProvider> obtainKey(ImageConfiguration configuration) {
  final dpr = configuration.devicePixelRatio ?? 1.0;
  var targetWidth = pixelWidth;
  var targetHeight = pixelHeight;
  final size = this.size;
  if (targetWidth == null && targetHeight == null && size != null) {
    targetWidth = _toPixels(size.width, dpr);
    targetHeight = _toPixels(size.height, dpr);
  }

  // The key carries the resolved scale and decode size, so equal inputs on
  // the same device produce equal keys.
  return SynchronousFuture<PocketBaseImageProvider>(
    PocketBaseImageProvider(
      client: client,
      recordId: recordId,
      recordCollectionName: recordCollectionName,
      filename: filename,
      thumb: thumb,
      pixelWidth: targetWidth,
      pixelHeight: targetHeight,
      scale: scale ?? dpr,
      expireAfter: expireAfter,
      token: token,
      autoGenerateToken: autoGenerateToken,
      requestPolicy: requestPolicy,
      timeout: timeout,
    ),
  );
}