基本属性

  1. const Image({
  2. Key key,
  3. @required this.image, // 图片资源地址
  4. this.frameBuilder, //
  5. this.loadingBuilder,
  6. this.errorBuilder,
  7. this.semanticLabel,
  8. this.excludeFromSemantics = false,
  9. this.width,
  10. this.height,
  11. this.color,
  12. this.colorBlendMode,
  13. this.fit,
  14. this.alignment = Alignment.center,
  15. this.repeat = ImageRepeat.noRepeat,
  16. this.centerSlice,
  17. this.matchTextDirection = false,
  18. this.gaplessPlayback = false,
  19. this.filterQuality = FilterQuality.low,
  20. })

图片能网络请求或者项目中请求,但项目中请求需要配置pubspec.yaml信息,可以查阅 此链接

基本用法

  1. Center(
  2. child: Container(
  3. // 容器的子组件是图片组件
  4. child: Image(
  5. // 图片组件image参数为本地图片
  6. image: AssetImage("lib/image/img1.jpg"),
  7. width: 100.0,
  8. ),
  9. width: 300.0, // 容器宽度
  10. height: 300.0, // 容器的高度
  11. decoration: BoxDecoration(
  12. color: Colors.green[200], // decoration中也有color,背景颜色
  13. ),
  14. )
  15. )

image.png

alignment

  1. Center(
  2. child: Container(
  3. // 容器的子组件是图片组件
  4. child: Image(
  5. // 图片组件image参数为本地图片
  6. image: AssetImage("lib/image/img1.jpg"),
  7. width: 100.0,
  8. alignment: Alignment.bottomLeft,
  9. ),
  10. width: 300.0, // 容器宽度
  11. height: 300.0, // 容器的高度
  12. decoration: BoxDecoration(
  13. color: Colors.green[200], // decoration中也有color,背景颜色
  14. ),
  15. )
  16. )

image.png

fit

  1. Center(
  2. child: Container(
  3. // 容器的子组件是图片组件
  4. child: Image(
  5. // 图片组件image参数为本地图片
  6. image: AssetImage("lib/image/img1.jpg"),
  7. width: 100.0,
  8. fit: BoxFit.cover,
  9. ),
  10. width: 300.0, // 容器宽度
  11. height: 300.0, // 容器的高度
  12. decoration: BoxDecoration(
  13. color: Colors.green[200], // decoration中也有color,背景颜色
  14. ),
  15. )
  16. )

image.png

图片复制

  1. Center(
  2. child: Container(
  3. // 容器的子组件是图片组件
  4. child: Image(
  5. // 图片组件image参数为本地图片
  6. image: AssetImage("lib/image/img1.jpg"),
  7. width: 100.0,
  8. repeat: ImageRepeat.repeat // 背景平铺
  9. // repeat: ImageRepeat.repeatY // Y轴平铺
  10. // repeat: ImageRepeat.repeatY // X轴平铺
  11. // repeat: ImageRepeat.noRepeat // 不平铺
  12. ),
  13. width: 300.0, // 容器宽度
  14. height: 300.0, // 容器的高度
  15. decoration: BoxDecoration(
  16. color: Colors.green[200], // decoration中也有color,背景颜色
  17. ),
  18. )
  19. )

image.png