简体   繁体   English

为什么flutter_svg包不能在包中工作?

[英]Why flutter_svg package not working in a package?

My problem is, I am writing a package and it is contains some helpful widgets.我的问题是,我正在编写一个包,它包含一些有用的小部件。 And what I do succeed is simply, create a widget with uses my package assets and show it to any app.我所做的只是简单地使用我的包资产创建一个小部件并将其显示给任何应用程序。

So;所以;

dependencies: flutter: sdk: flutter flutter_svg: ^1.0.3依赖项:颤振:sdk:颤振颤振_svg:^1.0.3

flutter: assets:颤振:资产:

  • assets/illustrations/资产/插图/

I add correctly the svg assets to my package, and I call it on my widget like;我将 svg 资产正确添加到我的包中,然后在我的小部件上调用它,例如;

SvgPicture.asset(
        "assets/illustrations/xx.svg",
        width: 50,
        height: 220.0,
      )

if we assume my widget name XX如果我们假设我的小部件名称 XX

I am using the XX widget in my app like XX();我在我的应用程序中使用 XX 小部件,例如 XX();

and I am getting these errors;我收到了这些错误;

The following assertion was thrown resolving a single-frame picture stream:

Unable to load asset: assets/illustrations/....svg无法加载资产:资产/插图/....svg

When the exception was thrown, this was the stack: 

#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7) #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)

#1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:72:27) #1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:72:27)

#2 AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:546:25) #2 AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:546:25)

But if I do same steps for adding assets and using same way the same .svg file on my real app, it is working correctly.但是,如果我在我的真实应用程序上执行相同的步骤来添加资产并使用相同的 .svg 文件,它就可以正常工作。

So here is my question;所以这是我的问题; What is the difference using a svg asset in a package and call it from the real app project.在包中使用 svg 资产并从真实的应用程序项目中调用它有什么区别。

and lastly, I am sorry for my poor english but any idea will be gladly accepted, thank u :)最后,我很抱歉我的英语很差,但任何想法都会很乐意接受,谢谢你:)

I found the solution at from here and what we need is simply, give the package: "", parameter.从这里找到了解决方案,我们需要的很简单,给出包:“”,参数。

 SvgPicture.asset(
        "assets/illustrations/xxx.svg",
        width: 50,
        height: 220.0,
        package: "packageName",
      ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM