1
votes

I want to add a user's DisplayName upon creating a new user. When I tried to use updateProfile method, it gives below warning

/// Updates a user's profile data.

@Deprecated( 'Will be removed in version 2.0.0. ' 'Use updatePhotoURL and updateDisplayName instead.',

How can get around this ??

      String email, String password) async {
    final UserCredential userCredential =
        await _firebaseAuth.createUserWithEmailAndPassword(
            email: email.trim(), password: password.trim());
    await userCredential.user.updateDisplayName('Mohamed Rahuman');
    User user = userCredential.user;
    print(user);
    return _userFromFirebaseUser(user);
  }

flutter: User(displayName: null, email: [email protected], emailVerified: false, isAnonymous: false, metadata: UserMetadata(creationTime: 2021-06-06 10:35:13.689, lastSignInTime: 2021-06-06 10:35:13.689), phoneNumber: null, photoURL: null, providerData, [UserInfo(displayName: null, email: [email protected], phoneNumber: null, photoURL: null, providerId: password, uid: [email protected])], refreshToken: , tenantId: null, uid: gghhhhhhhh55555666)

THIS IS FIXED: with firebase_auth 1.3.0 (see the Changelog)

2
Try to call reload() (pub.dev/documentation/firebase_auth/latest/firebase_auth/User/…) before print statement like this: await userCredential.user.reload()Simon Sot
Hi Simon, I tried your solution, still getting null,developer-rahul
There was an issue with updating User.updateDisplayName and User.updatePhotoURL, now with firebase_auth 1.3.0 they have fixed that bug...developer-rahul

2 Answers

1
votes

Had the same issue. Solved by calling:

await user.reload();
user = await _auth.currentUser;

this is the full code snippet:

UserCredential result = await _auth.createUserWithEmailAndPassword(
          email: email, password: password);
User? user = result.user;
if (user != null) {
   //add display name for just created user
   user.updateDisplayName(displayName);
   //get updated user
   await user.reload();
   user = await _auth.currentUser;
   //print final version to console
   print("Registered user:");
   print(user);
}
0
votes

The cause of this issue was displayName and photoURL is unable to be set to null. More details are discussed here. As you've mentioned, this issue should be fixed as of version 1.3.0.

To fetch the display name configured during Registration, you can fetch by calling currentUser on your FirebaseAuth instance.

var currentUser = FirebaseAuth.instance.currentUser;
debugPrint('${currentUser.displayName}');