YImage function

Widget YImage(
  1. double? width,
  2. double? height,
  3. String url, {
  4. BoxFit fit = BoxFit.contain,
  5. String? imagePlaceHolder,
})

加载图像

Implementation

Widget YImage(double? width, double? height, String url, {BoxFit fit = BoxFit.contain, String? imagePlaceHolder}) {
  if (yIsNullOrEmpty(url)) return Image.asset(yIsNullOrEmpty(imagePlaceHolder) ? YConfig.imagePlaceHolder : imagePlaceHolder!, width: width, height: height, fit: fit);
  return ExtendedImage.network(
    url,
    loadStateChanged: (ExtendedImageState state) {
      switch (state.extendedImageLoadState) {
        case LoadState.loading:
          return Image.asset(yIsNullOrEmpty(imagePlaceHolder) ? YConfig.imagePlaceHolder : imagePlaceHolder!, width: width, height: height, fit: fit);
        case LoadState.completed:
          return state.completedWidget;
        case LoadState.failed:
          return yIsNullOrEmpty(imagePlaceHolder) ? SizedBox(width: width, height: height, child: const Icon(Icons.error)) : Image.asset(imagePlaceHolder!, width: width, height: height, fit: fit);
      }
    },
    width: width,
    height: height,
    fit: fit,
  );
}