A Flutter plugin for managing file downloads with queue management, priority handling, and caching capabilities.
- Priority-based Download Queue: Download files with configurable priorities
- Automatic Cache Management: Checks if files are already downloaded to avoid redundant downloads
- Progress Tracking: Monitor download progress with callbacks
- Folder Structure: Automatically creates folder structure based on URL paths
- Concurrent Download Prevention: Prevents duplicate downloads of the same file
- Resume Support: Uses temporary
.downloadingfiles during download process - File Type Filtering: Supports filtering for specific file types (MP4, SVGA)
Add this to your package's pubspec.yaml file:
dependencies:
file_download_cache_manager: ^${latest version}Configure the provider in your app:
import 'package:provider/provider.dart';
import 'package:file_download_cache_manager/file_download_cache_manager.dart';
// Add to your providers
ChangeNotifierProvider<BigFilesProvider>(
create: (_) => BigFilesProvider(),
lazy: false,
),Add a file to the download queue with lowest priority (999):
final provider = Provider.of<BigFilesProvider>(context, listen: false);
final result = await provider.addDownload(
'https://example.com/video.mp4',
progressCallback: (received, total) {
print('Progress: ${(received / total * 100).toStringAsFixed(2)}%');
},
);
if (result.isSuccess) {
print('Downloaded to: ${result.filePath}');
} else {
print('Download failed: ${result.error}');
}Insert a download with specific priority (lower number = higher priority):
final result = await provider.insertDownload(
'https://example.com/important-video.mp4',
priority: 1, // Higher priority
progressCallback: (received, total) {
print('Progress: $received/$total');
},
);final isDownloaded = await provider.isFileDownloaded(
'https://example.com/video.mp4',
);
if (isDownloaded) {
final filePath = await provider.getLocalFilePath(
'https://example.com/video.mp4',
);
print('File available at: $filePath');
}Consumer<BigFilesProvider>(
builder: (context, provider, child) {
return Column(
children: [
Text('Queue length: ${provider.downloadQueue.length}'),
Text('Processing: ${provider.isProcessingQueue}'),
],
);
},
)Main provider class for handling downloads.
addDownload(String url, {DownloadProgressCallback? progressCallback})- Add download with lowest priorityinsertDownload(String url, {required int priority, DownloadProgressCallback? progressCallback})- Add download with specific priorityisFileDownloaded(String url)- Check if file exists in cachegetLocalFilePath(String url)- Get local file path if downloaded
downloadQueue- List of queued downloadsisProcessingQueue- Whether queue is currently being processed
Result object returned after download completion.
status- Download status (pending, downloading, completed, failed, cancelled)filePath- Local file path (empty if failed)error- Error message (if failed)totalBytes- Total file size in bytesreceivedBytes- Downloaded bytes
isSuccess- Returns true if download completed successfullyisFailed- Returns true if download failedisDownloading- Returns true if currently downloading
Enum representing download states:
pending- Queued but not starteddownloading- Currently downloadingcompleted- Successfully downloadedfailed- Download failedcancelled- Download was cancelled
Files are stored in the application documents directory with folder structure mirroring the URL path:
<documents_directory>/<host>/<path>/<filename>
Example:
URL: https://resource-miku.voloshow.top/image/admin/20250904/video.mp4
Path: <documents>/resource-miku.voloshow.top/image/admin/20250904/video.mp4
By default, the manager only allows:
- MP4 files (.mp4)
- SVGA files (.svga)
To modify supported file types, update the _isAllowedFile method in the source code.
The plugin handles various error scenarios:
- Invalid URLs
- Unsupported file types
- Network errors
- Storage permission issues
- Disk space issues
All errors are captured and returned in the DownloadResult object.
dio- HTTP client for downloadspath_provider- Access to device directoriesflutter/foundation.dart- ChangeNotifier support