Skip to content

Instantly share code, notes, and snippets.

@obadajasm
Created April 12, 2020 13:29
Show Gist options
  • Save obadajasm/6c4f0dfab2f76c75c5e671314e2896cc to your computer and use it in GitHub Desktop.
Save obadajasm/6c4f0dfab2f76c75c5e671314e2896cc to your computer and use it in GitHub Desktop.
Future<void> download2(String url, String savePath) async {
var per = await Permission.storage.request();
if (per.isGranted) {
toogleisDownloading();
try {
Response response = await Dio().get(
url,
onReceiveProgress: (received, total) {
showDownloadProgress(received, total);
},
//Received data with List<int>
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
validateStatus: (status) {
return status < 500;
}),
);
// print(response.headers);
File file = File(savePath);
var raf = file.openSync(mode: FileMode.write);
// response.data is List<int> type
raf.writeFromSync(response.data);
await raf.close();
} catch (e) {
errMsg = e;
}
toogleisDownloading();
notifyListeners();
} else {
errMsg =
"we need Storage permission to download subtitles to your device ...";
notifyListeners();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment