Home > Net >  Add Action to AndroidNotificationDetails
Add Action to AndroidNotificationDetails

Time:11-05

I would like to add a button to my notification, I was able to get it displayed but I can't find the documentation on how to add an action to the button press

const androidNotification = AndroidNotificationDetails(
      'Bla', 'Bla',
      icon: 'ic_bg_service_small',
      ongoing: true,
      actions: [AndroidNotificationAction("stop", "Stop")]);

  flutterLocalNotificationsPlugin.show(
    888,
    'MyService',
    'bla',
    const NotificationDetails(android: androidNotification),
  );

CodePudding user response:

You need to use this plugin to make action in notifications https://pub.dev/packages/awesome_notifications

void _showNotificationWithButton() {
  AwesomeNotifications().createNotification(
    content: NotificationContent(
        id: 10,
        channelKey: 'basic_channel',
        title: 'Simple Notification',
        body: 'Simple body'),
    actionButtons: <NotificationActionButton>[
      NotificationActionButton(key: 'yes', label: 'Yes'),
      NotificationActionButton(key: 'no', label: 'No'),
    ],
  );
}
  • Related