All Projects → fluttercommunity → Flutter_workmanager

fluttercommunity / Flutter_workmanager

Licence: mit
A Flutter plugin which allows you to execute code in the background on Android and iOS.

Programming Languages

kotlin
9241 projects
dart
5743 projects

Projects that are alternatives of or similar to Flutter workmanager

celery.node
Celery task queue client/worker for nodejs
Stars: ✭ 164 (-60.67%)
Mutual labels:  background-jobs, background
Background
Runs things in the background.
Stars: ✭ 497 (+19.18%)
Mutual labels:  background, background-jobs
lovelace-animated-background
Animated backgrounds for lovelace
Stars: ✭ 123 (-70.5%)
Mutual labels:  background
Bagisto
An easy to use, free and open source laravel eCommerce platform to build your online shop in no time.
Stars: ✭ 4,140 (+892.81%)
Mutual labels:  headless
Swiftvideobackground
📹 Framework to Play a Video in the Background of any UIView
Stars: ✭ 303 (-27.34%)
Mutual labels:  background
Uieffect
UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
Stars: ✭ 3,449 (+727.1%)
Mutual labels:  background
Jobrunr
An extremely easy way to perform background processing in Java. Backed by persistent storage. Open and free for commercial use.
Stars: ✭ 331 (-20.62%)
Mutual labels:  background-jobs
awesome-storyblok
A curated list of awesome things related to Storyblok CMS. 😏
Stars: ✭ 53 (-87.29%)
Mutual labels:  headless
Flutter background geolocation
Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
Stars: ✭ 384 (-7.91%)
Mutual labels:  background
Onedrawable
✏️ Use only one image to set a background with a click effect for the View
Stars: ✭ 298 (-28.54%)
Mutual labels:  background
Android Hidden Camera
This library is to take picture using camera without camera preview.
Stars: ✭ 339 (-18.71%)
Mutual labels:  background
React Storefront
React Storefront - PWA for eCommerce. 100% offline, platform agnostic, headless, Magento 2 supported. Always Open Source, Apache-2.0 license. Join us as contributor ([email protected]).
Stars: ✭ 292 (-29.98%)
Mutual labels:  headless
Playwright Go
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Stars: ✭ 272 (-34.77%)
Mutual labels:  headless
Vue Lazy Image Loading
Vue lazy image and background loading plugin.
Stars: ✭ 335 (-19.66%)
Mutual labels:  background
Shrine
File Attachment toolkit for Ruby applications
Stars: ✭ 2,903 (+596.16%)
Mutual labels:  background-jobs
Marionette
🧸 Swift library which provides a high-level API to control a WKWebView
Stars: ✭ 374 (-10.31%)
Mutual labels:  headless
ex job
ExJob is a zero-dependency, ultra-fast, background job processing library.
Stars: ✭ 14 (-96.64%)
Mutual labels:  background-jobs
React Storefront
Build and deploy e-commerce progressive web apps (PWAs) in record time.
Stars: ✭ 275 (-34.05%)
Mutual labels:  headless
Mix.core
🚀 Mixcore CMS is an open source CMS that support both headless and decoupled to easily build any kinds of app/web app/customisable APIs built on top of ASP.NET Core / Dotnet Core. It is a completely open source ASP.NET Core (Dotnet Core) CMS solution. https://mixcore.org
Stars: ✭ 304 (-27.1%)
Mutual labels:  headless
Ycdownloadsession
iOS background download video or file lib
Stars: ✭ 410 (-1.68%)
Mutual labels:  background

Flutter Workmanager

pub package Build status

Flutter WorkManager is a wrapper around Android's WorkManager and iOS' performFetchWithCompletionHandler, effectively enabling headless execution of Dart code in the background.

This is especially useful to run periodic tasks, such as fetching remote data on a regular basis.

This plugin was featured in this Medium blogpost

Installation

dependencies:
  workmanager: ^0.2.0
flutter pub get
import 'package:workmanager/workmanager.dart';

Platform Setup

In order for background work to be scheduled correctly you should follow the Android and iOS setup first.

How to use the package?

See sample folder for a complete working example.
Before registering any task, the WorkManager plugin must be initialized.

void callbackDispatcher() {
  Workmanager.executeTask((task, inputData) {
    print("Native called background task: $backgroundTask"); //simpleTask will be emitted here.
    return Future.value(true);
  });
}

void main() {
  Workmanager.initialize(
    callbackDispatcher, // The top level function, aka callbackDispatcher
    isInDebugMode: true // If enabled it will post a notification whenever the task is running. Handy for debugging tasks
  );
  Workmanager.registerOneOffTask("1", "simpleTask"); //Android only (see below)
  runApp(MyApp());
}

The callbackDispatcher needs to be either a static function or a top level function to be accessible as a Flutter entry point.


Customisation (Android only!)

Not every Android WorkManager feature is ported.

Two kinds of background tasks can be registered :

  • One off task : runs only once
  • Periodic tasks : runs indefinitely on a regular basis
// One off task registration
Workmanager.registerOneOffTask(
    "1", 
    "simpleTask"
);

// Periodic task registration
Workmanager.registerPeriodicTask(
    "2", 
    "simplePeriodicTask", \
    // When no frequency is provided the default 15 minutes is set.
    // Minimum frequency is 15 min. Android will automatically change your frequency to 15 min if you have configured a lower frequency.
    frequency: Duration(hours: 1),
)

Each task must have an unique name;
This allows cancellation of a started task.
The second parameter is the String that will be send to your callbackDispatcher function, indicating the task's type.

Tagging

You can set the optional tag property.
Handy for cancellation by tag.
This is different from the unique name in that you can group multiple tasks under one tag.

Workmanager.registerOneOffTask("1", "simpleTask", tag: "tag");

Existing Work Policy

Indicates the desired behaviour when the same task is scheduled more than once.
The default is KEEP

Workmanager.registerOneOffTask("1", "simpleTask", existingWorkPolicy: ExistingWorkPolicy.append);

Initial Delay

Indicates how along a task should waitbefore its first run.

Workmanager.registerOneOffTask("1", "simpleTask", initialDelay: Duration(seconds: 10));

Constraints

Not all constraints are mapped.

Workmanager.registerOneOffTask(
    "1", 
    "simpleTask", 
    constraints: Constraints(
        networkType: NetworkType.connected,
        requiresBatteryNotLow: true,
        requiresCharging: true,
        requiresDeviceIdle: true,
        requiresStorageNotLow: true
    )
);

InputData

Add some input data for your task. Valid value types are: int, bool, double, String and their list

 Workmanager.registerOneOffTask(
    "1",
    "simpleTask", 
    inputData: {
    'int': 1,
    'bool': true,
    'double': 1.0,
    'string': 'string',
    'array': [1, 2, 3],
    },
);

BackoffPolicy

Indicates the waiting strategy upon task failure.
The default is BackoffPolicy.exponential.
You can also specify the delay.

Workmanager.registerOneOffTask("1", "simpleTask", backoffPolicy: BackoffPolicy.exponential, backoffPolicyDelay: Duration(seconds: 10));

Cancellation

A task can be cancelled in different ways :

By Tag

Cancels the task that was previously registered using this Tag, if any.

Workmanager.cancelByTag("tag");

By Unique Name

Workmanager.cancelByUniqueName("<MyTask>");

All

Workmanager.cancelAll();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].