download method
File download.
url.savePathThe path to save the downloaded file.
Implementation
Future<File> download(String url, String savePath) async {
final completer = Completer<File>();
url = http.config.apiDomain + url;
http.dio.download(
url,
savePath,
options: Options(responseType: ResponseType.stream),
).then((response) {
if (response.statusCode != 200) {
completer.completeError('Failed to download');
return;
}
completer.complete(Future<File>.value(File(savePath)));
}).catchError((error) {
completer.completeError(error.toString());
});
return completer.future;
}