Preload an image asset in flutter

Viewed 2477

I'm building a game with flutter. I have around 130-150mo of pictures. And some of them must be preloaded or else the user experience doesn't feels smooth.

I found by myself a way to preload images :

final asset = new ExactAssetImage(assetPath);
final stream = asset.resolve(createLocalImageConfiguration(context));

While this works, there's a huge drawback : The memory cost is about 6 times bigger then the actual image size.

Consequence ? My app end up consuming 800 MO of ram just by loading images, which is insane (especially considering it's a relatively simple app). In fact the ram consumption is so big that I get tons of frame lost.

So in short : What is the most ideal way to preload an image ? Is there something I missed ?

1 Answers

If you want the UX to feel smooth then you can use FadeInImage() and give it an asset image to use as placeholder until the final image loads, and if you want to fade in image from a transparent background then you can use the transparent_image package.

Related