使用image.asset()导入图像的问题

发布于 2025-01-22 01:32:12 字数 743 浏览 0 评论 0原文

我经常遇到这个错误,说:

抛出以下断言解决图像编解码器:无法 负载资产:../ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

极致的悲 2025-01-29 01:32:12

您的pubspec.yaml应该看起来像这样:

assets:
   - images/mall.png
   - images/example.png

不要

assets:
   - images/

添加所需的所有图像。

Your pubspec.yaml should look something like this:

assets:
   - images/mall.png
   - images/example.png

and not

assets:
   - images/

Add the all images you need.

看春风乍起 2025-01-29 01:32:12

项目目录中创建一个名为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:

  • assets/
笑咖 2025-01-29 01:32:12

think 您的路径看起来像:

/assets/images/mall.png

,但是您的pubspec.yaml说的是:

/images/mall.png

,找不到它。

确保您的Filetree与您在PubSpec.yaml中所说的相同,不要忘记正确缩进。

明确:

资产:

  • 图像/

并不意味着/资产/图像/

应该是:

资产:

  • 资产/图像/

I think you have a path that looks like:

/assets/images/mall.png

but your pubspec.yaml is saying it's:

/images/mall.png

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:

assets:

  • images/

does NOT mean /assets/images/

it should then be:

assets:

  • assets/images/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文