Created
July 29, 2019 13:47
-
-
Save plateaukao/3f0f587082f77d26c5729ab14c04cb40 to your computer and use it in GitHub Desktop.
flutter_load_image_fast.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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