I am using the flutter_svg package(version
^1.0.3
). I got svg icons from fathtericons site. But I have erros. I couldn’t find a better solution to this. filter icon
Output Error
══╡ EXCEPTION CAUGHT BY SVG ╞═══════════════════════════════════════════════════════════════════════
The following assertion was thrown resolving a single-frame picture stream:
Unable to load asset: assets/icons/task/filter.svg
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:237:7)
<asynchronous suspension>
#1 AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:72:27)
<asynchronous suspension>
#2 AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:546:25)
<asynchronous suspension>
Picture provider: ExactAssetPicture(name: "assets/icons/task/filter.svg", bundle: null, colorFilter:
null)
Picture key: AssetBundlePictureKey(bundle: PlatformAssetBundle#75508(), name:
"assets/icons/task/filter.svg", colorFilter: null, theme: SvgTheme(currentColor: null, fontSize:
14.0, xHeight: 7.0))
════════════════════════════════════════════════════════════════════════════════════════════
My Code:
SvgButton(
svg: 'assets/icons/task/filter.svg',
onPressed: () {
},
),
class SvgButton extends StatelessWidget {
const SvgButton({
Key? key,
required this.svg,
this.width = 24,
this.height = 24,
this.color,
this.onPressed,
}) : super(key: key);
final String svg;
final double width;
final double height;
final Color? color;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
return IconButton(
icon: SvgPicture.asset(
svg,
color: color,
height: height.w,
width: width.w,
),
onPressed: onPressed,
alignment: Alignment.center,
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
);
}
}
My pubspec.yaml
flutter:
uses-material-design: true
assets:
- assets/icons/
My Flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19044.1706], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Professional 2022 17.1.3)
[√] Android Studio (version 2021.1)
[√] VS Code (version 1.67.2)
[√] Connected device (4 available)
[√] HTTP Host Availability
• No issues found!