在根目录新建文件夹存放。如images或assets
在pubspec.yaml中添加,注意空格对齐
注意:#相关注释内的assets不能删掉#替换,需要新加
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- images/flutterjpg.jpg
引用资源
获取图片
//image:也可在assets/images中分类不同分辨率的图片,使用默认的 asset bundle 加载资源时,内部会自动处理分辨率
///第一种
image: new Image(height: 90,width: 90,image: AssetImage("images/logo.png"))
///第二种,依赖包中的图片
new AssetImage('icons/heart.png', package: 'images')
///第三种
new Image.asset('images/heart.png', fit: BoxFit.cover)
读取文件内容
///对于加载文件都要用异步请求的方式,该处返回的是Future<String>
var result= await rootBundle.loadString('assets/userInfo.json');
\