writeToFile function

Future<DownloadTaskForAll> writeToFile(
  1. File file,
  2. Reference ref
)

Implementation

Future<DownloadTaskForAll> writeToFile(File file, Reference ref) async {
  DownloadTaskForAll task = DownloadTaskForAll(targetFile: file);
  DownloadTask originalTask = ref.writeToFile(file);
  task.setDownloadingStream =
      originalTask.snapshotEvents.listen((taskSnapshot) {
    int total = taskSnapshot.metadata?.size ?? 0;
    switch (taskSnapshot.state) {
      case firebase_storage.TaskState.running:
        task.updateTask(ProcessTask(
            processed: taskSnapshot.bytesTransferred,
            total: total,
            state: models.TaskState.running));
        break;
      case firebase_storage.TaskState.paused:
        break;
      case firebase_storage.TaskState.success:
        task.updateTask(ProcessTask(
            processed: taskSnapshot.bytesTransferred,
            total: total,
            state: models.TaskState.success));
        break;
      case firebase_storage.TaskState.canceled:
        break;
      case firebase_storage.TaskState.error:
        break;
    }
  }, onError: (e, stackTrace) {
    task.addError(e, stackTrace);
  });
  return task;
}