Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Last active July 29, 2019 13:03
Show Gist options
  • Save plateaukao/ffc76091e5d6901e220d6ea9bed60840 to your computer and use it in GitHub Desktop.
Save plateaukao/ffc76091e5d6901e220d6ea9bed60840 to your computer and use it in GitHub Desktop.
flutter_load_image_slow.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,);
// 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