downloadWithProgress method
Stream<int>
downloadWithProgress(
- String url,
- String targetPath, {
- String? token,
- int maxRetries = 10,
- CancelToken? cancelToken,
- bool? foreground,
override
Downloads a file with progress tracking
Returns a stream of progress percentages (0-100)
Parameters:
url: Source URLtargetPath: Destination pathtoken: Optional auth tokenmaxRetries: Max retry attempts for transient errors (default: 10) Note: Auth errors (401/403/404) fail after 1 attempt regardless of this valuecancelToken: Optional token for cancellationforeground: Android foreground service mode (shows notification, no timeout)- null (default): auto-detect based on file size (>500MB = foreground)
- true: always use foreground
- false: never use foreground
Throws:
- DownloadCancelledException if cancelled via cancelToken
Example:
final cancelToken = CancelToken();
await for (final progress in downloader.downloadWithProgress(..., cancelToken: cancelToken)) {
print('Progress: $progress%');
}
// Cancel from elsewhere: cancelToken.cancel('User cancelled');
Implementation
@override
Stream<int> downloadWithProgress(
String url,
String targetPath, {
String? token,
int maxRetries = 10,
CancelToken? cancelToken,
bool? foreground,
}) {
// Delegate to SmartDownloader for all URLs
// SmartDownloader provides HTTP-aware retry logic for ANY URL
return SmartDownloader.downloadWithProgress(
url: url,
targetPath: targetPath,
token: token,
maxRetries: maxRetries,
cancelToken: cancelToken,
foreground: foreground,
);
}