使用flutter_local_notifications插件时如何更改标题和正文等通知数据?
Posted
技术标签:
【中文标题】使用flutter_local_notifications插件时如何更改标题和正文等通知数据?【英文标题】:How to change notification data like title and body, when using flutter_local_notification plugin? 【发布时间】:2022-01-09 13:16:09 【问题描述】:我目前正在使用 flutter_local_notifications 插件来触发通知,但问题是我想动态更改通知标题及其正文。基本上,我在我的 Django 后端创建新通知,然后在我的颤振前端获取最新的通知数据。每天都会触发通知,但通知标题和正文不会更改。示例代码sn-p如下:
var res = await http.get(Uri.parse(<REST API ENDPOINT>));
var body = await json.decode(res.body);
Map notificationData = body['results'][0];
await flutterLocalNotificationsPlugin.periodicallyShow(
notificationData['id'],
notificationData['title'],
notificationData['body'],
RepeatInterval.daily,
notificationDetails);
基本上,我想在触发每个通知之前从后端获取最新通知并使用最新数据,即标题和正文。
【问题讨论】:
【参考方案1】:基本上,我想在触发每个通知之前从后端获取最新通知并使用最新数据,即标题和正文
那么这意味着它不是定期通知。您应该定期显示通知。
来自文档,请注意重复的标题和正文
await flutterLocalNotificationsPlugin.periodicallyShow(0, 'repeating title',
'repeating body', RepeatInterval.everyMinute, platformChannelSpecifics,
androidAllowWhileIdle: true);
您应该获取数据并显示通知
await flutterLocalNotificationsPlugin.show(
0, 'plain title', 'plain body', platformChannelSpecifics,
payload: 'item x');
【讨论】:
以上是关于使用flutter_local_notifications插件时如何更改标题和正文等通知数据?的主要内容,如果未能解决你的问题,请参考以下文章
在使用加载数据流步骤的猪中,使用(使用 PigStorage)和不使用它有啥区别?
Qt静态编译时使用OpenSSL有三种方式(不使用,动态使用,静态使用,默认是动态使用)