createGroup method Null safety

Future<EMGroup> createGroup(
  1. {String? groupName,
  2. String? desc,
  3. List<String>? inviteMembers,
  4. String? inviteReason,
  5. required EMGroupOptions options}
)

Creates a group instance.

After the group is created, the data in the cache and database will be updated and multiple devices will receive the notification event and update the group data to the cache and database. You can set {@link com.EMMultiDeviceListener} to listen for the event. If an event occurs, the callback function {@link EMMultiDeviceListener#onGroupEvent(int, String, List)} is triggered, where the first parameter is the event which is {@link EMContactGroupEvent#GROUP_CREATE} for a group creation event.

Param groupName The group name.

Param desc The group description.

Param inviteMembers The group member array. The group owner ID is optional.

Param inviteReason The group joining invitation.

Param options The options for creating a group. See {@link EMGroupOptions}. The options are as follows:

  • The maximum number of group members. The default value is 200.
  • The group style. See {@link EMGroupManager.EMGroupStyle}. The default value is {@link EMGroupStyle#PrivateOnlyOwnerInvite}.
  • Whether to ask for permission when inviting a user to join the group. The default value is false, indicating that invitees are automatically added to the group without their permission.
  • The group detail extensions.

Return The created group instance.

Throws A description of the exception. See {@link EMError}.

Implementation

Future<EMGroup> createGroup({
  String? groupName,
  String? desc,
  List<String>? inviteMembers,
  String? inviteReason,
  required EMGroupOptions options,
}) async {
  Map req = {'options': options.toJson()};
  req.setValueWithOutNull("groupName", groupName);
  req.setValueWithOutNull("desc", desc);
  req.setValueWithOutNull("inviteMembers", inviteMembers);
  req.setValueWithOutNull("inviteReason", inviteReason);

  Map result = await _channel.invokeMethod(ChatMethodKeys.createGroup, req);
  try {
    EMError.hasErrorFromResult(result);
    return EMGroup.fromJson(result[ChatMethodKeys.createGroup]);
  } on EMError catch (e) {
    throw e;
  }
}