Skip to main content
FieldValue
Packagecometchat_chat_uikit
Key componentsCometchatUserInfo — uses CometChatUIKit.blockUsers() / CometChatUIKit.unblockUsers() SDK methods
InitCometChatUIKit.init(uiKitSettings) then CometChatUIKit.login(uid)
EventsBlock/unblock state managed via user.blockedByMe property
UI helpersCometChatUserInfoController, confirmation dialogs
Sample appGitHub
RelatedAll Guides
Block/Unblock lets users prevent specific users from sending them messages. When blocked, the message composer is hidden and replaced with an unblock prompt. Before starting, complete the Getting Started guide.

Components

Component / ClassRole
CometchatUserInfoUser profile screen with block/unblock controls
CometChatUserInfoControllerController managing block/unblock state and actions
CometChatUIKit.blockUsers()SDK method to block specific users
CometChatUIKit.unblockUsers()SDK method to unblock previously blocked users
user.blockedByMeProperty indicating if current user blocked this user

Integration Steps

1. Navigate to User Info

Open the user info screen from the messages view when tapping the user profile or info icon. File: messages.dart
Navigator.push(
  context,
  MaterialPageRoute(
    builder: (_) => CometchatUserInfo(user: tappedUser),
  ),
);

2. Block User

Call the block user dialog which uses CometChatUIKit.blockUsers() with the target UID. On success, update the UI to show the blocked state. File: cometchat_user_info.dart
listTileOptions(
  controller.user?.blockedByMe != true
    ? Translations.of(context).block
    : Translations.of(context).unBlock,
  Icon(Icons.block, color: colorPalette.error),
  () {
    if (controller.user?.blockedByMe != true) {
      controller.blockUserDialog(
        context: context,
        colorPalette: colorPalette,
        typography: typography,
      );
    } else {
      controller.unblockUserDialog(
        context: context,
        colorPalette: colorPalette,
        typography: typography,
      );
    }
  },
)

3. Unblock User

Call CometChatUIKit.unblockUsers() with the target UID. On success, restore the UI to allow messaging. File: cometchat_user_info_controller.dart
void unblockUserDialog({
  required BuildContext context,
  required CometChatColorPalette colorPalette,
  required CometChatTypography typography,
}) {
  // Show confirmation dialog
  // On confirm: CometChatUIKit.unblockUsers([user.uid])
}

4. Blocked State Banner

Display a warning banner when viewing a blocked user’s profile. File: cometchat_user_info.dart
if (value.getBlockedByMe())
  Container(
    padding: EdgeInsets.symmetric(
      horizontal: spacing.padding3 ?? 0,
      vertical: spacing.padding2 ?? 0,
    ),
    color: colorPalette.warning?.withValues(alpha: 0.2),
    child: Row(
      children: [
        Icon(Icons.info, color: colorPalette.warning),
        SizedBox(width: spacing.padding2),
        Text("${Translations.of(context).youHaveBlocked} ${widget.user.name}."),
      ],
    ),
  ),

5. Composer Blocked State

When a user is blocked, the composer in thread/message views is replaced with an unblock prompt. File: cometchat_thread.dart
if (controller.user?.blockedByMe == true) {
  return Container(
    padding: EdgeInsets.symmetric(vertical: 8, horizontal: 20),
    color: colorPalette.background4,
    child: Column(
      children: [
        Text(Translations.of(context).cantSendMessageBlockedUser),
        ElevatedButton(
          onPressed: () => controller.unBlockUser(),
          child: Text(Translations.of(context).unBlock),
        ),
      ],
    ),
  );
}

Feature Matrix

FeatureComponent / MethodFile
User info screenCometchatUserInfocometchat_user_info.dart
Block userblockUserDialog()cometchat_user_info_controller.dart
Unblock userunblockUserDialog()cometchat_user_info_controller.dart
Check blocked statususer.blockedByMecometchat_user_info.dart
Blocked bannerWarning containercometchat_user_info.dart
Blocked composer_buildBlockedUserSection()cometchat_thread.dart

Next Steps