首页 > 解决方案 > Flutter:如何向本地通知添加按钮

问题描述

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

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

在此处输入图像描述

标签: dartflutterlocalnotification

解决方案


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

推荐阅读