executeDownload method
void
executeDownload(
- String url, {
- dynamic downloadHandler,
})
Implementation
void executeDownload(String url, {downloadHandler}){
try {
zeroLog('executeDownload retryDownloadCount=$retryDownloadCount');
String fileName = CommonUtils.apkName;
model.url = url;
model.status = DownloaderStatus.downloading;
model.progress = 0;
if (downloadHandler != null) {
downloadHandler(model);
}
if(isDownloading){
return;
}
isDownloading = true;
Zupdate()
.execute(
url,
destinationFilename: fileName,
)
.listen(
(ZUpdateEvent event) {
zeroLog('Zupdate status: ${event.status} : ${event.value} \n');
ZUpdateStatus status = event.status;
if (status == ZUpdateStatus.DOWNLOADING) {
model.status = DownloaderStatus.downloading;
double progress = 0;
if ((event.value ?? '').isNotEmpty) {
double progressD = double.parse(event.value ?? '0');
progress = progressD / 100;
model.progress = progress;
if (downloadHandler != null) {
downloadHandler(model);
}
}
if(progress>=1){
isDownloading = false;
model.progress = 1.0001;
if (downloadHandler != null) {
downloadHandler(model);
}
}
} else if (status == ZUpdateStatus.DOWNLOAD_ERROR ||
status == ZUpdateStatus.INTERNAL_ERROR) {
isDownloading = false;
model.status = DownloaderStatus.failed;
autoRetry();
}
},onError: (e){
zeroLog('Zupdate error:$e');
}
);
} catch (e) {
zeroLog('Failed to make Zupdate. Details: $e');
}
}