DownloadManager class

Manages concurrent file downloads with queuing, retries, progress reporting, cancellation, and strategies for handling existing files.

Provides methods to request files (getFile), add downloads to a queue (addToQueue, addAllToQueue), cancel downloads (cancelDownload, cancelAll), and manage downloaded files (deleteContentFile).

It uses a base directory and an optional subdirectory to store downloads. Concurrency limits and retry attempts are configurable. Logging can be enabled via the optional logger callback.

Constructors

DownloadManager.new({required String subDir, Directory? baseDirectory, int maxConcurrentDownloads = 3, int maxRetries = 3, LogCallback? logger, FileExistsStrategy fileExistsStrategy = FileExistsStrategy.resume, Duration delayBetweenRetries = Duration.zero})
Creates a DownloadManager instance.

Properties

delayBetweenRetries Duration
A duration representing the delay between retries when a download task fails.
getter/setter pair
fileExistsStrategy FileExistsStrategy
The default strategy to use when a file already exists, applied if not specified per-download. Defaults to FileExistsStrategy.resume.
final
hashCode int
The hash code for this object.
no setterinherited
logger LogCallback?
An optional callback function for logging messages from the manager. Receives records with a message string and a LogLevel.
final
maxConcurrentDownloads int
The maximum number of downloads that can run concurrently. Defaults to 3.
final
maxRetries int
The maximum number of times a failed download will be automatically retried. Defaults to 3.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
subDir String
The name of the subdirectory within the _baseDirectory where files will be stored.
final

Methods

addAllToQueue(List<QueueItem> downloadItems) Future<void>
Iterates through the list of download configurations and calls addToQueue for each. Allows specifying individual progress callbacks per download. The strategy field in the input records is ignored.
addToQueue(QueueItem downloadItem) Future<void>
Adds a URL to the download queue without waiting for completion. Honours the manager's configured default FileExistsStrategy. Note: This method currently does not support overriding the strategy per call.
cancelAll() → void
Cancels all active and queued downloads.
cancelDownload(String url) Future<void>
Cancels a specific download (if active or queued).
deleteContentFile(QueueItem item) Future<void>
Deletes the downloaded file corresponding to the URL, if it exists. Also attempts to delete the corresponding .tmp file.
dispose() Future<void>
Disposes of the download manager, cancelling all downloads and releasing resources.
getFile(QueueItem downloadItem) Future<File?>
Retrieves a file, downloading it if necessary, based on the manager's configured default strategy.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited