dart - Flutter:如何向本地通知添加按钮

标签 dart flutter localnotification

我已经能够显示本地通知,但是否有任何选项可以显示通知下方的按钮?

(请参阅附图中的“暂停”和“关闭”按钮)。

enter image description here

最佳答案

如果您正在使用 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
        )
    ]
);

关于dart - Flutter:如何向本地通知添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52408222/

相关文章:

asynchronous - 为 await block 中的对象字段分配新值进一步说明

flutter - 启用时切换

Flutter - 在 pubspec.yaml 中添加 pub 包

android - 试图让 phonegap 的 Android LocalNotification 插件在 cordova-1.6.0 中工作

android-studio - 坚持将文件同步到设备 Chrome... Flutter Web

dart - Flutter Overlapped InkWells 手势检测

flutter - Null 相关错误 - 无法将参数类型 'String? Function(String)' 分配给参数类型 'String? Function(String?)?'

flutter - 如何在Flutter中制作带有倒圆角的容器?

ios - 持久本地通知 iOS

ios - 带有开始和结束时间的每日本地通知