【发布时间】:2020-12-17 18:16:25
【问题描述】:
我在终端上使用这个命令创建了一个新项目:flutter create test_app
然后,我创建了 assets 文件夹和 images 文件夹。我已在此文件夹中添加了一张图片进行测试。
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模拟器和Android手机我都试过了。
我的电脑是 macOS Catalina 10.15.6。
谢谢...
【问题讨论】:
标签: flutter flutter-dependencies