deleteGroup static method

Future<void> deleteGroup(
  1. String guid, {
  2. required dynamic onSuccess(
    1. String message
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?,
})

Deletes a group.

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

Android Reference: GroupsRequest.deleteGroup(String guid)

In order to delete a group.

The user must be an Admin of the group they are trying to delete.

guid A unique identifier for a group that logged in user wants to delete.

method could throw PlatformException with error codes specifying the cause

Implementation

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

    // Call repository
    await sdk.groups.deleteGroup(guid);

    // Call success callback
    if (onSuccess != null) onSuccess('Group deleted successfully');
  } 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);
  }
}