flutter - Flutter 中的本地调度通知
问题描述
我想每天在特定时间触发本地通知(由用户选择)。类似于报警类型。在日期选择器的帮助下。用户必须选择日期和时间,它应该每天在该时间推送本地通知。
解决方案
假设你已经预设了 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
}
用户将如何选择日期(在特定时间每天应触发多少天本地通知
您可以使用日期时间选择器来选择日期,如果它是一次发生的通知
如果它必须在不同的日期同时发生,您可以使用工作管理器并每 24 小时运行一次,并在没有频率结束后结束服务
检查这篇博文
推荐阅读
- python - 如何使用python按分钟制作日历事件图
- multithreading - 使用 IServiceScopeFactory 为多线程创建 Scoped DB 上下文的缺点
- android - 如何在我的应用程序中打开窗口并重定向到谷歌播放中的另一个应用程序下载页面
- python - 如何使用其中同一库中的多个函数为函数声明多个 kwargs
- javascript - reCAPTCHA v2 复选框小部件未在我的 REACT 应用程序上呈现
- c - 为什么在一行上声明变量会产生意想不到的结果?
- ios - iOS,我可以知道我是否有使用 CallKit 的来电吗?(不是网络电话)
- reactjs - NextJS,如何将服务器端呈现的应用程序上传到我的 FTP 帐户
- javascript - 在 Blade Foreach 循环中动态隐藏元素
- python - Numpy 在 Spyder 3.8 (Python 3) 中不起作用