resizeIfNeeded static method

ImageProvider<Object> resizeIfNeeded({
  1. required ImageProvider<Object> provider,
  2. int? cacheWidth,
  3. int? cacheHeight,
  4. double? compressionRatio,
  5. int? maxBytes,
  6. bool cacheRawData = false,
  7. String? imageCacheName,
})

Composes the provider in a ResizeImage only when cacheWidth and cacheHeight are not both null.

When cacheWidth and cacheHeight are both null, this will return the provider directly.

Extended with scaling and maxBytes.

Implementation

static ImageProvider<Object> resizeIfNeeded({
  required ImageProvider<Object> provider,
  int? cacheWidth,
  int? cacheHeight,
  double? compressionRatio,
  int? maxBytes,
  bool cacheRawData = false,
  String? imageCacheName,
}) {
  if ((compressionRatio != null &&
          compressionRatio > 0 &&
          compressionRatio < 1) ||
      (maxBytes != null && maxBytes > 0) ||
      cacheWidth != null ||
      cacheHeight != null) {
    return ExtendedResizeImage(
      provider,
      width: cacheWidth,
      height: cacheHeight,
      maxBytes: maxBytes,
      compressionRatio: compressionRatio,
      cacheRawData: cacheRawData,
      imageCacheName: imageCacheName,
    );
  }
  return provider;
}