Native background task manager for Flutter with zero Flutter Engine overhead.
Flutter background task manager with native workers and task chains.
- Zero Flutter Engine Overhead: Native workers execute I/O tasks without loading the Flutter Engine
- Task Chains: Automate multi-step workflows (Download β Process β Upload) with built-in dependency management
- 11 Built-in Workers: HTTP, File operations, Compression, Crypto, Image processing
- Hybrid Architecture: Choose native workers for I/O or Dart workers for complex logic
- Production Ready: 808 passing tests, comprehensive documentation, iOS 12.0+ and Android API 21+ support
Step 1: Install
flutter pub add native_workmanagerStep 2: Initialize
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await NativeWorkManager.initialize();
runApp(MyApp());
}Step 3: Schedule a Task
Option A: Simple HTTP Sync (Native Worker)
// Starts hourly API sync without Flutter Engine overhead
await NativeWorkManager.enqueue(
taskId: 'sync',
trigger: TaskTrigger.periodic(Duration(hours: 1)),
worker: NativeWorker.httpSync( // β Native worker
url: 'https://api.example.com/sync',
method: HttpMethod.post,
),
);
// β Task runs every hour, even when app is closed
// β No Flutter Engine overheadOption B: Complex Dart Logic (Dart Worker)
// For tasks requiring custom Dart code or packages
await NativeWorkManager.enqueue(
taskId: 'process',
trigger: TaskTrigger.oneTime(),
worker: DartWorker(callbackId: 'complexLogic'), // β Dart worker
);
// β Access to all Dart packages
// β Full Flutter/Dart ecosystem supportTasks are registered with the OS and survive app restarts, phone reboots, and force-quits.
Complete getting started guide β
Good news: ~90% API compatibility, most code stays the same!
- Replace
Workmanager.registerPeriodicTaskwithNativeWorkManager.enqueue - Update task trigger syntax (same logic, different API)
- Replace callback with
DartWorker(callbackId)or use native workers - Test on both iOS and Android (should work immediately!)
Before (workmanager):
Workmanager.registerPeriodicTask(
'myTask',
'api_sync',
frequency: Duration(hours: 1),
);After (native_workmanager):
// Upgrade to native worker
NativeWorkManager.enqueue(
taskId: 'myTask',
trigger: TaskTrigger.periodic(Duration(hours: 1)),
worker: NativeWorker.httpSync( // β Native HTTP worker
url: 'https://api.example.com/sync',
),
);Result: Same functionality, zero Flutter Engine overhead for I/O tasks.
Full migration guide β | Migration tool β
β Use Native Workers (zero Flutter Engine overhead)
- No Flutter Engine overhead
- Minimal battery impact
- See example β
β Use HttpUploadWorker with Task Chains
- Built-in retry logic
- Progress tracking
- Automatic cleanup
- See example β
β Use Task Chains (Download β Compress β Upload)
- Sequential or parallel execution
- Automatic dependency management
- Failure isolation
- See example β
β Use DartWorker with autoDispose
- Full Flutter Engine access
- All Dart packages available
- Smart memory management
- See example β
1. Native Workers
- Execute I/O tasks without spawning Flutter Engine
- 11 Built-in Workers: HTTP (request, upload, download, sync), Files (compress, decompress, copy, move, delete), Image processing, Crypto (hash, encrypt, decrypt)
- Extensible with custom Kotlin/Swift workers
2. Task Chains
- Automate multi-step workflows: A β B β C or A β [B1, B2, B3] β D
- Built-in dependency management
- Automatic retry and failure handling
- Data passing between steps
3. Hybrid Execution Model
- Choose per-task: Native workers (I/O) or Dart workers (complex logic)
autoDisposeflag for fine-grained engine lifecycle control- Best of both worlds
4. Cross-Platform Consistency
- Unified API across Android and iOS
- Platform feature parity
- Built on kmpworkmanager for reliability
| Platform | Status | Min Version | Key Limitation |
|---|---|---|---|
| Android | β Supported | API 21 (5.0+) | Doze mode may defer tasks |
| iOS | β Supported | iOS 12.0+ | 30-second execution limit |
Background tasks on iOS must complete in 30 seconds. For longer tasks:
Solutions:
- β Use task chains - Split work into 30-second chunks
- β Use native workers - Faster than Dart workers (no engine overhead)
- β Use Background URLSession - For large file transfers (no time limit)
β οΈ Consider foreground services for truly long tasks
Example:
// β Won't work: Takes 90 seconds
await downloadLargeFile(); // 60sec
await processFile(); // 30sec
// β
Works: Split into chain (each <30sec)
await NativeWorkManager.beginWith(
TaskRequest(id: 'download', worker: HttpDownloadWorker(...)), // 20sec
).then(
TaskRequest(id: 'process', worker: ImageProcessWorker(...)), // 15sec
).enqueue();Read iOS background task guide β
Android 6+ may defer tasks in Doze mode. Use constraints to ensure execution:
await NativeWorkManager.enqueue(
taskId: 'important-sync',
trigger: TaskTrigger.periodic(Duration(hours: 1)),
worker: NativeWorker.httpSync(url: 'https://api.example.com/sync'),
constraints: Constraints(
requiresNetwork: true, // Wait for network
requiresCharging: true, // Wait for charging (optional)
requiresBatteryNotLow: true, // Skip if battery low
),
);Read Android optimization guide β
- Quick Start (3 min) - Get running fast
- API Reference - Complete API docs
- FAQ - Common questions answered
- Real-World Use Cases (8 examples)
- Security Policy - Report vulnerabilities, best practices
- Production Deployment - Launch with confidence
- Platform Consistency - iOS vs Android differences
- Custom Native Workers - Write Kotlin/Swift workers
- Task Chains & Workflows - Complex automations
- iOS Background Limits - 30-second workarounds
Q: Will my task run if the app is force-closed? A: Yes! Tasks are registered with the OS (Android WorkManager / iOS BGTaskScheduler), not your Flutter app.
Q: How much memory does a task actually use? A: Native workers execute without Flutter Engine overhead. Dart workers require the full Flutter runtime. Actual memory usage depends on worker type and task complexity.
Q: Can I chain 100 tasks together? A: Yes, but on iOS each task in the chain must complete within 30 seconds. Use native workers for speed.
Q: What happens if a task in a chain fails? A: The chain stops. Subsequent tasks are cancelled. You can use retry policies to handle failures.
Q: Is this compatible with workmanager? A: ~90% compatible. Most code works with minor syntax changes. See migration guide.
Q: Can I use this for location tracking?
A: Background tasks are for periodic work, not continuous tracking. For location, use geolocator with background modes.
- Dio - HTTP client for complex requests
- Hive - Local database sync
- Firebase - Analytics & Crashlytics
- Sentry - Error tracking in background tasks
- Security: No critical vulnerabilities
- Tests: 808 unit tests passing
- Coverage: All 11 native workers tested
- Platforms: iOS 12.0+ and Android API 21+
- π¬ GitHub Discussions - Ask questions, share use cases
- π Issue Tracker - Report bugs
- π§ Email: support@brewkits.dev
- Search existing issues
- Create new issue with:
- Flutter version (
flutter --version) - Platform (iOS/Android)
- Minimal reproducible example
- Flutter version (
We welcome contributions! See CONTRIBUTING.md for:
- How to report bugs
- How to request features
- How to submit pull requests
- Coding standards
Built with β€οΈ using platform-native APIs:
- Android: WorkManager - Google's official background task library
- iOS: BGTaskScheduler - Apple's background task framework
- Shared Core: kmpworkmanager - Cross-platform worker orchestration
Inspired by Android WorkManager and iOS BackgroundTasks best practices.
Need help?
- π Website: brewkits.dev
- π Issues: GitHub Issues
- π§ Email: datacenter111@gmail.com
Links:
- π¦ pub.dev Package
- π Documentation
- π» GitHub Repository
Licensed under the MIT License - see LICENSE file for details.
Author: Nguyα» n TuαΊ₯n Viα»t β’ BrewKits
β If this library helps your Flutter app, please star the repo!