Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How Can I Add buttons to Local Notification

i've been able to show Local Notification but is there any option to show buttons below the notification?

(See "Snooze" & "Dismiss" button in the attached picture).

enter image description here

like image 878
Tayo.dev Avatar asked Sep 19 '18 14:09

Tayo.dev


Video Answer


1 Answers

If you are using local_notifications you can add 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
        )
    ]
);
like image 105
zeucxb Avatar answered Sep 19 '22 18:09

zeucxb