0
votes

I am new to flutter and I can't get firebase updateProfile function work

I created a user through the console and tried to update the user info through code in flutter web application. I created userprofile instance:

UserProfile fbP = UserProfile();
fbP.displayName = "Youmna";
fbP.photoURL = "";

And passed it to updateProfile function:

authFB.currentUser.updateProfile(fbP);

--authFB is my Firebase.Auth attribute

And I reloaded the user

authFB.currentUser.reload();

And then I tried to print the display name, but it gave me null!

print(authFB.currentUser.displayName);

However I tried to print the email and it printed it correctly.

print(authFB.currentUser.email);

What shall I do, please?

1

1 Answers

0
votes

Perhaps, you have missed async/await keywords. Use them as in this example:

import 'package:firebase/firebase.dart' as fb;

...

  void updateProfile() async {
    final profile = fb.UserProfile();
    profile.displayName = 'Another Name';
    profile.photoURL = '';
    final user = fb.auth().currentUser;
    await user.updateProfile(profile);
    await user.reload();
    print(user.displayName);
  }