颤动图像不显示:“无法加载资源”

Tho*_*hoe 1 flutter

我没有在应用程序中看到我的图像,而是看到一个带有 X 的红色框,上面写着Unable to load asset: images/aboutmaggie.png.

我创建了一个assets带有子目录的目录images。该目录assets与 处于同一级别pubspec.yaml

我将图像放入images目录中。当我在 Android Studio 中单击图像时,图像就会显示。

在此输入图像描述

pubspec.yaml我有这些行:

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:
    - assets/images/
Run Code Online (Sandbox Code Playgroud)

我添加了

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:
    - assets/images/
Run Code Online (Sandbox Code Playgroud)

我跑了flutter pub get。我运行了“工具”>“颤振”>“颤振清洁”。我关闭并重新启动 Android Studio。

错误信息是:

======== Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: images/aboutmaggie.png
Run Code Online (Sandbox Code Playgroud)

我尝试将另一个图像放入assets/images并调用它,但第二个图像也不会加载。

这张照片有什么问题吗?

小智 9

调用图像时出错,

更改代码中的这一行

Image.asset('images/aboutmaggie.png')
Run Code Online (Sandbox Code Playgroud)

到这一行

Image.asset('assets/images/aboutmaggie.png')
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助,谢谢