简体   繁体   中英

How to add additonal user data like displayName in firebase using flutter?

Future<bool> signupwithemail(
    String emailS, String passwordS, String nameS) async {
  AuthResult result = await _auth.createUserWithEmailAndPassword(
      email: emailS, password: passwordS);
  FirebaseUser user = result.user;
  var info = new UserUpdateInfo();
  info.displayName = nameS;
  await user.updateProfile(info);
  await user.reload();
  uid = user.uid;
  email = user.email;
  name = user.displayName;
}

my implementation doesnt work,i always get the name as null,can someone point out my error

You are getting the name of the old user not the updated one

try this:

            UserUpdateInfo userUpdateInfo = UserUpdateInfo()..displayName='hello';
            await user.updateProfile(userUpdateInfo);
            print('current user is ${(await _firebaseAuth.currentUser()).displayName}');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM