我正在尝试使用flutter_svg软件包加载一些.svg图标。
class _MyHomePageState extends State<MyHomePage> {
final String iconPath = "assets/icons/adept.svg";
...
}
我在pubspec.yaml
文件中添加了包含icons/
文件夹的assets/
文件夹:
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): ════════════════════════════════════════════════════════════════════════════════════════════════════
请友善地解释我错过了什么?
SvgPicture.asset('assets/icons/adept.svg')
。 - Andrej- assets/icons/
,我原本以为只需要添加父文件夹,所有后续文件夹都会自动包含,但事实并非如此,很奇怪。 - user13848261