progress property

Stream<DownloadProgress> get progress

The progress of the download: the current snapshot when you listen, then events while bytes are written (at most one per 64 KiB and 100 ms), when the metadata gives the size, and on each change of state (DownloadState.paused, back to DownloadState.running, and the final one). The stream closes after the final event; errors are not sent on it but in result. It can be listened to any number of times, and earlier events are not replayed.

As with UploadTask.progress, the download can finish before a pause takes effect; check what pause returns, or wait for an event with an orElse.

Implementation

Stream<DownloadProgress> get progress => Stream<DownloadProgress>.multi((
  MultiStreamController<DownloadProgress> controller,
) {
  controller.add(snapshot);
  if (_events.isClosed) {
    controller.close();
    return;
  }
  final StreamSubscription<DownloadProgress> subscription = _events.stream
      .listen(controller.add, onDone: controller.close);
  controller.onCancel = subscription.cancel;
}, isBroadcast: true);