Member-only story

Preload Asset Images

Fred Grott
4 min readMar 18, 2022

--

Part of any well executed, quality flutter UX in Flutter UI is the act of management of the parts that make up the UI, including images. Let me show you a way to make it easy to preload all those asset images.

The Implementation

First, let’s group those asset images in a List of Strings:

Now, what we want is to during the Widget Binding phase to grab the assets via the precacheImage function:

The binding.addPostFrameCallback once the RootWidget(MaterialApp) loads calls the inner code, thus preCaching our image assets.

Keep in mind that anything that needs starting after the MaterialApp Widget loads the first frame can use that same binding.addPostFrameCallback function.

Conclusion

--

--

Fred Grott
Fred Grott

No responses yet