---
source_url: https://www.pubnub.com/docs/sdks/dart/api-reference/channel-groups
title: Channel Groups API for Dart SDK
updated_at: 2026-06-26T11:05:35.054Z
sdk_name: PubNub Dart SDK
sdk_version: 7.1.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Channel Groups API for Dart SDK

PubNub Dart SDK, use the latest version: 7.1.0

Install:

```bash
dart pub add pubnub@7.1.0
```

[Channel groups](https://www.pubnub.com/docs/general/channels/subscribe#channel-groups) allow PubNub developers to bundle thousands of [channels](https://www.pubnub.com/docs/general/channels/overview) into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.

:::note Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
:::

## Add channels to a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the PubNub [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function adds channels to a channel group.

### Method(s)

Use the following method in the Dart SDK:

:::note Maximum number of channels
You can add up to 200 channels to a channel group per API call.
:::

```dart
pubnub.channelGroups.addChannels(
  String group,
  Set<String> channels,
  {Keyset? keyset,
  String? using}
) 
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| group | String | Yes |  | The channel group to add the channels to. |
| channels | Set<String> | Yes |  | The channels to add to the channel group. |
| keyset | Keyset | Optional |  | Override for the PubNub default keyset configuration. |
| using | String | Optional |  | Keyset name from the `keysetStore` to be used for this method call. |

### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```dart
import 'package:pubnub/pubnub.dart';

void main() async {
  // Create PubNub instance with default keyset.
  var pubnub = PubNub(
    defaultKeyset: Keyset(
      subscribeKey: 'demo',
      publishKey: 'demo',
      userId: UserId('myUniqueUserId')
    ),
  );

  // Define the channel group and channels to add.
  var group = 'cg1';
  var channels = {'ch1', 'ch2'};

  // Add channels to the channel group
  var result = await pubnub.channelGroups.addChannels(group, channels);

  // Print the result
   print('Add Channels Result: ${result}');
}
```

### Response

The `addChannels()` method returns a `ChannelGroupChangeChannelsResult`.

```json
{
  "service": "channel-registry",
  "status": "200",
  "error": false,
  "message": "OK"
}
```

## List channels in a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function lists all channels in a channel group.

### Method(s)

Use the following method in the Dart SDK:

```dart
pubnub.channelGroups.listChannels(
  String group,
  {Keyset? keyset,
  String? using}
) 
```

| Parameter | Description |
| --- | --- |
| `group` *Type: `String` | The channel group for which to list channels. |
| `keyset`Type: `Keyset` | Override for the PubNub default keyset configuration. |
| `using`Type: `String` | Keyset name from the `keysetStore` to be used for this method call. |

### Sample code

```dart
var result = await pubnub.channelGroups.listChannels('cg1');
```

### Returns

The `listChannels()` operation returns a `ChannelGroupListChannelsResult` which contains the following operations:

| Method | Description |
| --- | --- |
| `channels`Type: `Set<String>` | List of `channels` of a `channel group`. |
| `name`Type: `String` | Channel group name. |

## Remove channels from a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function removes channels from a channel group.

### Method(s)

Use the following method in the Dart SDK:

```dart
pubnub.channelGroups.removeChannels(
  String group,
  Set<String> channels,
  {Keyset? keyset,
  String? using}
)
```

| Parameter | Description |
| --- | --- |
| `group` *Type: `String` | The channel group to remove the channels from. |
| `channels` *Type: `Set<String>` | The channels to remove from the channel group. |
| `keyset`Type: `Keyset` | Override for the PubNub default keyset configuration. |
| `using`Type: `String` | Keyset name from the `keysetStore` to be used for this method call. |

### Sample code

```dart
var result = await pubnub.channelGroups.removeChannels('cg1', {'ch1'});
```

### Returns

The `removeChannels` method returns a `ChannelGroupChangeChannelsResult`.

```json
{
  "service": "channel-registry",
  "status": "200",
  "error": false,
  "message": "OK"
}
```

## Delete a channel group

:::note Requires Stream Controller add-on
This method requires that the *Stream Controller* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). Read the [support page](https://support.pubnub.com/hc/en-us/articles/360051974791-How-do-I-enable-add-on-features-for-my-keys-) on enabling add-on features on your keys.
:::

This function deletes a channel group.

### Method(s)

Use the following method in the Dart SDK:

```dart
pubnub.channelGroups.delete(
  String group,
  {Keyset? keyset,
  String? using}
) 
```

| Parameter | Description |
| --- | --- |
| `group` *Type: `String` | The channel group to remove all channels from. |
| `keyset`Type: `Keyset` | Override for the PubNub default keyset configuration. |
| `using`Type: `String` | Keyset name from the `keysetStore` to be used for this method call. |

### Sample code

```dart
var result = await pubnub.channelGroups.delete('cg1');
```

### Returns

The `delete` method returns a `ChannelGroupDeleteResult`.

```json
{
"service": "channel-registry",
"status": "200",
"error": false,
"message": "OK"
}
```

## Get subscribed channel groups

Returns all the subscribed channel groups in a `Set<String>`.

### Method(s)

`Get Subscribed Channel Groups` is accomplished by inspecting the following property in the Dart SDK:

```dart
// property of `Subscription` class
subscription.channelGroups
```

### Sample code

```dart
var subscription = pubnub.subscribe(channelGroups: {'cg1', 'cg2'});
var subscribedChannelGroups = subscription.channelGroups;

print('subscribed channel groups are $subscribedChannelGroups');
```

### Response

This property is of type `Set<String>`.

```json
["channel1", "channel2"]
```

## Terms in this document

* **Channel** - A pathway for sending and receiving messages between devices, created automatically when you first use it, that can handle any number of users and messages for different communication needs, like 1-1 text chats, group conversations, and other data streaming.
* **PubNub** - PubNub is a real-time messaging platform that provides APIs and SDKs for building scalable applications. It handles the complex infrastructure of real-time communication, including: Message delivery and persistence, Presence detection, Access control, Push notifications, File sharing, Serverless processing with Functions and Events & Actions, Analytics and monitoring with BizOps Workspace, AI-powered insights with Illuminate.