Image
加入图片的方式:
- Image.asset 项目资源图片
- Image.file (绝对路径) 系统资源图片
- Image.network(url) 网络资源图片
fit属性
- BoxFit.fill
- BoxFit.contain
- BoxFit.cover
repeat属性
- ImageRepeat.repeat 横向和纵向都重复,铺满整个容器
- ImageRepeat.repeatX 横向重复
- ImageRepeat.repeatY 纵向重复
body: new Center( child: new Container( child: new Image.network( 'https://profile.csdnimg.cn/0/5/2/1_jyd0124', fit: BoxFit.cover, //color: Colors.lightBlue, //colorBlendMode: BlendMode.darken, //图片混合模式(colorBlendMode)和color属性配合使用 ), width: 300.0, height: 200.0, color: Colors.lightGreen, ) ),
Image.asset( 'images/flutter_logo.png', //图片资源路径 ), Image.asset( 'images/flutter_logo.png', width: 100, //图片宽度 height: 100, //图片高度 fit: BoxFit.fill, //适配显示方式,fill表示宽高填充满 ), Image.asset( 'images/flutter_logo.png', color: Colors.red, //混合的颜色,和colorBlendMode一起使用 colorBlendMode: BlendMode.overlay, //颜色和图片混合模式,功能较强大,其它模式参见官方文档或源码 ), Image.asset( 'images/flutter_logo.png', width: 200, height: 200, repeat: ImageRepeat.repeat, //在宽高内重复平铺图片,直到铺满 )
除以上使用的Image.asset()构造函数外,Image还有Image.file()、Image.network()和Image.memory()等命名构造函数。
- Image.file 可通过路径加载SD卡中存储的图片,安卓使用此方法时需要申请
android.permission.READ_EXTERNAL_STORAGE
权限。
-
Image.network 可通过url加载网络图片。
-
Image.memory 可通过Uint8List对象加载内存中的图片。