Skip to content

Instantly share code, notes, and snippets.

@omerasif57
Created February 28, 2021 12:08
Show Gist options
  • Save omerasif57/ede83eda65a3271c4c00aa8c32ff58f3 to your computer and use it in GitHub Desktop.
Save omerasif57/ede83eda65a3271c4c00aa8c32ff58f3 to your computer and use it in GitHub Desktop.
Download A Network Image In Flutter using Dio Library
Future<Null> _downloadNetworkImage() async {
Dio dio = Dio();
try {
var dir = await getTemporaryDirectory();
print(dir);
Scaffold.of(context).showSnackBar(
SnackBar(content: Text("Downloading image. Please wait...")));
await dio.download(url, '${dir.path}/image.jpeg',
onReceiveProgress: (rec, total) {
setState(() {
_downloading = true;
_progressString = ((rec / total) * 100).toStringAsFixed(0) + "%";
print(progressString);
if (_progressString == "100%") {
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("Next Action...")));
// NextAction();
}
});
});
} catch (exp) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment