我在终端上使用以下命令创建了一个新项目:
flutter create test_app
然后,创建了资产文件夹和图像文件夹。我已将一个图像添加到此文件夹中进行测试。
test_app /资产/图像/
test_app / assets / images / note.png
我已经为资产文件夹编辑了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 Phone。
我的电脑是macOS Catalina 10.15.6。
谢谢...
您需要像这样给出图像的完整路径:
Image(image: AssetImage('assets/images/note.png')),
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句