downloadFile static method
Implementation
static Future downloadFile(String url, String fileName,
{Function(double percent)? onProgress,
Function()? onFinished,
Function(Object e)? onError}) async {
Dio dio = Dio();
// Download the file
var appDocDir = await appFolder();
try {
if (fileName.startsWith("/")) {
fileName = fileName.substring(1);
}
await dio.download(url, "$appDocDir/$fileName",
onReceiveProgress: (received, total) {
if (total != -1) {
var progress = received / total;
onProgress?.call(progress);
if (progress == 1) {
onFinished?.call();
}
}
});
} catch (e) {
onError?.call(e);
}
}