updateTaskById method

void updateTaskById(
  1. String taskId,
  2. DownloadStatus status
)

Implementation

void updateTaskById(String taskId, DownloadStatus status) {
  final task = findTaskById(taskId);
  if (task != null) {
    task.status = status;
    if (status == DownloadStatus.DOWNLOADING) {
      if (downloadingTasks.length > _poolSize) {
        DownloadTask lowest = downloadingTasks
            .where((e) => e.id != taskId)
            .reduce((a, b) => a.priority < b.priority ? a : b);
        lowest.status = DownloadStatus.PAUSED;
      }
      _download(task);
    } else if (status == DownloadStatus.COMPLETED ||
        status == DownloadStatus.FAILED ||
        status == DownloadStatus.CANCELLED) {
      _taskList.removeWhere((task) => task.id == taskId);
      _notifyTask(task);
    }
  }
}