Flutter Workmanager Example
Complete working demo showing all Flutter Workmanager features and task types.
Features Demonstrated
- One-off tasks: Immediate background execution
- Periodic tasks: Scheduled recurring background work
- Processing tasks: Long-running iOS background tasks
- Task constraints: Network, battery, and device state requirements
- Debug notifications: Visual feedback when tasks execute
- Error handling: Proper task success/failure/retry logic
- Platform differences: Android vs iOS background execution
Quick Start
-
Clone and run:
git clone https://github.com/fluttercommunity/flutter_workmanager.git cd flutter_workmanager/example flutter run -
Platform setup:
- Android: Works immediately ✅
- iOS: Follow the iOS setup in
ios/Runner/AppDelegate.swiftandios/Runner/Info.plist
-
Test background tasks:
- Tap buttons to schedule different task types
- Put app in background to see tasks execute
- Check debug notifications to verify execution
Example Tasks
The demo includes practical examples:
- Simulated API sync: Fetches data and stores locally
- File cleanup: Removes old cached files
- Periodic maintenance: Regular app maintenance tasks
- Long processing: iOS-specific long-running tasks
Key Files
lib/main.dart- Main app with task scheduling UIlib/callback_dispatcher.dart- Background task execution logicios/Runner/AppDelegate.swift- iOS background task registrationios/Runner/Info.plist- iOS background modes configuration
Testing Background Tasks
Android:
- Tasks run reliably in background
- Enable debug mode to see notifications
- Use
adb shell dumpsys jobschedulerto inspect scheduled tasks
iOS:
- Test on physical device (not simulator)
- Enable Background App Refresh in Settings
- Use Xcode debugger commands to trigger tasks immediately
Documentation
For detailed guides and real-world use cases, visit: docs.page/fluttercommunity/flutter_workmanager →