flutter_svg icon indicating copy to clipboard operation
flutter_svg copied to clipboard

Unable to load asset: resources/icons/mouse.svg;

Open krll-kov opened this issue 4 years ago • 14 comments

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.

krll-kov avatar Oct 01 '21 08:10 krll-kov

Does the error builder not work in this case?

dnfield avatar Oct 01 '21 14:10 dnfield

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

krll-kov avatar Oct 01 '21 16:10 krll-kov

Ah! haha I was imagining API that doesn't exist. This should be easy to fix.

dnfield avatar Oct 01 '21 22:10 dnfield

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

krll-kov avatar Oct 02 '21 14:10 krll-kov

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.

dnfield avatar Oct 13 '21 05:10 dnfield

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

Taosif7 avatar Jan 13 '22 08:01 Taosif7

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

krll-kov avatar Jan 14 '22 09:01 krll-kov

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.

Taosif7 avatar Jan 14 '22 22:01 Taosif7

so what's the solution? I encountered this bug today.

ferdinaand avatar Dec 05 '22 19:12 ferdinaand

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.

acoutts avatar Feb 02 '23 21:02 acoutts

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.

dnfield avatar Feb 02 '23 21:02 dnfield

Ah phew!! Glad it's not me. I was going crazy trying different settings on my end, glad to know it's identified.

acoutts avatar Feb 02 '23 21:02 acoutts

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.

JaredS129 avatar Sep 29 '23 21:09 JaredS129

My names are lowercase as files, but issue is present

krll-kov avatar Sep 30 '23 05:09 krll-kov