【发布时间】:2021-10-06 23:57:27
【问题描述】:
我正在使用颤振本地通知,我想了解它的时间。在颤振本地通知中使用的代码文件 date_time.dart 中,我发现:
"The hour of the day, expressed as in a 24-hour clock [0..23]."
这意味着我需要在上午 8 点创建通知,我应该输入代码 07。 但是flutter本地通知的例子,通知的意思是在上午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;
}
【问题讨论】:
-
23 是晚上 11:00。所以 20 将是 8:00 PM,这反过来意味着 16 将是 4:00 PM,12 将是 12:00 PM。同样 10 是 10:00 AM 。因此,对于 8,您有 8:00 AM 作为答案。这里的 0 代表 00:00 AM
-
请将此评论作为批准它的答案,谢谢@KrishBhanushali
标签: flutter dart flutter-local-notification