Ad
Changing Display Name Takes Too Long. Flutter And FIrebase
I'm trying to make a list of my users and the display name takes a bit to change after update profile but by that time the list already has a null in the name section.
final User user = (await
_auth.createUserWithEmailAndPassword(
email: emailR,
password: passwordR,
)
).user;
user.updateProfile(displayName: usernameR);
emailc.clear();
passwordc.clear();
usernamec.clear();
DateTime now = DateTime.now();
String dt = "${now.day.toString().padLeft(2,'0')}/${now.month.toString().padLeft(2,'0')}/${now.year.toString()} ${now.hour.toString()}:${now.minute.toString()}";
FirebaseFirestore.instance.collection("users").doc(user.uid).set({
"id": user.uid,
"name": user.displayName,
"email": user.email,
"created_at": dt,
});
The reason why I think its a timing problem is because on my main page where it says the username the first time when I register, it'll show "hey, null" and every time after that it'll show the correct username.
Ad
Answer
The updateProfile
call is an asynchronous operation, and user.displayName
won't be updated until that operation has completed. Luckily it returns a Future
, so you can just use await
on the call to wait for it to complete, in the same way you already do for createUserWithEmailAndPassword
.
So:
await user.updateProfile(displayName: usernameR);
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad