image static method

Widget image({
  1. String? url,
  2. kSize? size,
  3. double? width,
  4. double? height,
  5. BoxFit? fit,
  6. String? tag,
  7. int? cacheHeight,
  8. int? cacheWidth,
  9. double offset = 0.0,
  10. bool isResize = false,
  11. bool? isVideo = false,
  12. bool hidePlaceHolder = false,
  13. bool forceWhiteBackground = false,
  14. String kImageProxy = '',
})

Smart image function to load image cache and check empty URL to return empty box Only apply for the product image resize with (small, medium, large)

Implementation

static Widget image({
  String? url,
  kSize? size,
  double? width,
  double? height,
  BoxFit? fit,
  String? tag,
  int? cacheHeight,
  int? cacheWidth,
  double offset = 0.0,
  bool isResize = false,
  bool? isVideo = false,
  bool hidePlaceHolder = false,
  bool forceWhiteBackground = false,
  String kImageProxy = '',
}) {
  // if (height == null && width == null) {
  //   width = 20;
  // }
  var ratioImage = 1.4;

  if (url?.isEmpty ?? true) {
    // debugPrint('image*****************111 =');

    return ExtendedImage.network(
      "https://www.pphfoundation.ca/wp-content/uploads/2018/05/default-avatar.png",
      width: width,
      height: height,
      fit: fit,
      cache: true,
      enableLoadState: true,
      loadStateChanged: (ExtendedImageState state) {
        Widget? widget;
        switch (state.extendedImageLoadState) {
          case LoadState.loading:
            // showLoadingDialog();
            break;
          case LoadState.completed:
            widget = ExtendedRawImage(
              image: state.extendedImageInfo?.image,
              width: width,
              height: height,
              fit: fit,
            );
            break;
          case LoadState.failed:
            widget = Container(
              width: width,
              height: height ?? width! * ratioImage,
              color: const Color(0x0D000000),
            );
            break;
        }
        return widget;
      },
    );
  }
  else if (url!.startsWith("assets")) {
    // debugPrint('image*****************222 =');
    return Image.asset(
      url,
      width: width,
      height: height,
      fit: fit,
    );
  }
  else if (url.startsWith("http")) {
    // debugPrint('image*****************333 = $url');
    return ExtendedImage.network(
      url,
      width: width,
      height: height,
      fit: fit,
      cache: true,
      enableLoadState: true,
      cacheHeight: cacheHeight,
      cacheWidth: cacheWidth,
      loadStateChanged: (ExtendedImageState state) {
        Widget? widget;
        switch (state.extendedImageLoadState) {
          case LoadState.loading:
            // showLoadingDialog();
            break;
          case LoadState.completed:
            widget = ExtendedRawImage(
              image: state.extendedImageInfo?.image,
              width: width,
              height: height,
              fit: fit,
            );
            break;
          case LoadState.failed:
            widget = Container(
              width: width,
              height: height ?? width! * ratioImage,
              color: const Color(0x0D000000),
            );
            break;
        }
        return widget;
      },
    );
  } else {
    // debugPrint('image*****************444 =');
    return Image.file(
      File(url),
      height: height,
      fit: fit,
    );
  }
}