download method
override
Downloads a file from a given url to the temporary directory with the given name.
Returns a future that resolves to the downloaded File.
Use onProgress to get notified about the download progress
totalis the total number of bytes to downloaddownloadedis the number of bytes that have been downloaded so farpercentis the percentage of the download that has been completed (between 0 and 1)
Throws an Exception if the download fails.
Implementation
@override
Future<File> download(
String url,
String name, {
void Function(int total, int downloaded, double percent)? onProgress,
}) async {
final dir = await getTemporaryDirectory();
final file = File('${dir.path}/$name');
await dio.download(
url,
file.path,
onReceiveProgress: (count, total) {
onProgress?.call(total, count, count / total);
},
);
if (!file.existsSync()) throw Exception('Download failed');
return file;
}