美文网首页Flutter圈子Flutter中文社区
flutter插件中使用图片需要注意

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

作者: xiaobug | 来源:发表于2020-05-11 14:21 被阅读0次

    最近发布了一个插件到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

    相关文章

      网友评论

        本文标题:flutter插件中使用图片需要注意

        本文链接:https://www.haomeiwen.com/subject/eclunhtx.html