updateUser static method
Future<User?>
updateUser(
- User user,
- String apiKey, {
- required dynamic onSuccess(
- User retUser
- required dynamic onError(
- CometChatException excep
Updating a user similar to creating a user should ideally be achieved at your backend using the Restful APIs
user
a user object which user needs to be updated.
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<User?> updateUser(User user, String apiKey,
{required Function(User retUser)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
final result = await channel.invokeMethod('updateUser', {
'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),
'apiKey': apiKey,
'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 user;
} on PlatformException catch (p) {
_errorCallbackHandler(null, p, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}