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

Retrieve a list of channels

Copy link

You can retrieve a list of open channels using OpenChannelListQuery's next() method, which returns a list of OpenChannel objects.

You can also retrieve a list of the current user's private group channels using the next() method of a GroupChannelListQuery instance, which returns a list of GroupChannel objects. Using the includeEmpty property of a GroupChannelListQuery instance, you can determine whether to include empty channels in the result. Empty channels are group channels that have been created but don't contain any messages, and thus aren't included in the result by default. However, if you turn off the Chat history option on Sendbird Dashboard, you may retrieve empty channels in the result.

Note: See search group channels by name, URL, or other filters to find out how to search for specific group channels using keywords and filters.


Open channel

Copy link

Create an OpenChannelListQuery instance to retrieve a list of open channels matching the specifications set by OpenChannelListQuery. After a list of open channels is successfully retrieved, you can access the data of each open channel from the result list through the openChannel parameter of the callback method.

try {
  final query = OpenChannelListQuery()
    ..channelUrl = channel.channelUrl;

  final openChannels = await query.next();
  // A list of open channels is successfully retrieved.
} catch (e) {
  // Handle error.
}

Group channel

Copy link

Create a GroupChannelListQuery instance to retrieve a list of group channels matching the specifications set by GroupChannelListQuery.

You can set GroupChannelListQuery's includeEmpty property to true so that users can view empty channels since the view chat history option is turned off to prevent new members from seeing previous conversations. You can determine whether to turn on the chat history option on Sendbird Dashboard under Settings > Chat > Channels > Group channels.

try {
  final query = GroupChannelListQuery()
    ..order = GroupChannelListOrder.latestLastMessage
    ..myMemberStateFilter = MyMemberStateFilter.joined
    ..limit = 10;
  final groupChannels = await query.next();
  // A list of private group channels matching the list query criteria is successfully retrieved.
} catch (e) {
  // Handle error.
}

List of properties

Copy link
Property nameTypeDescription

includeEmpty

bool

Determines whether to include empty group channels in the results.

myMemberStateFilter

MyMemberStateFilter

Restricts the search scope based on the state of the current user. Acceptable values are all, joined, and invited.

order

GroupChannelListQueryOrder

A list of user IDs invited to the channel. Acceptable values are chronological, latestLastMessage, channelNameAlphabetical, and metadataValueAlphabetical.

limit

int

Specifies the number of results to return per call. Acceptable values are 1 to 100, inclusive. The recommended value for this parameter is 20.


All public group channels

Copy link

If you want to retrieve a list of all public group channels regardless of the current user's membership status, use the PublicGroupChannelListQuery instance and set PublicGroupChannelMembershipFilter to PublicGroupChannelMembershipFilter.all in PublicGroupChannelListQuery.

After a list of public group channels is successfully retrieved, you can access the data of each channel from the result list.


Supergroup channels

Copy link

To retrieve a list of Supergroup channels, you can set the superChannelFilter property to SuperChannelFilter.superChannelOnly in either the GroupChannelListQuery or PublicGroupChannelListQuery instance. The superChannelFilter property works much like other search filters. Use GroupChannelListQuery when only searching for group channels that the current user belongs to, and use PublicGroupChannelListQuery when searching for all public group channels regardless of the current user's membership status.

When queried channels are returned, you can check if the channel is a Supergroup channel by looking at whether the isSuper property has a value of true.

Using GroupChannelListQuery

Copy link
try {
  final query = GroupChannelListQuery()
    ..superChannelFilter = SuperChannelFilter.superChannelOnly;
  final groupChannels = await query.next();
} catch (e) {
  // Handle error.
}

Using PublicGroupChannelListQuery

Copy link
try {
  final query = PublicGroupChannelListQuery()
    ..superChannelFilter = SuperChannelFilter.all;
  final groupChannels = await query.next();
} catch (e) {
  // Handle error.
}