如果我是你,我会使用颤振 cron 包:pub.dev 上的 cron 包
它允许你安排一个 cron 作业,这只是一个每隔 x 秒或天、月运行一次的任务......例如:
fltrNotification = new FlutterLocalNotificationsPlugin();
final cron = Cron();
// Schedule a task that will run every 3 days
cron.schedule(Schedule.parse('0 0 */3 * *'), () async {
// Schedule a notification right now
fltrNotification.schedule(1, "Times Uppp", task,
DateTime.now(), generalNotificationDetails);
print('every three days');
});
If you want to change the frequency, cron is very flexible and you can do pretty much any frequency, the cron syntax is pretty straightforward and their are some websites online that allow you to simply generate it.
当然,有几种方法可以使用 cron 来做你想做的事。您可以在接下来的 72 小时内每 72 小时安排一次通知,每 24 小时刷新一次,无论您觉得更好。
(顺便说一下,我在这个例子中使用了 Piyush Kumar 的部分答案,并将其更新为使用 cron)