Load your image assets faster in Flutter!

Future<void> precacheImage(
ImageProvider<Object> provider,
BuildContext context,
{Size? size,
ImageErrorListener? onError}
)
void didChangeDependencies() {      precacheImage(AssetImage("assets/logo.png"), context);     precacheImage(AssetImage("assets/home_bg.png"), context);      super.didChangeDependencies();  
}

Conclusion

This is a handy tip to load your image assets much faster! Here’s a small stats for how much time does it take to load an image with and without precacheImage()

Don’t forget to connect with me on:

Don’t stop, until you are breathing!💙
- Abhishek Doshi

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhishek Doshi

Abhishek Doshi

1.92K Followers

Google Developer Expert — Dart, Flutter & Firebase 💙💛