start method
Starts the file downloading.
Implementation
Future<void> start(String url, {String? to}) async {
progress.value = 0;
status.value = DownloadStatus.inProgress;
_completer = Completer<File?>();
try {
file = await PlatformUtils.download(
url,
filename,
size,
path: to,
checksum: checksum,
onReceiveProgress: (count, total) => progress.value = count / total,
cancelToken: _token,
);
_completer?.complete(file);
if (file != null) {
status.value = DownloadStatus.isFinished;
onDownloaded?.call(file!);
} else {
status.value = DownloadStatus.notStarted;
}
} catch (e) {
_completer?.completeError(e);
status.value = DownloadStatus.notStarted;
}
}