flutter_svg
flutter_svg copied to clipboard
Unable to load asset: resources/icons/mouse.svg;
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.
Does the error builder not work in this case?
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
Ah! haha I was imagining API that doesn't exist. This should be easy to fix.
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
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.
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
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
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.
so what's the solution? I encountered this bug today.
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?
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.
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?
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.
Ah phew!! Glad it's not me. I was going crazy trying different settings on my end, glad to know it's identified.
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.
My names are lowercase as files, but issue is present