getDisplayThumbnailFromMediaItem method

ImageProvider<Object> getDisplayThumbnailFromMediaItem(
  1. {required AppModel appModel,
  2. required MediaItem item,
  3. String? fallbackUrl,
  4. bool noOverride = false}
)

Given a MediaItem, return its thumbnail. Some media items may allow overriding of values for display purposes.

Implementation

ImageProvider<Object> getDisplayThumbnailFromMediaItem({
  required AppModel appModel,
  required MediaItem item,
  String? fallbackUrl,
  bool noOverride = false,
}) {
  ImageProvider<Object>? overrideThumbnail =
      getOverrideThumbnailFromMediaItem(
    appModel: appModel,
    item: item,
  );

  if (!noOverride && overrideThumbnail != null) {
    return overrideThumbnail;
  }

  if (item.imageUrl != null) {
    if (item.imageUrl!.startsWith('file://')) {
      return FileImage(File(item.imageUrl!.replaceFirst('file://', '')));
    } else {
      return CachedNetworkImageProvider(
        fallbackUrl ?? item.imageUrl!,
        cacheKey: item.uniqueKey,
      );
    }
  }

  if (item.base64Image == null) {
    return MemoryImage(kTransparentImage);
  }

  UriData? data = Uri.parse(item.base64Image!).data;
  if (data != null) {
    /// A cached version of [MemoryImage] so that the image does not reload
    /// on every revisit
    return CacheImageProvider(item.uniqueKey, data.contentAsBytes());
  } else {
    return MemoryImage(kTransparentImage);
  }
}