createGroup method
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 ChatMultiDeviceEventHandler to listen for the event. If an event occurs, the callback function ChatMultiDeviceEventHandler.onGroupEvent is triggered, where the first parameter is the event which is ChatMultiDevicesEvent.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 ChatGroupOptions.
The options are as follows:
- The maximum number of group members. The default value is 200.
- The group style. See ChatGroupStyle. The default value is ChatGroupStyle.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 ChatError.
Implementation
Future<ChatGroup> createGroup({
String? groupName,
String? desc,
List<String>? inviteMembers,
String? inviteReason,
required ChatGroupOptions 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 {
ChatError.hasErrorFromResult(result);
return ChatGroup.fromJson(result[ChatMethodKeys.createGroup]);
} on ChatError catch (e) {
throw e;
}
}