颤振本地通知"The hour of the day, expressed as in a 24-hour clock [0..23]."



我正在使用flutter本地通知,我想了解它的时间。在date_time。Dart,这是一个用于flutter本地通知的代码文件,我发现:

"The hour of the day, expressed as in a 24-hour clock [0..23]."

这意味着如果我需要在上午8点创建通知,我应该输入代码07。但是在颤振本地通知的例子中,通知应该是在上午10点,但在代码中他们写了10。这意味着取值范围是[1..][24]不是吗?调度示例代码为:

Future<void> _scheduleDailyTenAMNotification() async {
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
'daily scheduled notification title',
'daily scheduled notification body',
_nextInstanceOfTenAM(),
const NotificationDetails(
android: AndroidNotificationDetails(
'daily notification channel id',
'daily notification channel name',
'daily notification description'),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time);
}
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, 10);
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(const Duration(days: 1));
}
return scheduledDate;
}

这里的下一个实例10am是通过传递参数10来获取的[0..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, 10); //here 10 is for 10:00 AM
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(const Duration(days: 1));
}
return scheduledDate;
}

对应24小时格式。0代表00:00。23表示23:00,即12:00 AM和11:00 PM。

因此,对于在下一个实例8:00 AM设置,您需要通过8。这意味着24小时的8:00和12小时的8:00。

最新更新