flutter插件中使用图片需要注意

最近发布了一个插件到pub,在项目中远程依赖该库时,报错,提示找不到图片资源,但是图片肯定是有的,怎么会找不到了呢???

I/flutter (27000): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (27000): The following assertion was thrown resolving an image codec:
I/flutter (27000): Unable to load asset: images/video_down.png
I/flutter (27000): When the exception was thrown, this was the stack:
I/flutter (27000): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (27000): <asynchronous suspension>
I/flutter (27000): #1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:484:44)
I/flutter (27000): #2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:469:14)
I/flutter (27000): #3      ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter (27000): #4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter (27000): #5      ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter (27000): (elided 13 frames from package dart:async)
I/flutter (27000): Image provider: AssetImage(bundle: null, name: "images/video_down.png")
I/flutter (27000): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#c80a5(), name: "images/video_down.png",
I/flutter (27000):   scale: 1.0)
I/flutter (27000): ════════════════════════════════════════════════════════════════════════════════════════════════════

通过查看文档,参考其他大佬写的插件,最终发现需要插件中使用图片时,需要把包名加入;
如,下图中是插件中用的一些资源图片,已经在pubspec.ymal中进行了声明

image.png

使用时,需要在使用图片资源时,增加package的配置
image.png

否则将插件发布pub后,远程依赖该库时会报错
image.png

同时,该情况同样适用于组件化的一些方案。

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值