Flutter Image object to ImageProvider

vonqo picture vonqo · Nov 15, 2019 · Viewed 32k times · Source

I had to read my image source from base64 to flutter Image object.

Image img = Image.memory(base64Decode(BASE64_STRING));

and then i wanted to put the image as a Container background. But DecorationImage is only accepting ImageProvider.

How to convert Image to ImageProvider? or is ther any other way to deliver base64 image to ImageProvider?

Container(
  decoration: BoxDecoration(
    color: Colors.green,
    image: DecorationImage(
      image: img // <-- Expecting ImageProvider
    )
)

Answer

Michael Peterson picture Michael Peterson · Feb 28, 2020

Call .image on your ImageProvider.

In your case:

Container(
  decoration: BoxDecoration(
    color: Colors.green,
    image: DecorationImage(
      image: img.image // <--- .image added here
    )
)