download method

Future<DownloadClientData> download({
  1. required Uri url,
  2. Directory? directoryDownload,
  3. String? newFileName,
  4. bool isAutoDeleteDownloadClientData = true,
  5. required FutureOr onProggres(
    1. double proggres,
    2. File file
    ),
  6. required FutureOr onDone(
    1. DownloadClientData downloadClientData
    ),
})

Implementation

Future<DownloadClientData> download({
  required Uri url,
  Directory? directoryDownload,
  String? newFileName,
  bool isAutoDeleteDownloadClientData = true,
  required FutureOr<dynamic> Function(double proggres, File file) onProggres,
  required FutureOr<dynamic> Function(DownloadClientData downloadClientData)
      onDone,
}) async {
  DownloadClientData? downloadClientData = getDownloadClientData(uri: url);

  if (downloadClientData == null) {
    downloadClientData = await downloadRaw(
      url: url,
      directoryDownload: directoryDownload,
      newFileName: newFileName,
      isAutoDeleteDownloadClientData: isAutoDeleteDownloadClientData,
      onProggres: onProggres,
      onDone: onDone,
    );

    download_client_datas.add(downloadClientData);
    return downloadClientData;
  } else {
    if (downloadClientData.is_complete()) {
      if (isAutoDeleteDownloadClientData) {
        deleteDownloadClientData(uri: url);
      }
    }
    return downloadClientData;
  }
}