RetryImage.attachment constructor

RetryImage.attachment(
  1. ImageAttachment attachment, {
  2. BoxFit? fit,
  3. double? height,
  4. double? width,
  5. double? minWidth,
  6. BorderRadius? borderRadius,
  7. Future<void> onForbidden()?,
  8. ImageFilter? filter,
  9. bool cancelable = false,
  10. bool displayProgress = true,
})

Constructs a RetryImage from the provided attachment loading the ImageAttachment.big with a ImageAttachment.small fallback.

Implementation

factory RetryImage.attachment(
  ImageAttachment attachment, {
  BoxFit? fit,
  double? height,
  double? width,
  double? minWidth,
  BorderRadius? borderRadius,
  Future<void> Function()? onForbidden,
  ImageFilter? filter,
  bool cancelable = false,
  bool displayProgress = true,
}) {
  final ImageFile image;

  final StorageFile original = attachment.original;
  if (original.checksum != null &&
      CacheWorker.instance.exists(original.checksum!)) {
    image = original as ImageFile;
  } else {
    image = attachment.big;
  }

  double? aspectRatio;
  if (image.width != null && image.height != null) {
    aspectRatio = image.width! / image.height!;
  }

  return RetryImage(
    image.url,
    checksum: image.checksum,
    thumbhash:
        image.thumbhash ??
        attachment.big.thumbhash ??
        attachment.medium.thumbhash ??
        attachment.small.thumbhash,
    fit: fit,
    height: height,
    width: width,
    minWidth: minWidth,
    aspectRatio: aspectRatio,
    borderRadius: borderRadius,
    onForbidden: onForbidden,
    filter: filter,
    cancelable: cancelable,
    displayProgress: displayProgress,
  );
}