dart - Flutter:如何向本地通知添加按钮
问题描述
我已经能够显示本地通知,但是否有任何选项可以在通知下方显示按钮?
(请参阅附图中的“贪睡”和“关闭”按钮)。
解决方案
如果您使用的是local_notifications,您可以添加actions
:
handleCustomActionClick(String payload) {
if(payload == "secondAction") {
LocalNotifications.removeNotification(0);
}
}
int id = await LocalNotifications.createNotification(
title: "Multiple Actions",
content: 'With custom callbacks',
id: 0,
onNotificationClick: new NotificationAction(
actionText: "Some action",
callback: onNotificationClick,
payload: "Some payload",
launchesApp: false
),
actions: [
new NotificationAction(
actionText: "First",
callback: handleCustomActionClick,
payload: "firstAction",
launchesApp: true
),
new NotificationAction(
actionText: "Second",
callback: handleCustomActionClick,
payload: "secondAction",
launchesApp: false
)
]
);
推荐阅读
- django - 提交后台任务之前的Django超时
- pdf - 识别 pdf 文件中的渐变文本颜色
- python - 使用 Pandas .loc 函数过滤数据
- c - 在字符串中查找按字典顺序排列的最大单词 - C 指针
- eclipse - Eclipse Apache ISIS HelloWorld 原型错误:flatten、QHelloWorldObject、maven build java.sql.SQLException 缺失
- google-cloud-platform - 在自定义域云存储桶上启用 CORS
- javascript - 条件三元 Javascript 不接 api 调用
- azure - 使用 azure ci cd 本地部署 java 代码
- django - 过滤对象列表,检查是否存在
- gerrit - gerrit 远程主机关闭连接