我经常收到这样的错误:
在解析图像编解码器时抛出以下断言:无法加载资源:../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/
您的pubspec.yaml
应该看起来像这样:
assets:
- images/mall.png
- images/example.png
和
assets:
- images/
添加您需要的所有图像。
在PROJECT DIRECTORY中创建一个名为assets的文件夹不在lib或其他文件夹中。将图像拖放到assets文件夹中。现在是pubspec。Yaml应该是
资产:
- 资产/
我认为您的路径看起来像:
/资产/图片/mall.png
但是你的pubspec。Yaml说它是:
/图片/mall.png
找不到
确保您的文件树与您在pubspec中告诉它的相同。而且不要忘记正确缩进。
说明:
资产:
- 图像/
不代表/assets/images/
应该是:
资产:
- 资产/图片/