download method

Future<File> download(
  1. String url,
  2. String savePath
)

File download.

  • url .
  • savePath The 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;
}