createUser static method
Future<User?>
createUser(
- User user,
- String authKey, {
- required dynamic onSuccess(
- User user
- required dynamic onError(
- CometChatException excep
Method returns user after creation in cometchat environment
Ideally, user creation should take place at your backend
uid
specified on user creation. Not editable after that.
name
Display name of the user.
avatar
URL to profile picture of the user.
Implementation
static Future<User?> createUser(User user, String authKey,
{required Function(User user)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
final result = await channel.invokeMethod('createUser', {
'apiKey': authKey,
'uid': user.uid,
'name': user.name,
'link': user.link,
'tags': user.tags,
'avatar': user.avatar,
'statusMessage': user.statusMessage,
'metadata': user.metadata == null ? null : json.encode(user.metadata),
'role': user.role,
'lastActiveAt': user.lastActiveAt == null
? null
: user.lastActiveAt!.millisecondsSinceEpoch,
'hasBlockedMe': user.hasBlockedMe,
'blockedByMe': user.blockedByMe,
'status': user.status
});
final User res = User.fromMap(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;
}