flutter 图片工具类imageUtils

图片工具类,缓存图片,可以更改图片颜色

class ImgUtils {
  static showNetImg(String url) {
    return CachedNetworkImage(
      imageUrl: url ?? '',
      imageBuilder: (context, imageProvider) => Container(
        decoration: BoxDecoration(
          image: DecorationImage(
              image: imageProvider,
              fit: BoxFit.cover,
              colorFilter:
                  ColorFilter.mode(Colors.transparent, BlendMode.colorBurn)),
        ),
      ),
      placeholder: (context, url) => Center(
        child: Container(
          height: 40,
          width: 40,
          margin: EdgeInsets.all(5),
          child: CircularProgressIndicator(
            strokeWidth: 2.0,
            valueColor: AlwaysStoppedAnimation(Colors.blue),
          ),
        ),
      ),
      errorWidget: (context, url, error) => Container(
        child: Icon(
          Icons.terrain,
          size: 64,
        ),
        alignment: Alignment.center,
        color: Colors.black12,
      ),
    );
  }

  static showNetImgWH(String url, double width, double height) {
    return CachedNetworkImage(
      width: width,
      height: height,
      imageUrl: url ?? '',
      imageBuilder: (context, imageProvider) => Container(
        decoration: BoxDecoration(
          image: DecorationImage(
              image: imageProvider,
              fit: BoxFit.cover,
              colorFilter:
                  ColorFilter.mode(Colors.transparent, BlendMode.colorBurn)),
        ),
      ),
      placeholder: (context, url) => Center(
        child: Container(
          height: 40,
          width: 40,
          margin: EdgeInsets.all(5),
          child: CircularProgressIndicator(
            strokeWidth: 2.0,
            valueColor: AlwaysStoppedAnimation(Colors.blue),
          ),
        ),
      ),
      errorWidget: (context, url, error) => Container(
        child: Icon(
          Icons.terrain,
          size: 64,
        ),
        alignment: Alignment.center,
        color: Colors.black12,
      ),
    );
  }
}


更多详解:
喜欢可以加Q群号:913934649,点赞,评论;

简书: https://www.jianshu.com/u/88db5f15770d

csdn:https://me.csdn.net/beyondforme

掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7

发布了152 篇原创文章 · 获赞 18 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/beyondforme/article/details/104063934
今日推荐