R3HP
R3HP

Reputation: 510

Flutter - is there a way to execute a method periodically even when app is not open

I have a personal expenses app in which I have a Week model which holds user expanses over week and at the end of the week uploads it in cloud. My problem is that how can I implement a situation in which Week model is created at first day of week(eg.saturday) periodically even if the app is not running??? Is that even possible?? I searched a little and saw

timer.periodic(duration,callback);

but I don't think that would work in background

Upvotes: 0

Views: 1742

Answers (2)

Furkan Abbasioğlu
Furkan Abbasioğlu

Reputation: 218

You can use background_fetch plugin. But this plugin's lack of it is that works stable on just Android. You need to read the official document.

Upvotes: 1

Muhammad Hasan Alasady
Muhammad Hasan Alasady

Reputation: 130

Maybe this will help you:

  1. Firstly

You have to use Timer from dart:async to run periodically method, and put the duration for 7 days.

  Timer.periodic(
    Duration(days: 7),
    (timer){
      // Create new week model in database.
    }
  );
  1. Secondly

Use workmanager to run the previous code in the background, it will executed weekly.

Upvotes: 1

Related Questions