简体   繁体   中英

Is there a way to skip a recurring notification using flutter_local_notifications?

I'm using flutter_local_notifications to schedule daily reminder notifications but I want to prevent users from being bothered by the notification if they already accomplished the action that day. In other words, I want to be able to skip a day.

Since there is no way with FlutterLocalNotificationsPlugin to run some code before triggering each recurring notification, I thought I could do the following workaround when needing to skip one day: cancel the recurring notification and reschedule it with a TZDateTime parameter set to the next day . Unfortunately, it doesn't work this way.

The doc clearly says ( source ):

Note that when a value is given, the [scheduledDate] may not represent the first time the notification will be shown. An example would be if the date and time is currently 2020-10-19 11:00 (ie 19th October 2020 11:00AM) and [scheduledDate] is 2020-10-21 10:00 and the value of the [matchDateTimeComponents] is [DateTimeComponents.time], then the next time a notification will appear is 2020-10-20 10:00.

I'm afraid the only solution at this point is to manage my own background tasks using something like workmanager instead of FlutterLocalNotificationsPlugin . Am I right? Any other suggestions?

I encountered the same problem. The solution I'm going with is manually scheduling all the periodic notifications for X time into the future (say one month) with zonedSchedule (not configuring it to repeat).

Next, you can cancel any of the notifications you want with cancel . Then, you just have to make sure to reschedule a month into the future of daily notifications when it gets close to the initial scheduling time. You can use shared preferences to keep track of the limit of the scheduling to check whenever the app is opened for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM