flutter_local_notification 尚未支持ticket 中提到的通知操作按钮。您可能需要同时考虑使用awesome_notifications 插件,因为它支持通知按钮。
要使用操作按钮显示通知,只需使用
void _showNotificationWithButton() {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'Simple Notification',
body: 'Simple body'),
actionButtons: <NotificationActionButton>[
NotificationActionButton(key: 'yes', label: 'Yes'),
NotificationActionButton(key: 'no', label: 'No'),
],
);
}
然后,您可以通过在 NotificationActionButton 上添加图标属性来为操作按钮添加图标。图标应该是资产中映射的图像的字符串资源。
要侦听 Action Button 按下,请使用 actionStream 侦听器。你可以在屏幕的initState()添加这个
AwesomeNotifications().actionStream.listen((receivedNotification) {
// prints the key of the NotificationActionButton pressed
debugPrint('Notification key pressed: ${receivedNotification.buttonKeyPressed}');
});