addMembersToGroup static method

Future<Map<String?, String?>?> addMembersToGroup({
  1. required String guid,
  2. required List<GroupMember> groupMembers,
  3. required dynamic onSuccess(
    1. Map<String?, String?> result
    )?,
  4. required dynamic onError(
    1. 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 (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}