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
      // ignore: always_specify_types
      ?.map((a) => AndroidNotificationChannel(
            a['id'],
            a['name'],
            description: a['description'],
            groupId: a['groupId'],
            showBadge: a['showBadge'],
            importance: Importance.values
                // ignore: always_specify_types
                .firstWhere((i) => i.value == a['importance']),
            playSound: a['playSound'],
            sound: _getNotificationChannelSound(a),
            enableLights: a['enableLights'],
            enableVibration: a['enableVibration'],
            vibrationPattern: a['vibrationPattern'],
            ledColor: Color(a['ledColor']),
            audioAttributesUsage: AudioAttributesUsage.values.firstWhere(
              // ignore: always_specify_types
              (e) => e.value == a['audioAttributesUsage'],
              orElse: () => AudioAttributesUsage.notification,
            ),
          ))
      .toList();
}