smartdownloader 1.0.0
smartdownloader: ^1.0.0 copied to clipboard
A Flutter plugin for smart file downloading with progress, pause, resume, retry, and background support.
Dynamic Download Manager #
A highly intelligent, dynamic Flutter plugin built to automatically parse arbitrary API JSON payloads, extract targeted image/video URLs, and instantly download them via a robust Background downloading engine.
It ships out-of-the-box with DynamicDownloadDashboard, a beautiful Riverpod-powered Drop-In widget that effortlessly provides your users with visual file indicators, byte tracking, auto-retries, Light/Dark Modes, and Grid/ListView toggles.
🚀 Features #
- Dynamic JSON Targeting: Simply pass a raw JSON map and an array of keys
['adUrl', 'store_image_url']and the plugin automatically scrapes your payload. - Drop-In Dashboard Widget: Get a beautiful grid-view screen running in just 4 lines of code without needing to build your own progress bars!
- Robust Background Engine: Powered natively by the OS. Large video files won't cancel if the user minimizes the app.
- Pre-Validation: Automatically fires off
HEADrequests to validate URLs. Broken 404 links instantly render as beautiful red interactive Error cards rather than crashing your thread. - Zero 0B Glitching: Solves legacy package bugs by persistently freezing absolute sizes mathematically if trailing TCP packets dump zeroes.
- Intelligent Auto-Sorting: In Progress and Failed tasks are forced permanently to the top of your visual list, while completed downloads naturally filter to the bottom.
💾 Installation #
dependencies:
dynamic_download_manager: ^1.0.0
🛠️ Typical Usage #
To invoke the engine natively and trigger the interactive UI, all you have to do is render the DynamicDownloadDashboard widget and feed it variables. It will entirely encompass its own ProviderState and styling isolated from the rest of your app!
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:dynamic_download_manager/dynamic_download_package.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: DemoWrapper(), // Render your application
);
}
}
class DemoWrapper extends StatefulWidget {
const DemoWrapper({super.key});
@override
State<DemoWrapper> createState() => _DemoWrapperState();
}
class _DemoWrapperState extends State<DemoWrapper> {
String? _appDocPath;
// Simulate grabbing a raw JSON API response!
final String myApiResponse = '''
{
"data": [
{
"id": 1,
"name": "Item 1",
"store_image_url": "https://picsum.photos/id/237/200/300",
"adUrl": "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4"
}
]
}
''';
@override
void initState() {
super.initState();
_initPath();
}
Future<void> _initPath() async {
// Generate the platform specific destination filepath!
final dir = await getApplicationDocumentsDirectory();
setState(() {
_appDocPath = '${dir.path}/my_downloads';
});
}
@override
Widget build(BuildContext context) {
if (_appDocPath == null) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
// Call the plugin!
return Scaffold(
body: DynamicDownloadDashboard(
jsonResponse: jsonDecode(myApiResponse), // Your map
extractKeys: const ['store_image_url', 'adUrl'], // Which fields to download?
customDownloadDir: _appDocPath!, // Where do they go?
// Optional Parameters
initialIsGridView: true,
initialThemeMode: ThemeMode.dark,
)
);
}
}
⚙️ Headless API Methods #
If you do not want to use the included Dashboard UI, you can invoke the static methods globally.
Downloading Headless JSON
dynamic mutatedJson = await DynamicDownloadManager.processResponse(
jsonResponse: myJsonPayload,
extractKeys: ['store_image_url'],
customDownloadDir: '/my/path',
onTaskProgress: (url, progress, expectedBytes) {
debugPrint("\$url is at \$progress");
}
);
debugPrint("Downloads completed! The payload returns with \${key}_local_path attached!");
Issuing a Manual Retry
await DynamicDownloadManager.retryDownload(
url: 'https://badUrl.com',
customDownloadDir: '/my/path',
onTaskProgress: (url, progress, expectedBytes) {},
);