[英]I have a problem when i try to access the image /assets in Flutter
This is an error when I run the program, so I am a newbie in this language (Click to see an image)这是我运行程序时的错误,所以我是这门语言的新手(点击查看图片)
This is my file "pubspec.yaml ", I think I corrected every syntax and space, but it still happens this error (Click to see an image) And this这是我的文件“pubspec.yaml”,我想我纠正了每一个语法和空间,但它仍然发生这个错误(点击查看图像)和这个
Did you tried to add your image in asset folder in your project directory?您是否尝试将图像添加到项目目录的资产文件夹中?
Try below code hope its help to you.试试下面的代码希望它对你有帮助。
Make sure you have create assets folder in your project working directory, put your images in assets folder and write below code in your pubspec.yaml
file.确保在项目工作目录中创建了资产文件夹,将图像放在资产文件夹中,并在pubspec.yaml
文件中写入以下代码。
Refer adding assets in your project here请在此处参考在您的项目中添加资产
Your pubspec.yaml file你的 pubspec.yaml 文件
assets:
- assets/
Your Widget:你的小工具:
Image.asset('assets/human.jpg'),
1- make sure you write image path correctly 1-确保正确写入图像路径
2- write this commend in terminal 2- 在终端中写这个表扬
flutter pub get
or if you use vsCode ope pubspec.yaml and click Ctrl + s或者如果你使用 vsCode ope pubspec.yaml 然后点击 Ctrl + s
Change your pubspec.yaml file更改您的 pubspec.yaml 文件
from从
- assets/human.jpg
to this对此
assets:
- assets/
and your和你的
child : Image(
image : AssetImage("assets/human.jpg")
)
)
and finally make sure your space before asset最后确保您在资产之前的空间
(2 empty spces or 1 tab) assets:
(4 empty spces or 2 tabs) - assets/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.