leaveGroup static method
Future<void>
leaveGroup(
- String guid, {
- required dynamic onSuccess(
- String returnResponse
- required dynamic onError(
- CometChatException excep
Leaves a group.
Migration Note: Migrated from platform channels to native Dart. Behavior and signature remain identical.
Android Reference: GroupsRequest.leaveGroup(String guid)
In order to stop receiving updates and messages for any particular joined group.
Owner cannot leave the group , transfer the ownership before leaving the group
guid A unique identifier for a group that logged in user wants to leave.
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<void> leaveGroup(String guid,
{required Function(String returnResponse)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call repository
await sdk.groups.leaveGroup(guid);
// Call success callback
if (onSuccess != null) onSuccess('Group left 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);
}
}