Task constructor

  1. String? taskId,
  2. required String url,
  3. Map<String, String>? urlQueryParameters,
  4. String? filename,
  5. Map<String, String>? headers,
  6. String? httpRequestMethod,
  7. dynamic post,
  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. String metaData = '',
  15. String displayName = '',
  16. bool allowPause = false,
  17. int priority = 5,
  18. DateTime? creationTime,

Creates a Task

taskId must be unique. A unique id will be generated if omitted url properly encoded if necessary, can include query parameters 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, POST) post if set, uses POST instead of GET. Post must be one of the following:

  • a String: POST request with post as the body, encoded in utf8
  • a Map: will be jsonEncoded to a String and set as the POST body
  • a List of bytes: will be converted to a String using String.fromCharCodes and set as the POST body
  • a List: map will be jsonEncoded to a String and set as the POST body 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, task will pause if the task fails partly through the execution, when some but not all bytes have transferred, provided the server supports partial transfers. Such failures are typically temporary, eg due to connectivity issues, and may be resumed when connectivity returns 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.


    {String? taskId,
    required super.url,
    String? filename,
    String directory = '',
    this.baseDirectory = BaseDirectory.applicationDocuments,
    this.group = 'default',
    this.updates = Updates.status,
    this.requiresWiFi = false,
    this.metaData = '',
    this.displayName = '',
    this.allowPause = false,
    this.priority = 5,
    : taskId = taskId ?? Random().nextInt(1 << 32).toString(),
      filename = filename ?? Random().nextInt(1 << 32).toString(),
      directory = _startsWithPathSeparator.hasMatch(directory)
          ? directory.substring(1)
          : directory {
  if (filename?.isEmpty == true) {
    throw ArgumentError('Filename cannot be empty');
  if (_pathSeparator.hasMatch(this.filename) && this is! MultiUploadTask) {
    throw ArgumentError('Filename cannot contain path separators');
  if (allowPause && post != null) {
    throw ArgumentError('Tasks that can pause must be GET requests');
  if (priority < 0 || priority > 10) {
    throw ArgumentError('Priority must be 0 <= priority <= 10');