Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev0.2.0

workmanager_web

Implementação experimental da workmanager no web usando um Service Worker e um Web Worker para execução de tarefas em segundo plano.

Web
Downloads em 30 dias
193 mil
Curtidas
1
Pontos Pub
140

Instalar pacote

flutter pub add workmanager_web

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

workmanager_web fornece uma implementação experimental para web do pacote workmanager, permitindo a execução de tarefas em segundo plano em aplicativos Flutter Web usando Service Workers e Web Workers. Ele permite agendar e executar tarefas mesmo quando o app não está ativamente em uso, imitando as capacidades nativas de processamento em segundo plano. Este pacote foi projetado para suportar tarefas periódicas e únicas em ambientes web onde a execução em segundo plano tradicional é limitada.

Casos de uso

  • Agendamento de sincronizações periódicas de dados
  • Executar tarefas em segundo plano após o fechamento do aplicativo
  • Implementando o tratamento de notificação por push
  • Executando operações de longa duração sem bloquear a IU
  • Apoiar aplicativos com foco em offline

Principais recursos

  • Integração do Service Worker
  • Execução de tarefas baseada em Web Worker
  • Agendamento de tarefas periódicas e únicas
  • Compatibilidade experimental com web
  • Sobrecarga mínima de tempo de execução

Indicado para

  • Desenvolvedores Flutter Web que precisam de tarefas em segundo plano
  • Aplicativos que exigem manutenção agendada
  • Aplicações web capazes de funcionar offline
  • Desenvolvedores testando fluxos de trabalho em segundo plano na web

Considerações

  • Estado experimental com possível instabilidade
  • Suporte limitado do navegador para Service Workers
  • Sem tempo de execução garantido em todos os navegadores
  • Requer HTTPS em produção
  • Não adequado para operações críticas sensíveis ao tempo

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

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.

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.

Rankings