Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Image object to ImageProvider

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     ) ) 
like image 615
vonqo Avatar asked Nov 15 '19 04:11

vonqo


People also ask

How do I use image in ImageProvider in Flutter?

To obtain an ImageStream from an ImageProvider, call resolve, passing it an ImageConfiguration object. ImageProvider uses the global imageCache to cache images. The type argument T is the type of the object used to represent a resolved configuration. This is also the type used for the key in the image cache.

How do I fade an image in Flutter?

Use the FadeInImage widget for exactly this purpose. FadeInImage works with images of any type: in-memory, local assets, or images from the internet.

How pass an asset image as a File in Flutter?

And, In the case of the AssetImage() or Image. asset() widget, we need to pass the image path of String type. We have to simply use the _selectedImage. path that will convert the image file of File type to a valid Asset image path format.


1 Answers

Call .image on your ImageProvider.

In your case:

Container(   decoration: BoxDecoration(     color: Colors.green,     image: DecorationImage(       image: img.image // <--- .image added here     ) ) 
like image 126
Michael Peterson Avatar answered Oct 04 '22 08:10

Michael Peterson