kickGroupMember static method

Future<String?> kickGroupMember({
  1. required String guid,
  2. required String uid,
  3. required dynamic onSuccess(
    1. String result
    )?,
  4. required dynamic onError(
    1. CometChatException excep
    )?,
})

Kicks a member from a group.

Migration Note: Migrated from platform channels to native Dart. Behavior and signature remain identical.

Android Reference: GroupMembersRequest.kickGroupMember(String guid, String uid)

Admin or Moderator of a group can kick a member out of the group

guid The GUID of the group from which user is to be kicked

uid The UID of the user to be kicked

Kicked user can rejoin the group.

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<String?> kickGroupMember(
    {required String guid,
    required String uid,
    required Function(String result)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call repository
    await sdk.groupMembers.kickMember(guid, uid);

    // Call success callback
    final result = 'Member kicked successfully';
    if (onSuccess != null) onSuccess(result);
    return result;
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    _errorCallbackHandler(cometChatEx, null, null, onError);
  } catch (e) {
    // Handle unexpected errors
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}