Firebase can not change displayName ,displayName is null on every way

1,982

You are saving data in Firestore, and trying to get the name from Firebase Auth. Those are two services. Instead of trying to use firestore, what you could is,

    FirebaseUser firebaseUser = await FirebaseAuth.instance.currentUser();
    var userUpdateInfo = UserUpdateInfo();
    userUpdateInfo.displayName = _name;
    firebaseUser.updateProfile(userUpdateInfo);
    await firebaseUser.reload();
    firebaseUser = await FirebaseAuth.instance.currentUser();
Share:
1,982
Asgar
Author by

Asgar

Updated on December 20, 2022

Comments

  • Asgar
    Asgar over 1 year

    Can't add I more user information with await FirebaseAuth.instance .createUserWithEmailAndPassword(email: _email, password: _password); function?

    part of signup.dart file:

     String _email, _password, _name;
    
      final formkey = new GlobalKey<FormState>();`
    
      Future<void> registered() async {
        if (formkey.currentState.validate()) {
          formkey.currentState.save();
          try {
            await FirebaseAuth.instance
                .createUserWithEmailAndPassword(email: _email, password: _password);
            FirebaseUser firebaseUser = await FirebaseAuth.instance.currentUser();
            Firestore.instance
                .collection("users")
                .document(firebaseUser.uid)
                .setData({"name": _name});
            await firebaseUser.reload();
            firebaseUser = await FirebaseAuth.instance.currentUser();
            print(
                "${firebaseUser.uid},${firebaseUser.email},${firebaseUser.displayName} , $_password this user has been created-----");
          } catch (e) {
            print("${e.message} message--------------------------------------");
          }
        } else {
          print("somthing went wrong");
        }
      }
    

    I have tried many way to do this but still i have no result

  • Asgar
    Asgar about 4 years
    i didn't get what i exactly to do.there isn't something like creating user with more fields in that video.
  • SHARAN RAJ S
    SHARAN RAJ S about 4 years
    Thats a playlist.... you can skip some of the content in it to go to your part...youtube.com/…