Roaa94/dashtronaut

Image caching for planet pngs

Closed this issue · 1 comments

Hi @Roaa94

I watched your presentation on this project and under the performance part you mentioned something about caching the planet images.

Could you kindly explain what it is for and where in the code you did that?

Thank you for this great project.

Hi Aytunc

I'm very happy that you watched the presentation and glad that you like the project.

Regarding caching images, this is done with a “precacheImage” function built-in in flutter. All you have to do is call this method, I’m calling it in the didChangeDependencies of my App widget, and give it the value of the ImageProvider.

bool _isInit = true;

@override
void didChangeDependencies() {
  if (_isInit) {
    for (BackgroundLayerType layerType in BackgroundLayers.types) {
      precacheImage(
        Image.asset('assets/images/background/${layerType.name}.png').image,
        context,
      );
    }

    for (int size in Puzzle.supportedPuzzleSizes) {
      precacheImage(
        Image.asset('assets/images/puzzle-solved/solved-${size}x$size.png').image,
        context,
      );
    }
  }
  _isInit = false;
  super.didChangeDependencies();
}

You can read more details about this in this article I just published where you can also read about the other performance optimization I mentioned in the presentation: warming up SKSL shaders.

https://dashtronaut.app/tutorials/performance

Feel free to let me know if you have any questions 🙌🏼