[英]How to schedule notification at specific time using awesome package in Flutter?
I am using an awesome Package and am trying to make a notification at a specific time using this package.我正在使用一个很棒的包,并尝试使用此包在特定时间发出通知。
Future<void> showNotificationWithIconsAndActionButtons(int id) async {
AwesomeNotifications().initialize(
'',
[
NotificationChannel(
channelKey: 'basic_channel',
channelName: 'Basic notifications',
channelDescription: 'Notification channel for basic tests',
defaultColor: Color(0xFF9D50DD),
ledColor: Colors.white,
playSound: true,
importance: NotificationImportance.Max,
defaultRingtoneType: DefaultRingtoneType.Notification,
)
]
);
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: 'basic_channel',
title: 'Anonymous says:',
body: 'Hi there!',
payload: {'uuid': 'user-profile-uuid'},
displayOnBackground: true,
displayOnForeground: true,
),
i need to make notification in particular time.我需要在特定时间发出通知。
The same plugin provides a way to schedule notifications as per the need.相同的插件提供了一种根据需要安排通知的方法。
Checkout this link from it's description: https://pub.dev/packages/awesome_notifications#scheduling-a-notification从它的描述中查看此链接: https : //pub.dev/packages/awesome_notifications#scheduling-a-notification
Bascially showing it at a specific time will look something like this:基本上在特定时间显示它看起来像这样:
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: 'scheduled',
title: 'Just in time!',
body: 'This notification was schedule to shows at ' +
(Utils.DateUtils.parseDateToString(scheduleTime.toLocal()) ?? '?') +
' $timeZoneIdentifier (' +
(Utils.DateUtils.parseDateToString(scheduleTime.toUtc()) ?? '?') +
' utc)',
notificationLayout: NotificationLayout.BigPicture,
bigPicture: 'asset://assets/images/delivery.jpeg',
payload: {'uuid': 'uuid-test'},
autoCancel: false,
),
schedule: NotificationCalendar.fromDate(date: scheduleTime));
Note: The code sample is from the plugin's Readme.注意:代码示例来自插件的自述文件。 I have not tested this yet.我还没有测试过这个。
Timer.periodic(Duration(minutes: 1), (timer) {
if (DateTime.now()== DateTime.parse("2021-07-20 20:18:04Z")){// 8:18pm
return showNotificationWithIconsAndActionButtons();
}
});
This will let it check the time every minute.这将让它每分钟检查一次时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.