【问题标题】:Flutter error while adding images(assets)添加图像(资产)时出现颤振错误
【发布时间】:2021-11-24 22:41:50
【问题描述】:

我正在尝试通过资产将图像添加到我的颤振应用程序中。 this is the where i have linked the images. this is the pubspec yaml file 尝试了不同的方法。似乎没有任何效果。

【问题讨论】:

  • 您应该使用 Image.asset 小部件,然后作为第一个参数将图像的路径作为字符串。
  • 首先将 pubspec -images 中的行更改为 -assets/images 然后运行 ​​pubget 然后你就可以访问图像了

标签: flutter android-studio flutter-dependencies flutter-image flutter-assetimage


【解决方案1】:

首先在您的项目中创建一个名为 assets 的文件夹,而不是在您的 lib 文件夹中。之后在 pubspace.yaml 中定义您的文件夹,如下所示 assets/images/

【讨论】:

    【解决方案2】:

    你在 pubspace.yaml 中做错了。 如下所示保持空格

    flutter:
      assets:
        - assets/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 2019-03-09
      • 2020-01-04
      • 2022-08-10
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      相关资源
      最近更新 更多