使用image.asset()导入图像的问题
我经常遇到这个错误,说:
抛出以下断言解决图像编解码器:无法 负载资产:../ images/Mall.png
即使YAML文件正确。
这是我的pubspec.yaml
environment:
sdk: ">=2.18.0-10.0.dev <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
# The following section is specific to Flutter packages.
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/
I'm constantly getting this error saying:
The following assertion was thrown resolving an image codec: Unable to
load asset: ../images/mall.png
Even though the YAML file is correct.
This is my pubspec.yaml
environment:
sdk: ">=2.18.0-10.0.dev <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
# The following section is specific to Flutter packages.
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/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的
pubspec.yaml
应该看起来像这样:不要
添加所需的所有图像。
Your
pubspec.yaml
should look something like this:and not
Add the all images you need.
在项目目录中创建一个名为Assets的文件夹
不在lib或其他一些文件夹中。将图像拖放到资产文件夹中。
现在您的pubspec.yaml就像
资产:
Create a folder named as assets in PROJECT DIRECTORY
not in lib or some other folder. Drag and drop your image into assets folder.
Now your pubspec.yaml would be like
assets:
我 think 您的路径看起来像:
,但是您的pubspec.yaml说的是:
,找不到它。
确保您的Filetree与您在PubSpec.yaml中所说的相同,不要忘记正确缩进。
明确:
并不意味着/资产/图像/
应该是:
I think you have a path that looks like:
but your pubspec.yaml is saying it's:
and can't find it.
Make sure your filetree is the same as you're telling it is in pubspec.yaml and don't forget to indent correctly.
To be clear:
does NOT mean /assets/images/
it should then be: