flutter_svg icon indicating copy to clipboard operation
flutter_svg copied to clipboard

SvgPicture.network - Unhandled Exception: HttpException: Could not get network asset

Open lemmerel opened this issue 2 years ago • 12 comments

When using SvgPicture.Network and the image could not be found, it throws the unhandled exception:

Unhandled Exception: HttpException: Could not get network asset, uri = http://127.0.0.1:1323/icon/person.svg

Version 2.0.3.

Could be fixed with try/catch and a parameter onException (as placeholderBuilder doesn't seem to affect it).

lemmerel avatar Mar 13 '23 09:03 lemmerel

I'm trying to remember how this works with Image.network. But.. I think throwing an exception is the right thing to do here?

dnfield avatar Mar 13 '23 17:03 dnfield

Thank you for your quick reply, @dnfield.

 @override
  Future<Uint8List?> prepareMessage(BuildContext? context) {
    try {
      return httpGet(url, headers: headers);
    } catch (HttpException) {
      throw HttpException;
    }
  }

Let me know what you think.

lemmerel avatar Mar 13 '23 20:03 lemmerel

      Widget build(BuildContext context) {
    var res;

    try {
      res = SvgPicture.network(url,
          color: color,
          width: width,
          height: height,
          placeholderBuilder: placeholderBuilder);
    } on HttpException {
      res = Container();
    }
    return res;
  }

What am I doing wrong?

lemmerel avatar Mar 13 '23 21:03 lemmerel

Ok.

To do what you want here, you'd need some kind of errorBuilder parameter on the SvgPicture.network constructor.

Right now that's not implemented but probably isn't too hard.

dnfield avatar Mar 13 '23 21:03 dnfield

I, and I'm sure all of your other very grateful users, would really appreciate it if you did that.

lemmerel avatar Mar 14 '23 09:03 lemmerel

Any news here?

lemmerel avatar Apr 04 '23 19:04 lemmerel

@dnfield

lemmerel avatar Apr 06 '23 14:04 lemmerel

This has been waiting on https://github.com/dnfield/vector_graphics/pull/196

dnfield avatar Apr 10 '23 16:04 dnfield

Ah my bad! Thank you so much for your work :)

On Mon, 10 Apr 2023 at 18:48, Dan Field @.***> wrote:

This has been waiting on dnfield/vector_graphics#196 https://github.com/dnfield/vector_graphics/pull/196

— Reply to this email directly, view it on GitHub https://github.com/dnfield/flutter_svg/issues/881#issuecomment-1502046928, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6F2KHSX45PWKFHSG7PN6W3XAQ2UJANCNFSM6AAAAAAVYY4QF4 . You are receiving this because you authored the thread.Message ID: @.***>

lemmerel avatar Apr 10 '23 16:04 lemmerel

Next steps will be to publish new vector_graphics* and then use it in flutter_svg.

dnfield avatar Apr 10 '23 18:04 dnfield

Thanks for your hard work! Seems like vector_graphics is all set, can this be pulled into flutter_svg?

glacials avatar Aug 01 '23 15:08 glacials

any news on this?

tanis2000 avatar May 13 '24 14:05 tanis2000