Created
February 28, 2021 12:08
-
-
Save omerasif57/ede83eda65a3271c4c00aa8c32ff58f3 to your computer and use it in GitHub Desktop.
Download A Network Image In Flutter using Dio Library
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
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