Repository: flutter
Issue: [flutter_svg] Unable to load asset: resources/icons/mouse.svg;
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/604_

Original report by @krll-kov on Oct 1, 2021

```
Unable to load asset: resources/icons/mouse.svg; #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224)<asynchronous suspension>#1      AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:68)<asynchronous suspension>#2      AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:462)<asynchronous suspension>
```

```
Bad state: Invalid SVG data; #0      SvgParserState.parse (package:flutter_svg/src/svg/parser_state.dart:823)#1      SvgParser.parse (package:flutter_svg/parser.dart:25)#2      Svg.fromSvgString (package:flutter_svg/svg.dart:119)#3      Svg.svgPictureStringDecoder (package:flutter_svg/svg.dart:80)#4      SvgPicture.svgStringDecoder.<anonymous closure> (package:flutter_svg/svg.dart:571)#5      AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:473)<asynchronous suspension>
```

Maybe it'll be good to add some onError widget alternative for cases when package can not load some asset to avoid  unhandled exceptions. This can happen in release mode if user deletes resources folder or if image downloads broken.

---
Comment by @dnfield on Oct 1, 2021
Does the error builder not work in this case?

---
Comment by @krll-kov on Oct 1, 2021
> Does the error builder not work in this case?

Isn't it global? What if i want something specific for error on this svg and something other for others? And the main goal is to avoid any unhandled exceptions in application

---
Comment by @dnfield on Oct 1, 2021
Ah! haha I was imagining API that doesn't exist. This should be easy to fix.

---
Comment by @krll-kov on Oct 2, 2021
> Ah! haha I was imagining API that doesn't exist. This should be easy to fix.

I thought you were talking about this https://flutter.dev/docs/testing/errors#define-a-custom-error-widget-for-build-phase-errors

---
Comment by @dnfield on Oct 13, 2021
I could have sworn there was a PR at some point to add an `errorBuilder` property to `SvgPicture`.

I would be in support of this. The patch just needs a test to be landed. I can get to this eventually but I'm not sure when right now - if you're interested in writing it I'd be happy to review.

---
Comment by @Taosif7 on Jan 13, 2022
> ```
> Unable to load asset: resources/icons/mouse.svg; #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224)<asynchronous suspension>#1      AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:68)<asynchronous suspension>#2      AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:462)<asynchronous suspension>
> ```
> 
> ```
> Bad state: Invalid SVG data; #0      SvgParserState.parse (package:flutter_svg/src/svg/parser_state.dart:823)#1      SvgParser.parse (package:flutter_svg/parser.dart:25)#2      Svg.fromSvgString (package:flutter_svg/svg.dart:119)#3      Svg.svgPictureStringDecoder (package:flutter_svg/svg.dart:80)#4      SvgPicture.svgStringDecoder.<anonymous closure> (package:flutter_svg/svg.dart:571)#5      AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:473)<asynchronous suspension>
> ```
> 
> Maybe it'll be good to add some onError widget alternative for cases when package can not load some asset to avoid unhandled exceptions. This can happen in release mode if user deletes resources folder or if image downloads broken.

Please make sure that the path to your file is included in pubspec.yaml

---
Comment by @krll-kov on Jan 14, 2022
> > ```
> > Unable to load asset: resources/icons/mouse.svg; #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224)<asynchronous suspension>#1      AssetBundle.loadString (package:flutter/src/services/asset_bundle.dart:68)<asynchronous suspension>#2      AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:462)<asynchronous suspension>
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > ```
> > Bad state: Invalid SVG data; #0      SvgParserState.parse (package:flutter_svg/src/svg/parser_state.dart:823)#1      SvgParser.parse (package:flutter_svg/parser.dart:25)#2      Svg.fromSvgString (package:flutter_svg/svg.dart:119)#3      Svg.svgPictureStringDecoder (package:flutter_svg/svg.dart:80)#4      SvgPicture.svgStringDecoder.<anonymous closure> (package:flutter_svg/svg.dart:571)#5      AssetBundlePictureProvider._loadAsync (package:flutter_svg/src/picture_provider.dart:473)<asynchronous suspension>
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Maybe it'll be good to add some onError widget alternative for cases when package can not load some asset to avoid unhandled exceptions. This can happen in release mode if user deletes resources folder or if image downloads broken.
> 
> Please make sure that the path to your file is included in pubspec.yaml

Ahahahahaha, do you think i did not do that and posted an issue?) This problem happens in release mode on a small percentage of devices. While almost everyone do not face this bug and have all svgs loaded correctly, there's a little amount of users who can not use the app properly because of this issue

---
Comment by @Taosif7 on Jan 14, 2022

> Ahahahahaha, do you think i did not do that and posted an issue?) This problem happens in release mode on a small percentage of devices. While almost everyone do not face this bug and have all svgs loaded correctly, there's a little amount of users who can not use the app properly because of this issue

sorry for doubting you, I actually made this mistake a while ago so I thought. anyways.

---
Comment by @ferdinaand on Dec 5, 2022
so what's the solution? 
I encountered this bug today.

---
Comment by @acoutts on Feb 2, 2023
Today after upgrading to 2.0 from 1.1.1+1, I'm unable to load svg assets from other packages which previously worked. Could it be related?

```dart
SvgPicture.asset(
  'assets/images/scan-bar.svg'
  package: 'componentlib',
  width: 20,
  height: 20,
),
```

If I take the same svg file and put it in my own package, then it works.

---
Comment by @dnfield on Feb 2, 2023
> Today after upgrading to 2.0 from 1.1.1+1, I'm unable to load svg assets from other packages which previously worked. Could it be related?
> 
> ```dart
> SvgPicture.asset(
>   'assets/images/scan-bar.svg'
>   package: 'componentlib',
>   width: 20,
>   height: 20,
> ),
> ```
> 
> If I take the same svg file and put it in my own package, then it works.

There's a bug in the package loading logic in 2.0, sorry about that.

---
Comment by @acoutts on Feb 2, 2023
Ah phew!! Glad it's not me. I was going crazy trying different settings on my end, glad to know it's identified.

---
Comment by @JaredS129 on Sep 29, 2023
For anyone still experiencing this issue, here's something that worked for me:

I discovered that the SVG filenames are case sensitive once you run your app in release mode, hence why this error only appears in production.

Check that your SVG filename and the path in your SvgPicture.asset() widget have identical casing.
In my case my file was named 'Icon.svg', but the path was 'icon.svg'. This caused the "Bad state: Invalid SVG data" error in release mode only. The SVG was still visible in debug mode.

---
Comment by @krll-kov on Sep 30, 2023
My names are lowercase as files, but issue is present