检索Web资产时出错(颤振)

时间:2019-08-31 12:41:13

标签: image flutter assets flutter-web

我遇到Flutter WEB的问题。我遵循了Flutter团队(https://flutter.dev/docs/development/ui/assets-and-images)上有关资产的教程,但是收到错误

SearchBar(text: $searchText)

我的pubspecs.yaml

 ══╡ 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)
════════════════════════════════════════════════════════════════════════════════════════════════════ 

我正在加载这样的图像

flutter:
  uses-material-design: true

  assets:
    - assets/images/

我在哪里弄糟?

1 个答案:

答案 0 :(得分:1)

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

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

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