createGroup method

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

~english 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 EMMultiDeviceEventHandler to listen for the event. If an event occurs, the callback function EMMultiDeviceEventHandler.onGroupEvent is triggered, where the first parameter is the event which is EMMultiDevicesEvent.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 EMGroupOptions. The options are as follows:

  • The maximum number of group members. The default value is 200.
  • The group style. See EMGroupStyle. The default value is 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 EMError. ~end

~chinese 创建群组。

群组创建成功后,会更新内存及数据库中的数据,多端多设备会收到相应的通知事件,将群组更新到内存及数据库中。 可通过设置 EMClient.addMultiDeviceEventHandler 监听相关事件,事件回调函数为 EMMultiDeviceEventHandler.onGroupEvent,第一个参数为事件,创建群组事件为 EMMultiDevicesEvent.GROUP_CREATE

Param groupName 群组名称。

Param desc 群组描述。

Param inviteMembers 群成员数组。群主 ID 可选。

Param inviteReason 用户入群邀请信息。

Param options 群组的其他选项。请参见 {@link EMGroupOptions}。 群组的其他选项。

  • 群最大成员数,默认值为 200;
  • 群组类型,详见 EMGroupStyle,默认为 EMGroupStyle.PrivateOnlyOwnerInvite
  • 邀请进群是否需要对方同意,默认为 false,即邀请后直接进群;
  • 群组详情扩展。

Return 创建成功的群对象。

Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 EMError。 ~end

Implementation

Future<EMGroup> createGroup({
  String? groupName,
  String? desc,
  List<String>? inviteMembers,
  String? inviteReason,
  required EMGroupOptions options,
}) async {
  Map req = {'options': options.toJson()};
  req.putIfNotNull("groupName", groupName);
  req.putIfNotNull("desc", desc);
  req.putIfNotNull("inviteMembers", inviteMembers);
  req.putIfNotNull("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;
  }
}