Skip to content

Instantly share code, notes, and snippets.

@icatalud
Last active September 6, 2019 17:41
Show Gist options
  • Save icatalud/082cca82d74943e308e57379bffc1059 to your computer and use it in GitHub Desktop.
Save icatalud/082cca82d74943e308e57379bffc1059 to your computer and use it in GitHub Desktop.
Adds a lock to the fetch function.
var _fetching = false;
fetchAndUpdateImage([String url = 'https://picsum.photos/300/200']) async {
if(_fetching) {
return;
}
_fetching = true;
final response = await http.get(url);
floop['image'] = TransitionImage(Image.memory(response.bodyBytes));
_fetching = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment