1.先在Android Studio 中添加插件 flutter-img-sync 。
2.在项目根目录下新建存放图片的文件夹,放入需要使用的图片。
3.在配置文件 pubspec.yaml 中添加 :
assets: # assets-generator-begin # assets/img/* # assets/img/3x/* # assets-generator-end
4.使用插件工具。
5.随便写个端口。
6.可以看到生成了一个 R.dart 文件。
7.如何使用。
先添加引用 import 'r.dart';
return Container(
width: double.infinity,
height: double.infinity,
color: Colors.white,
child: Image.asset(R.assetsImgSplash, ///你本地的图片--local picture
fit: BoxFit.fill,///自动填充页面大小--auto fill page size
),
);