1

I have used Image.memory(base64Decode(encodedString, fit: BoxFit.cover, width: imgWidth,height: imgHeight) to load a base64 encoded image in flutter. In a listview viewing the images causes a flickering. Bcoz each time, the image is loaded again and again for each item in the list. So is there any way to cache a base64 encoded image in flutter?

Febin K R
  • 886
  • 2
  • 11
  • 21

1 Answers1

0

Instead of calling MemoryImage inside Widget build(), you can initialize the base64 images inside initState().

late List<MemoryImage> _listImages;

@override
void initState(){
  super.initState();
  
  // load images here
  _listImages.add(MemoryImage(imageData));
}

This should prevent the "flickering" happening on the widgets since the Screen is usually refreshed when the state has been changed.

Omatt
  • 8,564
  • 2
  • 42
  • 144