downloadFile function

Future<String?> downloadFile({
  1. required String url,
  2. String? savePath,
  3. bool loading = true,
})

Implementation

Future<String?> downloadFile(
    {required String url, String? savePath, bool loading = true}) async {
  if (!BaseEasyLoading.isShow) {
    if (loading) {
      showLoading();
    }
  }

  var file = await _downloadFile(url: url);

  if (file == null) {
    if (loading) {
      dismissLoading();
    }
    return null;
  }
  final path = savePath ?? await url.crateNewSharePath;
  logDebug("download url: $url path: $path");

  await file.copy(path);
  if (loading) {
    dismissLoading();
  }
  return path;
}