getNotificationChannels method

Future<List<AndroidNotificationChannel>?> getNotificationChannels()

Returns the list of all notification channels.

This method is only applicable on Android 8.0 or newer. On older versions, it will return an empty list.

Implementation

Future<List<AndroidNotificationChannel>?> getNotificationChannels() async {
  final List<Map<dynamic, dynamic>>? notificationChannels = await _channel
      .invokeListMethod('getNotificationChannels');

  return notificationChannels
      ?.map(
        (a) => AndroidNotificationChannel(
          a['id'],
          a['name'],
          description: a['description'],
          groupId: a['groupId'],
          showBadge: a['showBadge'],
          importance: Importance.values.firstWhere(
            (i) => i.value == a['importance'],
          ),
          bypassDnd: a['bypassDnd'],
          playSound: a['playSound'],
          sound: _getNotificationChannelSound(a),
          enableLights: a['enableLights'],
          enableVibration: a['enableVibration'],
          vibrationPattern: a['vibrationPattern'],
          ledColor: Color(a['ledColor']),
          audioAttributesUsage: AudioAttributesUsage.values.firstWhere(
            (e) => e.value == a['audioAttributesUsage'],
            orElse: () => AudioAttributesUsage.notification,
          ),
        ),
      )
      .toList();
}