flutter 相关之添加图片
flutter添加图片在win和linux上【环境】1、win子系统ubuntu18.042、ubuntu下flutter版本1.22.43、xrdp 远程桌面1、win102、win10下flutter版本1.24.0.10-1.pre一、win上添加1、创建图片存放目录mkdir imagestree -L 1├── README.md├── android├── build├── has-a
·
flutter添加图片在win和linux上
【环境】
1、win子系统ubuntu18.04
2、ubuntu下flutter版本1.22.4
3、xrdp 远程桌面
1、win10
2、win10下flutter版本1.24.0.10-1.pre
一、win上添加
1、创建图片存放目录
mkdir images
tree -L 1
├── README.md
├── android
├── build
├── has-anmimation-bak-main.dart-txt.txt
├── images
├── ios
├── lib
├── linux
├── pubspec.lock
├── pubspec.yaml
├── test
└── textdisplay.iml
images文件名可以随意设置
2、修改文件pubspec.yaml
# The following section is specific to 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
# To add assets to your application, add an assets section, like this:
assets:
- images/1.jpg
# - images/a_dot_ham.jpeg
use-material-design: true
assets: 前确保是两个空格
“- images” -前面确保四个空格,-后面有一个空格 images文件名和上面创建的一致
3、修改main.dart
child: new Image.asset("images/1.jpg"),
实现方式有很多种,就不一一举例了,可以网上搜索。
4、执行就可以了
二、ubuntu上添加
操作过程和win上一模一样,但是每次执行都会出错,后来将1.jpg 文件格式改成了 1.png后,就可以正常显示了。
原因到底是不支持.jpg文件还是其他,暂时不明,待后续找到真正原因再更新该文档。
更多推荐


所有评论(0)