flutter学习--Image组件

本文介绍了Flutter中Image组件的使用,包括通过Image.asset、Image.network、Image.file和Image.memory加载图片的方式,详细讲解了fit属性设置,如BoxFit.fill、BoxFit.contain等。同时提到了图片的混合模式colorBlendMode以及repeat属性用于图片重复显示的各种选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

加入图片的几种方式

  • Image.asset:加载资源图片,就是加载项目资源目录中的图片,加入图片后会增大打包的包体体积,用的是相对路径。
  • Image.network:网络资源图片,意思就是你需要加入一段http://xxxx.xxx的这样的网络路径地址。
  • Image.file:加载本地图片,就是加载本地文件中的图片,这个是一个绝对路径,跟包体无关。
  • Image.memory: 加载Uint8List资源图片
    1.Image.asset方法:
    首先在项目跟目录新建文件夹assets/images,在images文件夹下添加一张图片,然后在pubspec.yaml文件中配置asset资源,在flutter:节点下添加;
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
          - assets/images/你的图片名

配置完成,package get
然后,在代码中使用:

body: Center(
          child: Container(
            child: Image.asset(
              'assets/images/ic_launcher72.png',
              width: 200.0,
              height: 200.0,
              scale: 1.0,
              color: Colors.black,
            ),
            width: 400.0,
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值