download method

Downloading download(
  1. String url,
  2. String filename,
  3. int? size, {
  4. String? checksum,
  5. String? to,
})

Downloads a file from the provided url.

Implementation

Downloading download(
  String url,
  String filename,
  int? size, {
  String? checksum,
  String? to,
}) {
  Downloading? downloading = downloads[checksum]?..start(url, to: to);

  if (downloading == null) {
    downloading = Downloading(
      checksum,
      filename,
      size,
      onDownloaded: (file) {
        if (checksum != null) {
          _downloadLocal?.upsert(checksum, file.path);
        }
      },
    )..start(url, to: to);

    if (checksum != null) {
      downloads[checksum] = downloading;
    }
  }

  return downloading;
}