搜索插件、代码仓与 APP 分类

插件详情v0.10.5

workmanager_platform_interface

工作管理器插件的通用平台接口。

AndroidiOSLinuxmacOSWebWindows
近 30 天下载
28.1万
喜欢数
0
Pub 分数
150

安装插件

flutter pub add workmanager_platform_interface

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于 workmanager 插件的共享平台接口,可在 Android、iOS、Linux、macOS、Web 和 Windows 上实现一致的后台任务执行。它抽象了平台特定的实现,使开发者能够编写可靠的跨平台代码,以调度和管理后台工作。该接口确保了兼容性,并通过统一的 API 简化了与原生平台的集成。此包是 workmanager 生态系统的基础,支持周期性任务和一次性作业等功能。

适合场景

  • 在多个平台上调度后台任务
  • 在后台运行周期性任务
  • 执行一次性后台操作
  • 确保跨平台一致性
  • 支持长时间运行的后台进程

主要特点

  • 跨平台统一 API
  • 平台抽象层
  • 支持 Android、iOS、Linux、macOS、Web 和 Windows
  • 启用后台任务调度
  • 促进插件可扩展性

适合对象

  • 使用后台任务开发跨平台应用的开发者
  • 需要一致的后台作业管理的团队
  • 使用 workmanager 插件生态系统的项目
  • 需要可靠周期性或一次性后台执行的应用程序

使用建议

  • 需要由平台特定的插件实现
  • 没有具体的平台实现,无法独立使用
  • 依赖主 workmanager 包以实现功能
  • 在某些平台上可能需要额外的权限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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.

所属分类

依赖

依赖清单 2 项

  • meta^1.10.0
  • plugin_platform_interface^2.1.0

源码仓库

使用此插件的项目

暂无相关数据。

所在榜单