我遇到了 Flutter WEB 的问题。我按照 Flutter 团队 (https://flutter.dev/docs/development/ui/assets-and-images) 的 Assets 教程进行操作,但是收到错误
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/my_custom_image.png
When the exception was thrown, this was the stack:
dart:sdk_internal 4602:11 throw_
load
package:flutter_web/…/services/asset_bundle.dart:220
dart:sdk_internal 25309:9 <fn>
...
Image provider: AssetImage(bundle: null, name: "assets/images/my_custom_image.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#078a9(), name:
"assets/images/my_custom_image.png", scale: 1)
════════════════════════════════════════════════════════════════════════════════════════════════════
我的 pubspecs.yaml
flutter:
uses-material-design: true
assets:
- assets/images/
我正在加载这样的图像
Image.asset("assets/images/my_custom_image.png")
我哪里搞砸了?
最佳答案
由于 flutter for web
的状态仍为 preview
,因此 Assets 处理与移动设备不同。assets
文件夹应位于web
文件夹和图像的引用路径不应包含 assets
:
Image.asset("images/my_custom_image.png")
在 flutter for web
中,我们不需要引用 pubspec.yaml 中的资源。
关于image - 检索网络 Assets 时出错( flutter ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57738104/