Flutter Image全解析

本文详细介绍了Flutter中Image Widget的使用,包括加载网络、本地文件和资源图片的方法,如Image.network、Image.file和Image.asset。还讨论了构造方法、属性如semanticLabel、fit、width、height、color、colorBlendMode、alignment、centerSlice、gaplessPlayback和repeat等,帮助开发者掌握图片在Flutter应用中的各种展示技巧。

博客地址:flutterall.com

Flutter imgae支持的图片格式为:JPEG, PNG, GIF, Animated GIF, WebP, Animated WebP, BMP, and WBMP。Flutter Image是显示图片的一个Widget。

Flutter Image的几个构造方法:

方法 释义
Image() ImageProvider中获取图片,从本质上看,下面的几个方法都是他的具体实现。
Image.asset(String name) AssetBundler中获取图片
Image.network(String src) 显示网络图片
Image.file(File file) File中获取图片
Image.memory(Uint8List bytes) Uint8List中显示图片

这里来看下继承关系,就知道“从本质上看,下面的几个方法都是他的具体实现”的意思了。
ImageProvider具体实现

下面来一一介绍

加载图片的几种基本使用方式

  • 加载网络图片 Image.network

Image.network(String src, {
   
   
    Key key,
    double scale = 1.0,
    this.semanticLabel,
    this.excludeFromSemantics = false,
    this.width,
    this.height,
    this.color,
    this.colorBlendMode,
    this.fit,
    this.alignment = Alignment.center,
    this.repeat = ImageRepeat.noRepeat,
    this.centerSlice,
    this.matchTextDirection = false,
    this.gaplessPlayback = false,
    this.filterQuality = FilterQuality.low,
    Map<String, String> headers,
  })

此方法中固定参数为src表示图片的URL地址,其他为可选参数。我们指定src来加载显示图片。

Image.network("https://upload.jianshu.io/users/upload_avatars/3884536/d847a50f1da0.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240")

image.png

  • 加载File图片 Image.file
Image.file(File file, 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值