【问题标题】:Flutter Unable to load asset: but dir doesnt existFlutter 无法加载资产:但目录不存在
【发布时间】:2020-08-12 15:32:53
【问题描述】:

flutter 抛出这些错误但是他找不到的图像不存在! 确实存在的图像位于文件夹 assets/images/ 中,并且具有其他(正常)名称。 我在 pubspec.yaml 中正确导入了它们 有什么办法可以解决这个奇怪的问题?

══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/v.png

When the exception was thrown, this was the stack:
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
#4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:360:22)
#5      ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:80)
#6      ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:108:19)
#7      ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:334:9)
#8      ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:464:26)
(elided 13 frames from dart:async)

Image provider: AssetImage(bundle: null, name: "assets/images/v.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#8dc86(), name: "assets/images/v.png",
  scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/images/v.png

When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:223:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:669:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:652:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
...
Image provider: AssetImage(bundle: null, name: "assets/images/v.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#8dc86(), name: "assets/images/v.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: Unable to load asset: assets/images/e.png

════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/images/e.png
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: Unable to load asset: assets/images/h.png

════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/images/h.png
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: Unable to load asset: assets/images/i.png

════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/images/i.png
════════════════════════════════════════════════════════════════════════════════════════════════════

【问题讨论】:

  • 如果是inide lib文件夹就不行,看看是不是这样
  • dart 文件在 lib 中,图片在项目的主目录中

标签: flutter dart


【解决方案1】:
 you can go to pubspec.yaml and give folder path there
 assets:
- assets/images/

Don't need to give the name of image just give folder path then

再次运行应用程序

【讨论】:

  • flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true assets: - assets/images/ 我的 pubspec.yaml 已经是这样了,这就是我的问题!
  • 请检查缩进资产:- assets/images/
猜你喜欢
  • 2020-04-28
  • 2021-05-10
  • 2020-04-11
  • 2020-04-26
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 2021-01-17
  • 2021-10-14
相关资源
最近更新 更多