downloadBatch method
- List<
DownloadTask> tasks, { - BatchProgressCallback? batchProgressCallback,
- TaskStatusCallback? taskStatusCallback,
- TaskProgressCallback? taskProgressCallback,
- void onElapsedTime()?,
- Duration? elapsedTimeInterval,
Enqueues a list of files to download and returns when all downloads
have finished (successfully or otherwise). The returned value is a
Batch object that contains the original tasks, the
Batch.results and convenience getters to filter successful and failed results.
If an optional batchProgressCallback function is provided, it will be
called upon completion (successfully or otherwise) of each task in the
batch, with two parameters: the number of succeeded and the number of
failed tasks. The callback can be used, for instance, to show a progress
indicator for the batch, where
double percent_complete = (succeeded + failed) / tasks.length
To also monitor status and/or progress for each task in the batch, provide
a taskStatusCallback and/or taskProgressCallback, which will be used
for each task in the batch.
An optional callback onElapsedTime will be called at regular intervals
(defined by elapsedTimeInterval, which defaults to 5 seconds) with a
single argument that is the elapsed time since the call to downloadBatch.
This can be used to trigger UI warnings (e.g. 'this is taking rather long')
or to cancel the task if it does not complete within a desired time.
For performance reasons the elapsedTimeInterval should not be set to
a value less than one second.
The onElapsedTime callback should not be used to indicate progress.
tasks cannot be an empty list
Implementation
Future<Batch> downloadBatch(
final List<DownloadTask> tasks, {
BatchProgressCallback? batchProgressCallback,
TaskStatusCallback? taskStatusCallback,
TaskProgressCallback? taskProgressCallback,
void Function(Duration)? onElapsedTime,
Duration? elapsedTimeInterval,
}) => _downloader.enqueueAndAwaitBatch(
tasks,
batchProgressCallback: batchProgressCallback,
taskStatusCallback: taskStatusCallback,
taskProgressCallback: taskProgressCallback,
onElapsedTime: onElapsedTime,
elapsedTimeInterval: elapsedTimeInterval,
);