download method Null safety
download starts the download process. It starts to download the file
Implementation
Future<bool> download() async {
final Completer<bool> downloadCompleter = Completer();
String uploadUrl =
'https://${config.credentailsConfig.host}/${Uri.encodeComponent(config.url)}';
Options options = Options(headers: _header);
try {
await DioDownloadManager().download(uploadUrl, config.downloadPath,
onReceiveProgress: ((count, total) {
_downloadProgress.add([count, total]);
onRecieveProgress?.call(count, total);
}),
cancelToken: _cancelToken,
options: options,
deleteOnError: false,
resumeDownload: config.resumeDownload).then(
(value) {
dispose();
downloadCompleter.complete(true);
},
onError: (error) {
// print(error.type);
// print(error);
if (error.type == DioErrorType.cancel) {
//It was cancelled using the cancel token
errorCallback?.call('Dio cancel Error');
} else {
errorCallback?.call(error.toString());
}
dispose();
downloadCompleter.complete(false);
},
);
} catch (error) {
if ((error as dynamic).type == DioErrorType.cancel) {
//It was cancelled using the cancel token
errorCallback?.call('Dio cancel Error');
} else {
errorCallback?.call(error.toString());
}
dispose();
downloadCompleter.complete(false);
}
return downloadCompleter.future;
}