美文网首页
flutter 图片工具类imageUtils

flutter 图片工具类imageUtils

作者: 张漂亮1号 | 来源:发表于2020-01-21 17:17 被阅读0次

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

    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,
          ),
        );
      }
    }
    
    image

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

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

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

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

    相关文章

      网友评论

          本文标题:flutter 图片工具类imageUtils

          本文链接:https://www.haomeiwen.com/subject/sevezctx.html