addMembersToGroup static method
Future<Map<String?, String?> ?>
addMembersToGroup({
- required String guid,
- required List<
GroupMember> groupMembers, - required dynamic onSuccess()?,
- required dynamic onError(
- CometChatException excep
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 {
List<Map<String, dynamic>> groupMemberMapList = [];
for (var member in groupMembers) {
groupMemberMapList.add(member.toJson());
}
try {
final result = await channel.invokeMethod('addMembersToGroup', {
'guid': guid,
'groupMembers': groupMemberMapList,
});
final Map<String?, String?> res = Map<String?, String?>.from(result);
if(onSuccess != null) onSuccess(res);
return res;
} on PlatformException catch (platformException) {
if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
} catch (e) {
debugPrint("Error: $e");
if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
}
return null;
}