如何使用 flutter_local_notification 包触发特定时间段的通知。我尝试了 pub.dev 上的教程,但我仍然无法做到。有人,请帮忙。
这是我在下午 4:23 触发它的尝试。
tz.TZDateTime _nextInstanceOfTenAM() {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduledDate =
tz.TZDateTime(tz.local, now.year, now.month, now.day, 16, 23));
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(const Duration(days: 1));
}
return scheduledDate;
Future<void> displayNotification() async {
notificationsPlugin.zonedSchedule(
0,
"Wake Up",
'Time to wake up now',
_nextInstanceOfTenAM(),
//tz.TZDateTime.now(tz.local).add(Duration(seconds: 3)),
NotificationDetails(
android: AndroidNotificationDetails(
'channel id', 'channel name', 'channel description'),
),
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true);
}