how add button named "Disconnect" in AndroidNotificationOptions ?

my simple code is here .

const AndroidNotificationOptions(
  channelId: 'parameter_channel',
  channelName: 'Parameters',
  channelDescription: 'This notification appears when the reading begaz params running.',
  channelImportance: NotificationChannelImportance.LOW,
  priority: NotificationPriority.LOW,
  visibility: NotificationVisibility.VISIBILITY_PRIVATE,
  playSound: false,
  enableVibration: false,
  iconData: NotificationIconData(
    resType: ResourceType.mipmap,
    resPrefix: ResourcePrefix.ic,
    name: 'launcher',
  ),
),

in here im using flutter_foreground_task.


Solution 1: MeLean

If you look at the documentation you will see an example, but in your case should be like this:

androidNotificationOptions: AndroidNotificationOptions(
      channelId: 'notification_channel_id',
      channelName: 'Foreground Notification',
      channelDescription: 'This notification appears when the foreground service is running.',
      channelImportance: NotificationChannelImportance.LOW,
      priority: NotificationPriority.LOW,
      iconData: const NotificationIconData(
        resType: ResourceType.mipmap,
        resPrefix: ResourcePrefix.ic,
        name: 'launcher',
      ),
      buttons: [
        const NotificationButton(id: 'disconnect', text: 'Disconnect'),
      ],
    ),

The clicks events should be handled in the TaskHandler, like this:

class MyTaskHandler extends TaskHandler{

  ...

  @override
  void onButtonPressed(String id) {
    // Called when the notification button on the Android platform is pressed.
    if(id == 'disconnect'){
      //stop the foreground task
      //do the disconnect
    }
  }

 ...
}