fast_download_manager 1.2.0
fast_download_manager: ^1.2.0 copied to clipboard
A lightweight Flutter package for downloading files with real-time progress tracking.
Fast Download Manager #
A lightweight and easy-to-use Flutter file downloader with real-time progress tracking, download speed, retry support, cancellation, status callbacks, and multiple simultaneous downloads.
Features #
- Download files from a URL
- Real-time download progress
- Download speed tracking
- Download status callbacks
- Unique download IDs
- Cancel individual downloads
- Cancel all active downloads
- Multiple simultaneous downloads
- Automatic retry support
- Configurable retry delay
- Custom HTTP headers
- Overwrite control
- Typed download exceptions
- Null Safety support
- Flutter compatible
- Simple and developer-friendly API
Installation #
Add the latest version to your pubspec.yaml:
dependencies:
fast_download_manager: ^1.2.0
Then run:
flutter pub get
Basic Usage #
import 'package:fast_download_manager/fast_download_manager.dart';
final file = await FastDownloader.download(
url: 'https://example.com/file.pdf',
savePath: '/storage/emulated/0/Download/file.pdf',
);
print('Downloaded: ${file.path}');
Download Progress #
You can receive real-time download progress:
await FastDownloader.download(
url: 'https://example.com/file.pdf',
savePath: '/storage/emulated/0/Download/file.pdf',
onProgress: (progress) {
print(
'${(progress.progress * 100).toStringAsFixed(0)}%',
);
print(
'Speed: ${progress.speedFormatted}',
);
print(
'${progress.receivedFormatted} / '
'${progress.totalFormatted}',
);
},
);
The DownloadProgress object provides:
progressreceivedtotalspeedelapsedspeedInKBspeedInMBspeedFormattedreceivedFormattedtotalFormatted
Download Status #
You can listen to the current download status:
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
onStatus: (status) {
print(status);
},
);
Available statuses:
DownloadStatus.downloading
DownloadStatus.retrying
DownloadStatus.completed
DownloadStatus.cancelled
DownloadStatus.failed
Download ID #
Every download receives a unique ID.
String? downloadId;
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
onStart: (id) {
downloadId = id;
print('Download started: $id');
},
);
You can also provide your own ID:
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
downloadId: 'my-file-download',
);
Cancel a Download #
Cancel a specific download using its ID:
FastDownloader.cancel(downloadId);
For example:
String? downloadId;
FastDownloader.download(
url: fileUrl,
savePath: filePath,
onStart: (id) {
downloadId = id;
},
);
if (downloadId != null) {
FastDownloader.cancel(downloadId!);
}
Cancel All Downloads #
Cancel all currently active downloads:
FastDownloader.cancelAll();
You can also check active downloads:
print(
FastDownloader.activeDownloads,
);
Retry Support #
Configure the number of retry attempts:
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
retryCount: 3,
);
You can also configure the retry delay:
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
retryCount: 3,
retryDelay: const Duration(
seconds: 2,
),
);
The downloader increases the delay between retry attempts.
Custom Headers #
You can pass custom HTTP headers:
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
},
);
Overwrite Control #
By default, an existing file will be overwritten: dart await FastDownloader.download( url: fileUrl, savePath: filePath, );
To keep the existing file:
dart await FastDownloader.download( url: fileUrl, savePath: filePath, overwrite: false, );
If the file already exists and overwrite is false, the existing file is returned.
Error Handling #
The package provides a typed DownloadException:
dart try { await FastDownloader.download( url: fileUrl, savePath: filePath, ); } on DownloadException catch (e) { print(e.message); print(e.type); }
Available error types:
```dart
DownloadErrorType.network
DownloadErrorType.timeout
DownloadErrorType.server
DownloadErrorType.cancelled
DownloadErrorType.storage
DownloadErrorType.unknown
You can also receive errors through onError:
await FastDownloader.download(
url: fileUrl,
savePath: filePath,
onError: (error) {
print(error.message);
},
);
Complete Example #
import 'package:fast_download_manager/fast_download_manager.dart';
Future<void> downloadFile() async {
try {
final file = await FastDownloader.download(
url: 'https://example.com/file.pdf',
savePath: '/storage/emulated/0/Download/file.pdf',
retryCount: 3,
retryDelay: const Duration(seconds: 2),
onStart: (id) {
print('Download started: $id');
},
onProgress: (progress) {
print(
'Progress: '
'${(progress.progress * 100).toStringAsFixed(0)}%',
);
print(
'Speed: ${progress.speedFormatted}',
);
print(
'Downloaded: '
'${progress.receivedFormatted} / '
'${progress.totalFormatted}',
);
},
onStatus: (status) {
print('Status: $status');
},
onComplete: (file) {
print(
'Download completed: ${file.path}',
);
},
onError: (error) {
print(
'Download error: ${error.message}',
);
},
);
print(
'File saved at: ${file.path}',
);
} on DownloadException catch (e) {
print(
'Download failed: ${e.message}',
);
}
}
Multiple Downloads #
Multiple downloads can run independently.
FastDownloader.download(
url: fileUrl1,
savePath: filePath1,
);
FastDownloader.download(
url: fileUrl2,
savePath: filePath2,
);
FastDownloader.download(
url: fileUrl3,
savePath: filePath3,
);
Each download has its own ID and cancellation token.
Cancel only one download without affecting the others:
FastDownloader.cancel(downloadId);
Version #
Current version:
1.2.0
Changelog #
1.2.0 #
- Added unique download IDs
- Added multiple simultaneous downloads
- Added individual download cancellation
- Added cancel all downloads
- Added active download tracking
- Added
DownloadProgressmodel - Added download speed tracking
- Added formatted download speed
- Added formatted file size
- Added download status callbacks
- Added retry delay support
- Added typed
DownloadException - Added typed download error categories
- Improved error handling
- Improved API structure
1.1.0 #
- Added download progress callback
- Added download speed callback
- Added retry support
- Added custom headers
- Added overwrite control
- Improved download handling
1.0.0 #
- Initial release
- Basic file downloading
- Progress tracking
- Null Safety support
License #
MIT License