createAssetImage method

Widget createAssetImage(
  1. String url, {
  2. double? width,
  3. double? height,
  4. LoadStateChanged? loadStateChanged,
  5. AnimationController? controller,
  6. BoxShape? boxShape,
  7. BoxFit fit = BoxFit.cover,
  8. BorderRadiusGeometry borderRadius = BorderRadius.zero,
})

extend的assets图里面有闪烁

Implementation

Widget createAssetImage(String url, {double? width, double? height,LoadStateChanged? loadStateChanged,
  AnimationController? controller, BoxShape? boxShape, BoxFit fit = BoxFit.cover, BorderRadiusGeometry borderRadius = BorderRadius.zero}) {
  if (url.isEmpty) return const SizedBox();
  debugPrint("====================${url}===============`");
  //指定外包的两种方式
  /*return ClipRRect(
    borderRadius: borderRadius,
    // asset形式的extend_image会闪烁,所以用原生哦
    child: Image.asset(
      url,
      width: width,
      height: height,
      fit: fit,
    ),
  );*/
  return ExtendedImage.asset(  url,
    width: width,
    height: height,
    fit: fit,

    loadStateChanged: loadStateChanged ??
            (ExtendedImageState state) {
          switch (state.extendedImageLoadState) {
            case LoadState.loading: //加载中。。。
              if (controller != null) {
                controller.reset();
              }
              return VImgLoading();

          ///if you don't want override completed widget
          ///please return null or state.completedWidget
          //return null;
          //return state.completedWidget;
            case LoadState.completed: //加载完成
              if (controller != null) {
                controller.forward();
              }
              return FadeTransition(
                  opacity: controller!,
                  // CurvedAnimation(parent: controller!, curve: Curves.easeIn),
                  child: state.completedWidget

                //   ExtendedRawImage(
                //   //如果你想重写完成图片的 size 或者 sourceRect, 你可以通过使用 ExtendedRawImage 来完成
                //   image: state.extendedImageInfo?.image,
                //   width: 20,
                //   height: 30,
                // ),
              );
            case LoadState.failed: //加载失败
              if (controller != null) {
                controller.reset();
              }
              state.imageProvider.evict();
              return VImgLoadFailed(reloadClick: state.reLoadImage);
              ;
              break;
          }
        },
  );

}