小编典典

为Web检索资产时出错(flutter)

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")

我在哪里弄糟?


阅读 358

收藏
2020-08-13

共1个答案

小编典典

由于状态flutter for web仍为preview,资产处理与移动设备不同。assets文件夹应位于该web文件夹中,并且图像的引用路径不应包括assets

Image.asset("images/my_custom_image.png")

在中flutter for web,我们不需要引用pubspec.yaml中的资产。

2020-08-13