簡體   English   中英

使用 image.asset() 在 flutter 中導入圖像時出現問題

[英]problem in importing images in flutter using 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/

您的pubspec.yaml應如下所示:

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

並不是

assets:
   - images/

添加您需要的所有圖像。

PROJECT DIRECTORY中創建一個名為 assets 的文件夾,而不是在 lib 或其他文件夾中。 將圖像拖放到資產文件夾中。 現在你的 pubspec.yaml 就像

資產:

  • 資產/

認為您的路徑看起來像:

/assets/images/mall.png

但是你的 pubspec.yaml 說的是:

/圖片/mall.png

找不到它。

確保您的文件樹與您在 pubspec.yaml 中所說的相同,並且不要忘記正確縮進。

要明確:

資產:

  • 圖片/

並不意味着 /assets/images/

那么它應該是:

資產:

  • 資產/圖像/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM