Search packages, repositories and app categories

Package detailsv0.10.5

workmanager_platform_interface

A common platform interface for the workmanager plugin.

AndroidiOSLinuxmacOSWebWindows
30-day downloads
281K
Likes
0
Pub points
150

Install package

flutter pub add workmanager_platform_interface

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A shared platform interface for the workmanager plugin, enabling consistent background task execution across Android, iOS, Linux, macOS, Web, and Windows. It abstracts platform-specific implementations, allowing developers to write cross-platform code that schedules and manages background work reliably. The interface ensures compatibility and simplifies integration with native platforms through a unified API. This package is foundational for the workmanager ecosystem, supporting features like periodic tasks and one-time jobs.

Use cases

  • Scheduling background tasks on multiple platforms
  • Running periodic jobs in the background
  • Executing one-time background operations
  • Ensuring cross-platform consistency
  • Supporting long-running background processes

Key features

  • Unified API across platforms
  • Platform abstraction layer
  • Support for Android, iOS, Linux, macOS, Web, and Windows
  • Enables background task scheduling
  • Facilitates plugin extensibility

Suitable for

  • Developers building cross-platform apps with background tasks
  • Teams requiring consistent background job management
  • Projects using the workmanager plugin ecosystem
  • Apps needing reliable periodic or one-time background execution

Considerations

  • Requires implementation by platform-specific plugins
  • Not usable standalone without concrete platform implementations
  • Depends on the main workmanager package for functionality
  • May require additional permissions on certain platforms

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Flutter Workmanager

pub package pub points likes popularity GitHub Workflow Status license

Execute Dart code in the background, even when your app is closed (Android and iOS). On macOS, background tasks run while the app is running or backgrounded and the Mac is awake. Perfect for data sync, file uploads, and periodic maintenance tasks.

⚠️ Experimental web support now exists via workmanager_web (Service Worker + Web Worker based background execution). See the Web (experimental) page and the package README for honest limitations and how to test it in Chrome.

📖 Documentation

Get started with background tasks in Flutter:

→ Quick Start Guide - Installation and setup

→ API Documentation - Complete Dart API reference

→ Debugging Guide - Troubleshooting help

→ Troubleshooting Guide - Why tasks stop after app close (OEM battery optimization, constraints, verification)

🎯 Use Cases

Background tasks are perfect for:

  • Sync data from API - Keep your app's data fresh
  • Upload files in background - Reliable file uploads
  • Clean up old data - Remove old files and cache
  • Fetch notifications - Check for new messages
  • Database maintenance - Optimize and clean databases

⏱ Long-Running Tasks (Android)

For work that takes longer than the regular background execution window (bulk uploads/downloads, ML processing), Android tasks can run as a foreground service with a persistent notification. Pass a foregroundServiceConfig to registerOneOffTask or registerPeriodicTask:

await Workmanager().registerOneOffTask(
  "upload-task",
  "upload_files",
  foregroundServiceConfig: ForegroundServiceConfig(
    notificationTitle: "Uploading files",
    notificationText: "Your files are being uploaded",
  ),
);

See the Quick Start guide for details and platform caveats.

🛑 Cancelling Running Work (Android)

cancelByUniqueName, cancelByTag and cancelAll stop the WorkManager worker immediately, but the Dart callback that is currently running keeps executing unless it reacts to the stop. Pass an onTaskStopped handler to executeTask inside your callbackDispatcher to be notified when a running task is stopped before it finishes:

@pragma('vm:entry-point')
void callbackDispatcher() {
  Workmanager().executeTask(
    (taskName, inputData) async {
      return true;
    },
    onTaskStopped: (taskName, stopReason) async {
      // Mark the task as cancelled / persist state, then return promptly.
    },
  );
}

The handler receives the task name and the WorkManager stop reason (cancelledByApp, timeout, preempt, ...); on Android < 12 the reason is StopReason.unknown. Android-only — iOS has no way to stop a running task. See the Customization guide for details.

🐛 Issues & Support

🚀 Example App

See the example folder for a complete working demo with all task types and platform configurations.

Categories

Dependencies

Dependency list 2 items

  • meta^1.10.0
  • plugin_platform_interface^2.1.0

Source repository

Projects using this package

No data available yet.

Rankings