【发布时间】:2021-10-12 12:29:53
【问题描述】:
我想每天在特定时间触发本地通知(由用户选择)。类似于报警类型。在日期选择器的帮助下。用户必须选择日期和时间,它应该每天在该时间推送本地通知。
【问题讨论】:
标签: flutter notifications alarmmanager localnotification
我想每天在特定时间触发本地通知(由用户选择)。类似于报警类型。在日期选择器的帮助下。用户必须选择日期和时间,它应该每天在该时间推送本地通知。
【问题讨论】:
标签: flutter notifications alarmmanager localnotification
假设你已经预设了flutter_local_notification
您可以按照以下方式进行操作
DateTime scheduledTime 处理日期时间分配
import 'package:flutter_local_notifications/flutter_local_notifications.dart'as notifs;
Future<void> scheduleNotification(
{notifs.FlutterLocalNotificationsPlugin notifsPlugin,
String id,
String title,
String body,
DateTime scheduledTime}) async {
var androidSpecifics = notifs.AndroidNotificationDetails(
id, // This specifies the ID of the Notification
'Scheduled notification', // This specifies the name of the notification channel
'A scheduled notification', //This specifies the description of the channel
icon: 'icon',
);
var iOSSpecifics = notifs.IOSNotificationDetails();
var platformChannelSpecifics = notifs.NotificationDetails(
androidSpecifics, iOSSpecifics);
await notifsPlugin.schedule(0, title, "Scheduled notification",
scheduledTime, platformChannelSpecifics); // This literally schedules the notification
}
用户将如何选择日期(在特定时间每天应触发多少天本地通知
如果是一次出现通知,您可以使用日期时间选择器来选择日期
如果它必须在不同的日子同时发生,您可以使用workmanager 并每 24 小时运行一次,并在没有频率结束后结束服务
检查这个blog post
【讨论】: