如何解决Flutter Dart:无法加载 SVG 资产:无法加载资产 iconPath
我正在尝试使用 flutter_svg 包加载一些 .svg 图标。
class _MyHomePageState extends State<MyHomePage> {
final String iconPath = "assets/icons/adept.svg";
...
}
我将包含 assets/
文件夹的 icons/
文件夹添加到 pubspec.yaml
文件中:
assets:
- assets/
当我尝试在我的身体内加载图标时:
body: Center(
child: Container(
child: LimitedBox(
child: SvgPicture.asset('iconPath',color: Colors.black,width: 100,height: 100,),maxHeight: 100,maxWidth: 100,)
)
),
我得到这个 StackTrace,无法加载资产:assetName,
I/Flutter (10154): ══╡ EXCEPTION CAUGHT BY SVG ╞═══════════════════════════════════════════════════════════════════════
I/Flutter (10154): The following assertion was thrown resolving a single-frame picture stream:
I/Flutter (10154): Unable to load asset: iconPath
I/Flutter (10154):
I/Flutter (10154): When the exception was thrown,this was the stack:
I/Flutter (10154): #0 PlatformAssetBundle.load (package:Flutter/src/services/asset_bundle.dart:223:7)
...
I/Flutter (10154): Picture provider: ExactAssetPicture(name: "iconPath",bundle: null,colorFilter: null)
I/Flutter (10154): Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#153a9(),name: "iconPath",I/Flutter (10154): colorFilter: null)
I/Flutter (10154): ════════════════════════════════════════════════════════════════════════════════════════════════════
请向我解释我遗漏了什么?
解决方法
你有没有像下面的代码那样改变?
assets:
- assets/
- assets/icons/
body: Center(
child: Container(
child: LimitedBox(
child: SvgPicture.asset(iconPath,color: Colors.black,width: 100,height: 100,),maxHeight: 100,maxWidth: 100,)
)
),
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。