Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss notification after action button clicked without opening the app?

I am showing a notification using awesome_notifications and there is action buttons that dismiss the notification, but the problem is if the app is in the background, and the action button clicked, then it dismisses the notification but open the app too which I don't want. So how can I just dismiss the notification when the action button is clicked without opening the app? The notification also contains another action button that opens the app but the second should not. What should I do in that case?

This is what currently happens: enter image description here

Code to show notification:

AwesomeNotifications().createNotification(
         content: NotificationContent(
           id: 333,
           title: 'Incoming Call',
           body: 'from $callerName',
           category: NotificationCategory.Call,
           channelKey: 'call_channel',
           largeIcon: 'asset://assets/images/logo_square.png',
           wakeUpScreen: true,
           fullScreenIntent: true,
           autoDismissible: false,
           showWhen: true,
           displayOnBackground: true,
           displayOnForeground: true,
           payload: {
             "callerName": callerName,
             "callerUsername": callerUsername,
             "callerID": callerID,
             "callerToken": callerToken,
             "callerImage": callerImage,
           },
         ),
         actionButtons: [
           NotificationActionButton(
               key: 'ACCEPT',
               label: 'Accept Call',
               color: Colors.green,
               autoDismissible: true,
           ),
           NotificationActionButton(
               key: 'REJECT',
               label: 'Reject Call',
               isDangerousOption: true,
               autoDismissible: true,
           ),
         ]
     );
like image 278
Siddharth Mehra Avatar asked Oct 24 '25 02:10

Siddharth Mehra


1 Answers

Found the answer while surfing the GitHub Repository of awesome_notifications. The notification can straightly be dismissed without opening the app by adding buttonType as ActionButtonType.DisabledAction in the NotificationActionButton

just like this:

NotificationActionButton(
   key: 'DISMISS',
   label: 'Dismiss',
   autoDismissible: true,
   buttonType: ActionButtonType.DisabledAction,
   isDangerousOption: true
)

Note: Doing so will not trigger any receivedAction in the actionStream.

like image 178
Siddharth Mehra Avatar answered Oct 25 '25 17:10

Siddharth Mehra