image - 检索网络 Assets 时出错( flutter )

标签 image flutter assets flutter-web

我遇到了 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/

相关文章:

javascript - JavaScript 中图像的文件路径

php - 如何从 MySQL 列中提取图像以显示在 Web 应用程序上

具有保存位置的 JQuery 可拖动图像

flutter - 通过DropDownList中的DropdownMenuItem在Flutter中传递对象

iphone - 在 Cocos2d 中缩放 CCMenuItem (Objective-C)

android - 从 Flutter Dart 中的 MainActivity.java 读取变量

android - 当前上下文中不存在名称 'Assets'

android - 1280 x 800 平板电脑尺寸 - 是 tvdpi 还是 xhdpi?或 mdpi 大小?

Yii2 AssetBundle 中的 Javascript 未在更新时发布

flutter - Flutter 中数据表的动态行高