Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Created July 29, 2019 13:47
Show Gist options
  • Save plateaukao/3f0f587082f77d26c5729ab14c04cb40 to your computer and use it in GitHub Desktop.
Save plateaukao/3f0f587082f77d26c5729ab14c04cb40 to your computer and use it in GitHub Desktop.
flutter_load_image_fast.dart
@override
void initState() {
super.initState();
downloadWhenNecessary();
}
downloadWhenNecessary({Function action}) {
_downloadImage().then((bytes) async {
if(!mounted) return;
// build an Image Widget from the downloaded image bytes.
final image = Image.memory(bytes, fit: BoxFit.contain,);
// do the precache here!!!
await precacheImage(image.image, context);
// ask state to build the widget right after Image Widget is created.
setState(() { });
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment