ParallelDownloadTask constructor

ParallelDownloadTask({
  1. String? taskId,
  2. required dynamic url,
  3. Map<String, String>? urlQueryParameters,
  4. String? filename,
  5. Map<String, String>? headers,
  6. String? httpRequestMethod,
  7. int chunks = 1,
  8. String directory = '',
  9. BaseDirectory baseDirectory = BaseDirectory.applicationDocuments,
  10. String group = 'default',
  11. Updates updates = Updates.status,
  12. bool requiresWiFi = false,
  13. int retries = 0,
  14. bool allowPause = false,
  15. int priority = 5,
  16. String metaData = '',
  17. String displayName = '',
  18. DateTime? creationTime,
})

Creates a ParallelDownloadTask

A ParallelDownloadTask is a DownloadTask that downloads the file from one or more URLs, and in one or more chunks per URL. The parallel download may speed up download from slow or restrictive servers.

taskId must be unique. A unique id will be generated if omitted url properly encoded if necessary, can include query parameters and can be a list of urls, each providing the same file. The same urlQueryParameters and headers will be applied to all urls in the list urlQueryParameters may be added and will be appended to the url, must be properly encoded if necessary filename of the file to save. If omitted, a random filename will be generated headers an optional map of HTTP request headers httpRequestMethod the HTTP request method used (e.g. GET) chunks the number of chunks to break the download into, i.e. the number of downloads that will happen in parallel directory optional directory name, precedes filename baseDirectory one of the base directories, precedes directory group if set allows different callbacks or processing for different groups updates the kind of progress updates requested requiresWiFi if set, will not start download until WiFi is available. If not set may start download over cellular network retries if >0 will retry a failed download this many times allowPause if true, allows pause command priority in range 0 <= priority <= 10 with 0 highest, defaults to 5 metaData user data displayName human readable name for this task creationTime time of task creation, 'now' by default.

A ParallelDownloadTask cannot be paused or resumed on failure

Implementation

ParallelDownloadTask(
    {super.taskId,
    required dynamic url,
    super.urlQueryParameters,
    super.filename,
    super.headers,
    super.httpRequestMethod,
    this.chunks = 1,
    super.directory,
    super.baseDirectory,
    super.group,
    super.updates,
    super.requiresWiFi,
    super.retries,
    super.allowPause,
    super.priority,
    super.metaData,
    super.displayName,
    super.creationTime})
    : assert(url is String || url is List<String>,
          'The `url` parameter must be a string or a list of strings'),
      assert(url is String || (url is List<String> && url.isNotEmpty),
          'The list of urls must not be empty'),
      urls = url is String
          ? [urlWithQueryParameters(url, urlQueryParameters)]
          : List.from(
              url.map((e) => urlWithQueryParameters(e, urlQueryParameters))),
      super(url: url is String ? url : url.first) {
  retriesRemaining = 0; // chunk tasks will retry instead, based on [retries]
}