workmanager_web는 workmanager 패키지에 대한 실험적인 웹 구현을 제공하여 서비스 워커와 웹 워커를 사용하여 Flutter 웹 앱에서 백그라운드 작업을 실행할 수 있게 해줍니다. 앱이 활성적으로 사용 중이 아닐 때도 작업을 스케줄링하고 실행할 수 있으며, 네이티브 백그라운드 처리 기능을 모방합니다. 이 패키지는 전통적인 백그라운드 실행이 제한된 웹 환경에서 주기적 및 단일 작업을 지원하도록 설계되었습니다.
사용 사례
정기적인 데이터 동기화 스케줄링
앱 종료 후 백그라운드 작업 실행
푸시 알림 처리 구현
UI를 차단하지 않고 긴 실행 시간 작업을 수행하는 것
오프라인 우선 애플리케이션 지원
주요 기능
서비스 워커 통합
웹 워커 기반 작업 실행
주기적 및 단일 작업 스케줄링
실험적 웹 호환성
최소의 런타임 오버헤드
적합한 대상
백그라운드 작업이 필요한 플러터 웹 개발자
예약된 유지보수를 필요로 하는 앱
오프라인 사용이 가능한 웹 애플리케이션
개발자가 웹에서 백그라운드 워크플로를 테스트하는 중
고려 사항
실험적 상태이며, 불안정할 수 있음
서비스 워커에 대한 브라우저 지원 제한
모든 브라우저에서 실행 시간이 보장되지 않습니다
생산 환경에서 HTTPS가 필요합니다
중요한 시간 민감한 작업에 적합하지 않습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Flutter Workmanager
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.
→ 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:
awaitWorkmanager().registerOneOffTask(
"upload-task",
"upload_files",
foregroundServiceConfig: ForegroundServiceConfig(
notificationTitle: "Uploading files",
notificationText: "Your files are being uploaded",
),
);
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')
voidcallbackDispatcher() {
Workmanager().executeTask(
(taskName, inputData) async {
returntrue;
},
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.