简体   繁体   English

Flutter 每天安排通知

[英]Schedule notification everyday for Flutter

I have a prayer-timing App with notifications to be shown for 5 prayers everyday.我有一个祈祷计时应用程序,每天会显示 5 次祈祷的通知。

For simplicity let's assume there are 5 events(prayers) everyday.为简单起见,我们假设每天有 5 个事件(祈祷)。

  1. 5:00 5:00
  2. 6:00 6:00
  3. 7:00 7:00
  4. 8:00 8:00
  5. 9:00 9:00

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.到这里为止,没有问题,我可以使用Flutter_local_notifications package 并使用“每日”方法每天安排这 5 个通知。

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.问题是这些时间每 2-3 天更改一次,因此通知的时间也必须在此期间更改。

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.或者,您可以通过 Firebase Cloud Messaging (FCM) 在线发送通知,您可以在控制台中安排它,它将反映给所有人。
FCM Reference: https://firebase.google.com/products/cloud-messaging FCM 参考: https://firebase.google.com/products/cloud-messaging
For Flutter: https://pub.dev/packages/firebase_messaging对于 Flutter: https://pub.dev/packages/firebase_messaging
Hope that helps!希望有帮助!
#Happy Coding! #快乐编码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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