I have a prayer-timing App with notifications to be shown for 5 prayers everyday.
For simplicity let's assume there are 5 events(prayers) everyday.
I want to schedule a notification for every event.
Till here, there is no problem, i can use the Flutter_local_notifications package and use the "daily" method to schedule these 5 notifications daily.
The problem is that these timings change every 2-3 days, so the timings of the notifications also have to be changed in that period.
For now i have written the code in such a way that, whenever the user opens the app, the notifications are scheduled again. This works, but the app freezes for a few seconds on start-up which looks really bad.
Is there any other way to do it?
EDIT : The prayer timings for the whole of next year are calculated in the app, the only problem is to schedule them.
As far as I understand your question, I would like to answer it.
Though your prayer timings change, if it has any specific pattern, you could also use Weekly Notification and set each day of the Week with different timings.
Something like this:
await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime(
0,
'On Monday Morning',
'Your Prayer at Monday',
Day.Monday,
time,
platformChannelSpecifics);
Or else, you can send notifications online by Firebase Cloud Messaging (FCM) and there you can schedule it in the console and it will be reflected for all.
FCM Reference: https://firebase.google.com/products/cloud-messaging
For Flutter: https://pub.dev/packages/firebase_messaging
Hope that helps!
#Happy Coding!
Salam my brother,
I'm also working on a prayer timer app, and I didn't find any method/package that helps.
so what I did is that each time the user opens the app I schedule the prayers for the next 7 days (you can make it the next month or even year), I figured that the user will probably use the app once in a week so I picked week.
Each time I schedule prayers (notifications) I save them in a list in Shared Preferences with a timestamp of the prayer, and before I schedule the next prayers I perform the following:
And make sure you use unique id for each notification, if you schedule two notifications with the same id then the second one will override the first. I used this method for that:
String getPrayerNotificationId(DateTime time) {
return DateFormat('yyyyMMddkkmm').format(time);
}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With