检索Web资产时出错(颤振) [英] Error on retrieving assets for web (flutter)

查看:132
本文介绍了检索Web资产时出错(颤振)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I face an issue for Flutter WEB. I followed tutorial on assets from Flutter team (https://flutter.dev/docs/development/ui/assets-and-images) however I receive an error

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

My pubspecs.yaml

flutter:
  uses-material-design: true

  assets:
    - assets/images/

我正在加载这样的图像

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

我在哪里弄糟?

推荐答案

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

Since the status of flutter for web is still preview, assets handling is not the same as for mobile.assets folder should be in the web folder, and reference path for the image should not include assets:

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

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

In flutter for web, we do not need to reference the assets in the pubspec.yaml.

这篇关于检索Web资产时出错(颤振)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆