Reputation: 441
I want the app to save the displayName
while user signing up
I've tried:
Future<void> signUp() async {
try {
FirebaseUser user = (await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email.text, password: password.text))
.user;
UserUpdateInfo userUpdateInfo = new UserUpdateInfo();
userUpdateInfo.displayName = name.text;
await user.reload();
showInSnackBar("User name ${user.displayName}");
try {
await user.sendEmailVerification();
showInSnackBar("Email verification sent");
} catch (e) {
print(e);
}
} catch (e) {
String errorCode = e.code;
print(e);
if (errorCode == "ERROR_EMAIL_ALREADY_IN_USE") {
showInSnackBar("This email is already in use");
} else {
showInSnackBar("Somthing went wrong! Try again later");
}
}
}
with this method, SnakBar
returns a null for displayName
Upvotes: 0
Views: 1140
Reputation: 317497
Setting userUpdateInfo.displayName = name.text
isn't enough to actually change the name on the user account. You have to call updateProfile() and pass it that UserUpdateInfo object in order to actually change the account.
await user.updateProfile(userUpdateInfo)
Upvotes: 2