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 ) )
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.
Use the FadeInImage widget for exactly this purpose. FadeInImage works with images of any type: in-memory, local assets, or images from the internet.
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.
Call .image
on your ImageProvider.
In your case:
Container( decoration: BoxDecoration( color: Colors.green, image: DecorationImage( image: img.image // <--- .image added here ) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With