gpt4 book ai didi

flutter - 无法从 Assets 文件夹加载图像(无缩进问题)

转载 作者:行者123 更新时间:2023-12-04 15:10:10 25 4
gpt4 key购买 nike

我在终端上使用这个命令创建了一个新项目:
flutter 创建 test_app

然后,我创建了 Assets 文件夹和图像文件夹。我已将一张图片添加到此文件夹以进行测试。

test_app/assets/images/

test_app/assets/images/note.png

我已经为 Assets 文件夹编辑了 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/

然后,我将这一行添加到 main.dart 文件中包含一些小部件的列中。

Image(image: AssetImage('images/note.png')),

我做的一切都正确,但为什么它不起作用我无法得到它?我以前做过一些项目,没有问题。我已经尝试创建许多项目来解决这个问题,但我做不到。

Unable to load asset: images/note.png

...
...

Image provider: AssetImage(bundle: null, name: "images/note.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#e7b4d(), name: "images/note.png", scale: 1.0)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.6 19G2021 darwin-x64,
locale en-TR)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.52.0)
[✓] Connected device (1 available)

• No issues found!

我试过iOS模拟器和安卓手机。

我的电脑是 macOS Catalina 10.15.6。

谢谢...

最佳答案

尝试将图像也添加到 pubspec.yaml 文件夹中,而不仅仅是 assets/images/。我的意思是:

  # To add assets to your application, add an assets section, like this:
assets:
- assets/images/image.png

那会起作用的。

关于flutter - 无法从 Assets 文件夹加载图像(无缩进问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65346210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com