cachedFlutterImgCall method

RenderableImg? cachedFlutterImgCall({
  1. required int widthPx,
  2. required int heightPx,
  3. required ImageFileFormat format,
  4. required String? arg,
  5. required int settingsHash,
  6. required bool allowResize,
})

Memoized variant of GemKitPlatform.callGetFlutterImg.

Consults ImgCache keyed by (uid, size, format, settingsHash, imageType, allowResize). On a miss, performs the FFI call and stores the result. Subclasses that report isCacheable => false (currently only SignpostImg) bypass the cache entirely.

Implementation

RenderableImg? cachedFlutterImgCall({
  required int widthPx,
  required int heightPx,
  required ImageFileFormat format,
  required String? arg,
  required int settingsHash,
  required bool allowResize,
}) {
  if (!isCacheable) {
    return GemKitPlatform.instance.callGetFlutterImg(
      pointerId,
      widthPx,
      heightPx,
      format.id,
      arg: arg,
      allowResize: allowResize,
    );
  }
  final ImgCacheKey key = ImgCacheKey(
    uid: uid,
    widthPx: widthPx,
    heightPx: heightPx,
    formatId: format.id,
    settingsHash: settingsHash,
    imageTypeId: imageType.id,
    allowResize: allowResize,
  );
  final RenderableImg? cached = ImgCache.instance.get(key);
  if (cached != null) {
    return cached;
  }
  final RenderableImg? fresh = GemKitPlatform.instance.callGetFlutterImg(
    pointerId,
    widthPx,
    heightPx,
    format.id,
    arg: arg,
    allowResize: allowResize,
  );
  if (fresh != null) {
    ImgCache.instance.put(key, fresh);
  }
  return fresh;
}