Home > Blockchain >  How to get Image's extension from url in Flutter?
How to get Image's extension from url in Flutter?

Time:11-11

I have an url that corresponds to an image.
The url looks like https://myImageUrl (there's no reference to the extension).
I want to show this image but i don't know if it's an svg or a jpg.
Is there a way to get the image's extension from its url? I've tried mime package https://pub.dev/packages/mime but it doesn't work.
I need to know the image's extension because:

  • if it's a svg I'll use SVG library
  • if it's a jpg I'll use Image.network('myImageUrl')

CodePudding user response:

Is there a way to get the image's extension from its url

No. If it's not there, it's not there. There is no magic available that would show missing information.

Since you want to load it from assets if it's an svg (which seems weird, but okay), you could just check the given URL against all assets... if it's in their, show it from assets.

  • Related