/ SDKs / Flutter
SDKs
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Flutter
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

Filter group channels by user IDs

Copy link

To filter group channels by user IDs, use GroupChannelListQuery's userIdsExactFilter or userIdsIncludeFilter. Let's assume the ID of the current user is Harry and the user is a member of three group channels.

  • Channel A: Harry and Jay.
  • Channel B: Harry, John, and Jin.
  • Channel C: Harry, John, Jin, and Jay.

A userIdsExactFilter filter returns a list of the current user's group channels containing exactly the queried user IDs. In case you specify only one user ID in the filter, the filter returns a list of the current user's one or more distinct 1-to-1 group channels with the specified user.

try {
    final query = GroupChannelListQuery()
        ..userIdsExactFilter = ['Jay'];
    final result = await query.loadNext();
} catch (e) {
    // Handle error.
}
// If successful, only Channel A is returned.

A userIdsIncludeFilter filter returns a list of the current user's group channels including the queried user IDs partially or exactly. Depending on the value of the GroupChannelListQueryType parameter, different results can be returned.

try {
    final query = GroupChannelListQuery()
    query.setUserIdsIncludeFilter(['John', 'Jay', 'Jin'], GroupChannelListQueryType.and);
    final result = await query.loadNext();
    // Channels should include only ['John', 'Jay', 'Jin'] as a subset. Thus, if successful, only Channel C is returned.
} catch (e) {
    // Handle error.
}

try {
    final query = GroupChannelListQuery()
    query.setUserIdsIncludeFilter(['John', 'Jay', 'Jin'], GroupChannelListQueryType.or);
    final result = await query.loadNext();
    // Channels may include any of the items in ['John', 'Jay', 'Jin']. Thus, if successful, all Channel A,B, and C are returned.
} catch (e) {
    // Handle error.
}