| title | Quick Start |
|---|---|
| description | Get started with Flutter Workmanager in minutes |
Add workmanager to your pubspec.yaml:
dependencies:
workmanager: ^0.8.0Then run:
flutter pub getAndroid works automatically - no additional setup required! ✅
**iOS Minimum Deployment Target:** iOS 14.0 or later is required. Update your project's deployment target in Xcode: 1. Open `ios/Runner.xcodeproj` in Xcode 2. Select the Runner target 3. Set "Minimum Deployments" to iOS 14.0 or later 4. Or edit `ios/Runner.xcodeproj/project.pbxproj` and set `IPHONEOS_DEPLOYMENT_TARGET = 14.0;`iOS requires a 5-minute setup in Xcode. Choose your approach based on your needs:
For regular data sync, notifications, cleanup - uses iOS Background Fetch:
- Enable Background Modes in Xcode target capabilities (Configuration Guide) and add to Info.plist (UIBackgroundModes reference):
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>- No AppDelegate configuration needed - works automatically from Dart code
For file uploads, data processing, longer tasks - uses BGTaskScheduler:
- Enable Background Modes in Xcode target capabilities (Configuration Guide) and add to Info.plist (UIBackgroundModes reference):
<key>UIBackgroundModes</key>
<array>
<string>processing</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.yourapp.processing_task</string>
</array>- Configure AppDelegate.swift (required for BGTaskScheduler):
import workmanager_apple
// In application didFinishLaunching
WorkmanagerPlugin.registerBGProcessingTask(
withIdentifier: "com.yourapp.processing_task"
)For periodic tasks with more control than Background Fetch - uses BGTaskScheduler with frequency:
- Enable Background Modes in Xcode target capabilities (Configuration Guide) and add to Info.plist (UIBackgroundModes reference):
<key>UIBackgroundModes</key>
<array>
<string>processing</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.yourapp.periodic_task</string>
</array>- Configure AppDelegate.swift (with frequency control):
import workmanager_apple
// In application didFinishLaunching
WorkmanagerPlugin.registerPeriodicTask(
withIdentifier: "com.yourapp.periodic_task",
frequency: NSNumber(value: 20 * 60) // 20 minutes (15 min minimum)
)@pragma('vm:entry-point')
void callbackDispatcher() {
Workmanager().executeTask((task, inputData) async {
switch (task) {
case "data_sync":
await syncDataWithServer();
break;
case "cleanup":
await cleanupOldFiles();
break;
case Workmanager.iOSBackgroundTask:
// iOS Background Fetch task
await handleBackgroundFetch();
break;
default:
// Handle unknown task types
break;
}
return Future.value(true);
});
}import 'package:flutter/foundation.dart';
void main() {
Workmanager().initialize(callbackDispatcher);
runApp(MyApp());
}// Schedule a one-time task
Workmanager().registerOneOffTask(
"sync-task",
"data_sync",
initialDelay: Duration(seconds: 10),
);
// Schedule a periodic task
Workmanager().registerPeriodicTask(
"cleanup-task",
"cleanup",
frequency: Duration(hours: 24),
);
// Schedule a periodic task with input data
Workmanager().registerPeriodicTask(
"sync-task",
"data_sync",
frequency: Duration(hours: 6),
inputData: <String, dynamic>{
'server_url': 'https://api.example.com',
'sync_type': 'full',
'max_retries': 3,
},
);
## Task Results
Your background tasks can return:
- `Future.value(true)` - ✅ Task successful
- `Future.value(false)` - 🔄 Task should be retried
- `Future.error(...)` - ❌ Task failed
## Key Points
- **Callback Dispatcher**: Must be a top-level function (not inside a class)
- **Separate Isolate**: Background tasks run in isolation - initialize dependencies inside the task
- **Platform Differences**:
- Android: Reliable background execution, 15-minute minimum frequency
- iOS: 30-second limit, execution depends on user patterns and device state
## Next Steps
- **[Task Customization](customization)** - Advanced configuration with constraints, input data, and management
- **[Debugging Guide](debugging)** - Learn how to debug and troubleshoot background tasks
- **[Example App](https://github.com/fluttercommunity/flutter_workmanager/tree/main/example)** - Complete working demo