Block a user
Add a specified user to the current user blocklist using the OpenIM Flutter SDK.
Add a specified user to the currently signed-in user's blocklist:
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userID | String | Yes | Target user ID to add to the blocklist. |
ex | String? | No | Custom extension string. Passing a new value overwrites existing extension text without automatically merging JSON properties. |
Code example
await OpenIM.iMManager.friendshipManager.addBlacklist(
userID: 'user_123',
ex: '{"source":"profile-menu"}',
);Return value
A successful Future returns void, indicating that the block request was committed by the server and recorded locally.
State changes after the call
This method alters relationship states. Once the block takes effect, the blocked user cannot send single-chat messages to the current user, though the current user can still dispatch messages to them; enforce mutual message suppression at the application layer if required.
Listen for blocklist events
Handle blocklist additions centrally. When the block takes effect, connected client devices receive onBlackAdded event notifications. Use userID as the key to merge records into the local blocklist state:
void handleBlackAdded(BlacklistInfo info) {
mergeBlockedUser(info);
}The Flutter SDK maintains a single OnFriendshipListener instance inside FriendshipManager. Register this handler through the application-wide entry point described in Events overview. To fetch the complete list of blocked users, see Retrieve a list of blocked users.
Was this page helpful?