Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG | MISSING] - No example scenario available to demonstrate how to dismiss a notification via action button. #2519

Open
dishankjindal1 opened this issue Jan 20, 2025 · 3 comments

Comments

@dishankjindal1
Copy link

@dishankjindal1 Please file a new issue with your code for setting up the plugin, your code for showing the notification, and your platform/device. Please also confirm that you've followed the instructions for setup properly and try checking the example app to see if it's an issue in your project's code.

Originally posted by @Levi-Lesches in #1991

@dishankjindal1
Copy link
Author

dishankjindal1 commented Jan 20, 2025

This is a notification details used for android, i dont see any problem here. But the dismiss button is not working.

Package v18.0.1
flutter v3.24.5
sdks:
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.24.0"

AndroidNotificationDetails(
          'notifications_channel',
          'Notifications',
          importance: Importance.max,
          priority: Priority.high,
          color: MBXPalette.primary100,
          icon: '@mipmap/ic_notification',
          styleInformation: notifType.contains('banner')
              ? banner == null
                  ? null
                  : BigPictureStyleInformation(
                      ByteArrayAndroidBitmap.fromBase64String(banner))
              : BigTextStyleInformation(
                  notificationData['body'].toString(),
                ),
          largeIcon: largeIcon == null
              ? null
              : ByteArrayAndroidBitmap.fromBase64String(largeIcon),
          ongoing: notificationData['is_sticky'] == 'True',
          actions: [
            if (notificationData['is_sticky'] == 'True')
              AndroidNotificationAction(
                'dismiss_action',
                'Dismiss',
              ),
            if (notificationData['primary_cta_title'] != null)
              AndroidNotificationAction(
                'primary_action',
                notificationData['primary_cta_title'],
                showsUserInterface: true,
                cancelNotification: false,
              ),
          ],
        )

@dishankjindal1 dishankjindal1 changed the title [MISSING] - No example scenario available to demonstrate how to dismiss a notification via action button. [BUG | MISSING] - No example scenario available to demonstrate how to dismiss a notification via action button. Jan 20, 2025
@Levi-Lesches
Copy link
Contributor

I do see that you've let AndroidNotificationAction.cancelNotification take its default value, true. I think that makes this a bug. In any case, have you tried:

@dishankjindal1
Copy link
Author

dishankjindal1 commented Jan 22, 2025

AndroidNotificationDetails(autoCancel: true?

Yes

using a callback to cancel the notification based on the notification ID and action ID?

onDidReceiveNotificationResponse: (details) {
  if (details.actionId == 'dismiss_action') {
    FlutterLocalNotificationsPlugin().cancel(details.id!);
  }
},
onDidReceiveBackgroundNotificationResponse: (details) {
  if (details.actionId == 'dismiss_action') {
    FlutterLocalNotificationsPlugin().cancel(details.id!);
  }
},

Tapping on notification body, dismiss it. But action buttons are not working as intended.

In the example project, i did not see callback are being used to cancel the notification. I think in the latest release there must be some bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants