setChannel method

  1. @override
Future<void> setChannel(
  1. NotificationChannel notificationChannel, {
  2. bool forceUpdate = false,
})
override

Sets a new notification channel or updates an existing channel.

The notificationChannel parameter is a NotificationChannel object that represents the channel to create or update.

The optional forceUpdate parameter is a boolean value that determines whether to completely update the channel on Android Oreo and above, which requires cancelling all current notifications. If this parameter is set to false, the channel will be updated without force the update changing the channel key nor cancelling notifications.

This method can be used to create or update notification channels for the app. On Android Oreo and above, updating a channel requires cancelling all current notifications associated with the channel. If the forceUpdate parameter is set to true, the channel will be updated using a new key managed by the plugin. This should only be used in emergency situations.

Implementation

@override
Future<void> setChannel(NotificationChannel notificationChannel,
    {bool forceUpdate = false}) async {
  Map<String, dynamic> parameters = notificationChannel.toMap();
  parameters.addAll({CHANNEL_FORCE_UPDATE: forceUpdate});

  await methodChannel.invokeMethod(
      CHANNEL_METHOD_SET_NOTIFICATION_CHANNEL, parameters);
}