【问题标题】:Image not showing in flutter.dart in vs code图像未显示在 vs 代码中的 flutter.dart 中
【发布时间】:2021-08-12 14:23:42
【问题描述】:

在我的 pubspec.yaml 文件中,

资产:-assets/

---------在我的应用程序目录文件夹中--- assets 文件夹位于 ....E:\recipes\assets

为什么在应用程序中找不到或未加载我的图像? 图片(图片: AssetImage('assets/spagetti.jpg'))

问题:我将资产文件夹(图像文件夹)放在目录中的什么位置?

enter image description here

在此处输入图片说明

【问题讨论】:

  • 请添加 pubspec.yaml 文件的截图。你可以把你的资产文件夹放在你的根目录中

标签: flutter visual-studio-code


【解决方案1】:

完全按照 pubspec.yaml 文件中的原样复制并粘贴以下代码,并将其替换为您的配置:

flutter:
  assets:
    - assets/

在此文件中设置路径时,间距很重要。这完全可以正常工作,你很高兴。

【讨论】:

  • 发生错误--- [recipes] flutter pub get 在 pubspec.yaml 中检测到错误:在“flutter”下发现了意外的子“flutter”。请更正 E:\recipes\pubspec.yaml 退出代码 1 处的 pubspec.yaml 文件
  • 同样的结果;图像仍然没有显示。我的图像目录是 e:\recipes\assets\images yaml 中的代码是 assets: -assets/images/ 但图像仍然没有显示。我需要做什么?谢谢
  • code: Widget buildRecipeCard(Recipe recipe) { // 1 return Card( // 2 child: Column( // 3 children: [ // 4 Image(image: AssetImage(recipe. imageUrl)), // 5 文本(recipe.label), ], ), ); }
  • 类食谱 { 字符串标签;字符串图像网址;食谱(this.label,this.imageUrl); static List samples = [ Recipe('Spaghetti and Meatballs', 'spagmeat.jpg'), Recipe('Tomato Soup', 'assets/27729023535_a57606c1be.jpg'), Recipe('Grilled Cheese', 'assets/3187380632_5056654a19_b 。 jpg'), ]; }
  • flutter: assets: - assets/images 只需在我的回答后添加图像,看看它是否有效
猜你喜欢
  • 2021-10-12
  • 1970-01-01
  • 1970-01-01
  • 2023-02-02
  • 2020-01-17
  • 2022-10-20
  • 1970-01-01
  • 1970-01-01
  • 2023-01-05
相关资源
最近更新 更多