Flutter Workmanager

⚠️ Experimental web support is available through the new workmanager_web package (Service Worker + Web Worker based background execution). It maps periodic tasks to Periodic Background Sync and executes the compiled Dart callback inside the Service Worker when the page is closed — with honest limitations (no exact scheduling, Chromium + installed PWA required, Flutter-free dispatcher). See workmanager_web/README.md.

⚠️ Experimental Linux support is available through the new workmanager_linux package (systemd user units: systemd-run transient units for one-off tasks, .timer/.service unit pairs for periodic tasks, with Persistent=true catch-up). Tasks launch the app in headless --background-task mode. Requires a systemd user session; constraints, backoff and tags are not supported yet. See workmanager_linux/README.md.

pub package pub points likes popularity GitHub Workflow Status license

Execute Dart code in the background, even when your app is closed. A Flutter wrapper around Android's WorkManager, iOS Background Tasks, and macOS NSBackgroundActivityScheduler (tasks run while the app is running/backgrounded; not after quit).

📖 Documentation

Complete documentation is available at docs.page →

🚀 Quick Example

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask((task, inputData) async {
    print("Background task: $task");
    // Your background work here
    return Future.value(true);
  });
}

void main() {
  Workmanager().initialize(callbackDispatcher);
  Workmanager().registerOneOffTask("task-id", "simpleTask");
  runApp(MyApp());
}

🎯 Use Cases

Perfect for:

  • Data sync - Keep your app's data fresh
  • File uploads - Reliable uploads in background
  • Cleanup tasks - Remove old files and cache
  • Notifications - Check for new messages
  • Database maintenance - Optimize and clean databases

🏗️ Federated Architecture

This plugin uses a federated architecture with platform-specific implementations:

  • workmanager: Main package providing the unified API
  • workmanager_android: Android implementation using WorkManager
  • workmanager_apple: iOS implementation using BGTaskScheduler + macOS implementation using NSBackgroundActivityScheduler
  • workmanager_web: Web implementation using Service Worker + Web Worker (experimental)
  • workmanager_linux: Linux implementation using systemd user units (experimental)

🐛 Support & Issues

📱 Example App

See the example folder for a complete working demo with all features.


For detailed setup instructions, advanced configuration, and troubleshooting, visit the complete documentation.

Libraries

workmanager