Home > Net >  Another exception was thrown: Invalid argument(s): No host specified in URI file:/// for network ima
Another exception was thrown: Invalid argument(s): No host specified in URI file:/// for network ima

Time:03-17

I have saved an image link into my firebase and the link is workable to show the image, however, when I insert the link to the NetworkImage in such:

Image(
  height: 80,
  width: 80,
  image: NetworkImage(shopLogo),
  fit: BoxFit.contain),
),

there is an error Another exception was thrown: Invalid argument(s): No host specified in URI file:/// when I enter this page but if I hot reload the page, the image only able to load. Anyone know how to solve this?

CodePudding user response:

NetworkImage is for image files on the internet

Image.file is for image files on the device (local)

Image.file(
  File('PATH_TO_YOUR_IMAGE'),
  height: 80,
  width: 80,
  fit: BoxFit.contain,
)

Ensure necessary permissions to use this

CodePudding user response:

For Firebase Hosted Files with links like file:///firebasestorage.googleapis.com/..., replace the file:/// with https:// to use in a NetworkImage

So your code should be

Image(
  height: 80,
  width: 80,
  image: NetworkImage(shopLogo.replaceFirst("file:///", "https://")),
  fit: BoxFit.contain),
),
  • Related