How to schedule background tasks in Flutter?

前端 未结 2 1526
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 04:23

I have been looking a lot for this but haven\'t found any packages or a way to schedule background tasks in Flutter. Like in Android there is WorkManager,

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 04:36

    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.

提交回复
热议问题