'How to prevent Image.file() in flutter from being laggy?

I am working on a flutter project and building a page where we have image folders as dropdown menu and as we select one, the page should display all the images present in that folder. I have achieved this using platform channels, but the problem is, I am trying to load all those images in a GridView using Image.file(), and it loads all those images very very slow and the whole UI freezes. How to fix it and make it smooth?



Solution 1:[1]

It's likely that your app hits its allocated memory. Out of Memory error is thrown because the images being displayed and cached are full-sized images that are most likely resized (still takes a chunk of memory). I suggest generating thumbnails for the images that you'll display to save memory. There are a lot of helpful answers on this post that you can choose from.

If you're just using the Image GridView as an image picker, you may want to consider using image_picker plugin as an option.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Omatt