/ SDKs / Flutter
SDKs
Chat SDKs Flutter v4
Chat SDKs Flutter
Chat SDKs
Flutter
Version 4

Create a channel

Copy link

Two basic types of channels you can create with Sendbird Chat SDK are open channels and group channels.

An open channel is ideal for use cases that don't require a permanent membership in the channel, such as short-lived live events and news-feed style messaging to a large audience. On the other hand, a group channel is suitable for closer interactions among a limited number of users. To learn more about the different use cases and characteristics of open and group channels, see the channel overview page.

When creating a channel, you can append additional information like cover image, description, and URL by passing several arguments to the corresponding parameters. The channel URL can only contain numbers, letters, underscores, or hyphens, and the URL's length must be between 4 and 100 characters. If you don't specify the channelUrl property, a URL is automatically generated.

If you want to create and continue to use a single group channel for a 1-to-1 chat, set the isDistinct property of the channel to true. If the isDistinct property is set to false, multiple 1-to-1 channels with their own chat history and data may be created for the same two users even if a channel already exists between them.

Note: By default, the Allow creating open channels and Allow creating group channels options are turned on, which means that any user can create open and group channels with Sendbird Chat SDK. This may grant access to unwanted data or operations, leading to potential security concerns. To manage your access control settings, you can turn on or off each option in Settings > Application > Security > Access control list on Sendbird Dashboard.


Open channel

Copy link

An open channel is ideal for use cases that require a small and static number of channels. To create an open channel from Sendbird Dashboard, do the following.

  1. On Sendbird Dashboard, go to Chat > Open channels, and then click Create channel at the top-right corner.
  2. In the dialog box that appears, specify the name, unique URL, cover image, and custom type of a channel.

Alternatively, you can create a channel on demand or dynamically through the Chat SDK or the Chat Platform API. Use the following code to create a channel through the Chat SDK.

try{
  final params = OpenChannelCreateParams()
    ..name = 'NAME'
    ..data = 'DATA'
    ..operatorUserIds = [OPERATOR_USER_IDS]
    ..coverImage = FileInfo.fromFileUrl(fileUrl: 'COVER_IMAGE_URL');  
    // coverImage can also take image files.

  final openChannel = await OpenChannel.createChannel(params);
  // An open channel is successfully created.
  // Through the openChannel parameter of the callback method, you can get the open channel's data from the result object that the Sendbird server has passed.
} catch (e) {
  // Handle error.
}

Or you can create an open channel by configuring an OpenChannelCreateParams object like the following.

try {
  final params = OpenChannelCreateParams()
    ..channelUrl = 'UNIQUE_CHANNEL_URL'
    // In an open channel, you can create a new channel by specifying its unique channel URL.
    ..name = 'NAME'
    ..data = 'DATA'
    ..customType = 'CUSTOM_TYPE';
    ..operatorUserIds = ['Jeff']
    // You can add more OPERATOR_USER_IDS to register users as channel operators.
    ..coverImage = FileInfo.fromFile(
      file: COVER_IMAGE_FILE,
      fileName: 'NAME',
      mimeType: 'image/jpeg',
    )
    // coverImage can also take image URLs.
    
  final openChannel = await OpenChannel.createChannel(params);
  // An open channel with detailed configuration is successfully created.
} catch (e) {
  // Handle error.
}

OpenChannelCreateParams

Copy link
Property nameTypeDescription

name

String

Specifies the channel topic, or the name of the channel.

channelUrl

String

Specifies a unique channel URL given when a new open channel is created.

data

String

Specifies additional channel information such as a long description of the channel or JSON formatted string.

operatorUserIds

List<String>

Specifies an array of one or more users to register as operators of the channel. Operators can delete any messages, and also view all messages in the channel without any filtering or throttling.

customType

String

Specifies the custom channel type which is used for channel grouping.

Note: See categorize channels by custom type for more information on cover images and custom types.


Group channel

Copy link

A user can create a group channel by inviting other users in their client app. At the implementation level, you need to create a GroupChannelCreateParams object with a list of user IDs to invite. In the params, you can also specify a user ID to designate an operator in the channel. Then, run code that passes the user ID list as an argument to a parameter in the createChannel() method.

Before running the code that creates a group channel for a typical 1-to-1 chat, you should make sure that you set the value of the isDistinct property to true. If the value of the isDistinct property is set to false, a new channel is created with the same two users even if there is already an existing channel between them. In this case, multiple 1-to-1 channels between the same two users can exist, each with its own chat history and data.

However, if you plan to create a Supergroup channel, the value of the isDistinct property should be set to false.

try {
  final params = GroupChannelCreateParams()
    ..userIds = [USER_IDS]
    ..operatorUserIds = [OPERATOR_USER_IDS];
  final groupChannel = await GroupChannel.createChannel(params);
  // Now you can work with the channel object.
} catch (e) {
  // Handle error.
}

GroupChannelCreateParams

Copy link
Property nameTypeDescription

userIds

List<String>

A list of user IDs to include as channel members.

operatorUserIds

List<String>

A list of user IDs to include as channel operators.


Supergroup channel

Copy link

Creating a Supergroup channel follows the exact same process of creating a group channel with the exception of the isSuper property. The GroupChannelCreateParams class has the isSuper property that determines whether a newly created channel is a Supergroup channel or a regular group channel. Set the value of this property to true to create a new Supergroup channel.

Because the distinct option isn't available for Supergroup channels, the isDistinct property is set to false by default when creating a Supergroup channel.

try {
  final params = GroupChannelCreateParams()
    ..userIds = ['John', 'Jin']
    ..operatorUserIds = ['John'];
    ..isSuper = true

  final groupChannel = GroupChannel.createChannel(params);
  // A group channel with the specified users is successfully created.
  // You can get the group channel's data from the result object that the Sendbird server has passed to the callback method.
} catch (e) {
  // Handle error.
}