addMembersToGroup static method
Future<Map<String?, String?> ?>
addMembersToGroup({
- required String guid,
- required List<
GroupMember> groupMembers, - required dynamic onSuccess()?,
- required dynamic onError(
- CometChatException excep
Adds members to a group.
Migration Note: Migrated from platform channels to native Dart. Behavior and signature remain identical.
Android Reference: GroupMembersRequest.addMembersToGroup(String guid, List<GroupMember> members)
Add members to the group
guid id of group in which members should be added
groupMembers list of GroupMember instance members to be added
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<Map<String?, String?>?> addMembersToGroup(
{required String guid,
required List<GroupMember> groupMembers,
required Function(Map<String?, String?> result)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call repository
await sdk.groupMembers.addMembers(guid, groupMembers);
// Create success map (matching Android SDK behavior)
final res = <String?, String?>{};
for (final member in groupMembers) {
res[member.uid] = 'success';
}
// Call success callback
if (onSuccess != null) onSuccess(res);
return res;
} 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;
}