buildNotificationChannel static method

AndroidNotificationChannel buildNotificationChannel(
  1. String chatChannelId,
  2. String? chatChannelName,
  3. bool isSummaryNotification
)
  • Build notification channel with given notification ID.
  • @parameter notificationId Unique notification id of the conversation
  • @return AndroidNotificationChannel

Implementation

static AndroidNotificationChannel buildNotificationChannel(
    String chatChannelId,
    String? chatChannelName,
    bool isSummaryNotification) {
  // AndroidNotificationChannel createdChannel;
  var notificationSoundUri = SessionManagement.getNotificationUri();
  var isVibrate = SessionManagement.getVibration();
  var isRing = SessionManagement.getNotificationSound();
  var channelName = chatChannelName ?? AppConstants.appNotifications;
  var channelId =
      getNotificationChannelId(isSummaryNotification, chatChannelId);
  var vibrateImportance = (isVibrate) ? Importance.high : Importance.low;
  var channelDescription = AppConstants.appNotificationsDesc;
  var ringImportance = (isRing) ? Importance.high : Importance.low;
  if (isRing) {
    return AndroidNotificationChannel(channelId, channelName,
        importance: ringImportance,
        showBadge: true,
        sound: notificationSoundUri != null
            ? UriAndroidNotificationSound(notificationSoundUri)
            : null,
        description: channelDescription,
        enableLights: true,
        ledColor: Colors.green,
        vibrationPattern: (isVibrate /*|| getDeviceVibrateMode()*/)
            ? getDefaultVibrate()
            : null,
        playSound: true);
  } else if (isVibrate) {
    return AndroidNotificationChannel(channelId, channelName,
        importance: vibrateImportance,
        showBadge: true,
        sound: null,
        description: channelDescription,
        enableLights: true,
        ledColor: Colors.green,
        vibrationPattern: (isVibrate /*|| getDeviceVibrateMode()*/)
            ? getDefaultVibrate()
            : null,
        playSound: false);
  } else {
    return AndroidNotificationChannel(channelId, channelName,
        importance: ringImportance,
        description: channelDescription,
        enableLights: true,
        ledColor: Colors.green,
        playSound: true);
  }
}