> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-llms-scoped-indexes.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Block/Unblock Users

> Implement block and unblock user functionality in CometChat Flutter UI Kit with composer state management.

<Accordion title="AI Agent Component Spec">
  | Field | Value |
  | - | - |
  | Package | `cometchat_chat_uikit` |
  | Key components | `CometchatUserInfo` — uses `CometChatUIKit.blockUsers()` / `CometChatUIKit.unblockUsers()` SDK methods |
  | Init | `CometChatUIKit.init(uiKitSettings)` then `CometChatUIKit.login(uid)` |
  | Events | Block/unblock state managed via `user.blockedByMe` property |
  | UI helpers | `CometChatUserInfoController`, confirmation dialogs |
  | Sample app | [GitHub](https://github.com/cometchat/cometchat-uikit-flutter/tree/v5/sample_app) |
  | Related | [All Guides](/ui-kit/flutter/v5/guide-overview) |
</Accordion>

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](/ui-kit/flutter/v5/getting-started) guide.

***

## Components

| Component / Class | Role |
| :- | :- |
| `CometchatUserInfo` | User profile screen with block/unblock controls |
| `CometChatUserInfoController` | Controller managing block/unblock state and actions |
| `CometChatUIKit.blockUsers()` | SDK method to block specific users |
| `CometChatUIKit.unblockUsers()` | SDK method to unblock previously blocked users |
| `user.blockedByMe` | Property 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](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/messages/messages.dart)*

```dart theme={null}
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](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info.dart)*

```dart theme={null}
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](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info_controller.dart)*

```dart theme={null}
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](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info.dart)*

```dart theme={null}
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](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/thread_screen/cometchat_thread.dart)*

```dart theme={null}
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

| Feature | Component / Method | File |
| :- | :- | :- |
| User info screen | `CometchatUserInfo` | [cometchat\_user\_info.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info.dart) |
| Block user | `blockUserDialog()` | [cometchat\_user\_info\_controller.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info_controller.dart) |
| Unblock user | `unblockUserDialog()` | [cometchat\_user\_info\_controller.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info_controller.dart) |
| Check blocked status | `user.blockedByMe` | [cometchat\_user\_info.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info.dart) |
| Blocked banner | Warning container | [cometchat\_user\_info.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/user_info/cometchat_user_info.dart) |
| Blocked composer | `_buildBlockedUserSection()` | [cometchat\_thread.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v5/sample_app/lib/thread_screen/cometchat_thread.dart) |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Users" href="/ui-kit/flutter/v5/users">
    Display and manage user lists.
  </Card>

  <Card title="Message Composer" href="/ui-kit/flutter/v5/message-composer">
    Customize the message input component.
  </Card>

  <Card title="All Guides" href="/ui-kit/flutter/v5/guide-overview">
    Browse all feature and formatter guides.
  </Card>

  <Card title="Sample App" href="https://github.com/cometchat/cometchat-uikit-flutter/tree/v5/sample_app">
    Full working sample application on GitHub.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.