为Web检索资产时出错(flutter)
问题内容:
我遇到Flutter
WEB的问题。我遵循了Flutter团队关于资产的教程(https://flutter.dev/docs/development/ui/assets-
and-images
),但是收到错误消息
══╡ 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)
════════════════════════════════════════════════════════════════════════════════════════════════════
我的pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/images/
我正在加载这样的图像
Image.asset("assets/images/my_custom_image.png")
我在哪里弄糟?
问题答案:
由于状态flutter for web
仍为preview
,资产处理与移动设备不同。assets
文件夹应位于该web
文件夹中,并且图像的引用路径不应包括assets
:
Image.asset("images/my_custom_image.png")
在中flutter for web
,我们不需要引用pubspec.yaml中的资产。