2

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!
DiyorbekDev
  • 706
  • 1
  • 5
  • 19

1 Answers1

1

Could you please try with newer version : flutter_svg: ^1.1.0

Use SVG cleaner or LOAD Assets in pubspec.yaml: see this :

  1. load assets in pubspec.yaml
  2. see the answer to the same question download SVG cleaner or upload SVG online and clean it. it works for me.
amit.flutter
  • 883
  • 9
  • 27