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.
Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.
Android Reference: UsersRequest.createUser(User user, String apiKey)
Implementation
static Future<User?> createUser(User user, String authKey,
{required Function(User user)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart user repository
final createdUser = await sdk.users.createUser(user, authKey);
// Call success callback
if (onSuccess != null) onSuccess(createdUser);
return createdUser;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}