How to schedule background tasks in Flutter?

坚强是说给别人听的谎言 提交于 2019-11-28 23:23:00

What you want to do, i.e. cross-platform scheduling, is not a Flutter limitation. It is an iOS limitation. See this SO post which is referenced in this GitHub comment.

There is a Medium blogpost that explains how to do this.
However we thought it was way too complicated to set up so it just happens we created a plugin that aids you with this.

//Provide a top level function or static function.
//This function will be called by Android and will return the value you provided when you registered the task.
//See below
void callbackDispatcher() {
  Workmanager.executeTask((task) {
    print("Native echoed: $task");
    return Future.value(true);
  });
}

Workmanager.initialize(
    callbackDispatcher, //the top level function.
    isInDebugMode: true //If enabled it will post a notification whenever the job is running. Handy for debugging jobs
)

We support Android's Workmanager and iOS performFetch


For now it only works for Android project, but we are looking at iOS soon.
I'll update this answer when it is available.


We have iOS support now too. It is still early alpha, but give a go.
We wrote a complimentary Medium post too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!