native_workmanager library

Native background task manager for Flutter.

Zero Flutter Engine overhead. Built on Kotlin Multiplatform.

Quick Start

import 'package:native_workmanager/native_workmanager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await NativeWorkManager.initialize();
  runApp(MyApp());
}

// Schedule a periodic sync
await NativeWorkManager.enqueue(
  taskId: 'sync',
  trigger: TaskTrigger.periodic(Duration(hours: 1)),
  worker: NativeWorker.httpSync(url: 'https://api.example.com/sync'),
  constraints: Constraints.networkRequired,
);

Features

  • Native Workers: Run background tasks without Flutter Engine (~2MB vs ~50MB RAM)
  • Task Chains: Complex workflows (A → B → C)
  • Auto iOS Config: Reads Info.plist automatically
  • Built-in Workers: HTTP (request, upload, download, sync), Files (compress, decompress), Image processing, Cryptography (hash, encrypt, decrypt)

See NativeWorkManager for full documentation.

Classes

BatteryLowTrigger
Execute when battery IS low (Android only).
BatteryOkayTrigger
Execute when battery is NOT low (Android only).
Constraints
Constraints that must be met before a task can run.
ContentUriTrigger
Execute when a content URI changes (Android only).
CryptoDecryptWorker
Crypto worker configuration for file decryption.
CryptoEncryptWorker
Crypto worker configuration for file encryption.
CryptoHashWorker
Crypto worker configuration for file hashing.
CustomNativeWorker
Custom native worker configuration.
DartWorker
Dart callback worker for custom logic (requires Flutter Engine).
DartWorkerInternal
Internal DartWorker with callback handle.
DeviceIdleTrigger
Execute when device is idle (Android only).
ExactTrigger
Execute at an exact time.
FileCompressionWorker
File compression worker configuration.
FileDecompressionWorker
File decompression worker configuration.
FileSystemCopyWorker
File system worker configuration for copy operation.
FileSystemDeleteWorker
File system worker configuration for delete operation.
FileSystemListWorker
File system worker configuration for list operation.
FileSystemMkdirWorker
File system worker configuration for mkdir operation.
FileSystemMoveWorker
File system worker configuration for move operation.
HttpDownloadWorker
HTTP download worker configuration.
HttpRequestWorker
HTTP request worker configuration.
HttpSyncWorker
HTTP sync worker configuration.
HttpUploadWorker
HTTP upload worker configuration.
ImageProcessWorker
Image processing worker configuration.
NativeWorker
Built-in native workers that run WITHOUT Flutter Engine.
NativeWorkManager
OneTimeTrigger
Execute once after an optional delay.
PerformanceEvent
A performance event record.
PerformanceMonitor
Performance monitoring utilities for native_workmanager.
PerformanceStatistics
Performance statistics summary.
PeriodicTrigger
Execute periodically at a fixed interval.
StorageLowTrigger
Execute when storage is low (Android only).
TaskChainBuilder
Builder for creating task chains (A -> B -> C workflows).
TaskEvent
Event emitted when a task completes (success or failure).
TaskMetrics
Metrics for a single task execution.
TaskProgress
Progress update during task execution.
TaskRequest
A single task request in a chain.
TaskTrigger
Defines when a task should be executed.
WindowedTrigger
Execute within a time window.
Worker
Base class for all worker configurations.
WorkerTypeStatistics
Statistics for a specific worker type.

Enums

BackoffPolicy
Backoff policy for retry behavior when task fails.
BGTaskType
iOS background task type selection (iOS 13.0+ only).
CompressionLevel
Compression levels for file compression.
EncryptionAlgorithm
Encryption algorithms supported by CryptoWorker.
ExactAlarmIOSBehavior
iOS-specific behavior for exact time alarms.
ExistingTaskPolicy
Policy for handling existing tasks with the same ID.
FileOperation
File system operations.
ForegroundServiceType
Android 14+ foreground service type for heavy tasks.
HashAlgorithm
Hash algorithms supported by CryptoWorker.
HttpMethod
HTTP methods for network workers.
ImageFormat
Image output formats.
PerformanceEventType
Performance event types.
QoS
Quality of Service (QoS) priority for task execution.
ScheduleResult
Result of scheduling a task.
SystemConstraint
System-level constraints for task execution (Android only).
TaskStatus
Current status of a task.

Typedefs

DartWorkerCallback = Future<bool> Function(Map<String, dynamic>? input)
Callback type for Dart workers.