How to schedule irregular local notifications (even if after the app gets killed)

  Kiến thức lập trình

so am building an app that sends about 5 local notifications to the user, at an irregular interval (the timings are internally calculated).

First i tried using Scheduled notifications from the package flutter_local_notification and it works quite smoothly, but from what i found there is no direct way that allows me to schedule all 5 notifications at once on the same channel or maybe like trigger a method when the notification is showed so i can reschedule the next notification.

Then i decided to try and use the WorkManager package and mix it with normal notifications from the flutter_local_notification package so i can call a logic that triggers the next notification time and so on, but am facing couple of problems, first the notification that i schedule using workmanager arent so consistent when i close the app, some times they work as intended, and other times it takes much longer than what it was scheduled, or simply only show when i reopen the app, which can be a bit problematic since i need the notifications to pop up on time.

ideally i would love to find a way to only use the flutter_local_notification package because it works quite smoothly and as intended, but it doesnt seem possible for now.

i think i found a somewhat decent solution, suggested by u/autognome in this post Schedule irregular Notifications combining scheduled notifications by the flutter_local_notification and background_fetch that uses headless function implementation that basically will awaken my app in the background about every 15 minutes, providing a short period of background running-time. which will execute the provided callback fun to reschedule the next notification.

finally if you have dealt with irregularly scheduled local notifications or just have a better solution or advice or would like to point our a mistake that i mentioned please go ahead, as i struggled to find a decent guide to do so and i want this to help people after me (and me) to basically not go through the maze i went through.

Ps: if anyone is having the same problem in the future and want some help, hit me up.