简体   繁体   English

flutter有没有添加/更新firebase用户名和照片url的功能?

[英]Is there any feature to add/update firebase user name and photo url in flutter?

Is there anyway to add/update firebase user name and photo url in flutter like we have UserProfileChangeRqeust() in native android?无论如何要在 flutter 中添加/更新 firebase 用户名和照片 url,就像我们在原生 android 中有UserProfileChangeRqeust()一样?

Yes, there is.就在这里。

After you have received FirebaseUser , you can call the updateProfile() method on the object to provide the new details.This method will take an input of type UserUpdateInfo .收到FirebaseUser ,您可以调用对象上的updateProfile()方法以提供新的详细信息。此方法将接受UserUpdateInfo类型的输入。

For eg.,例如,

FirebaseUser user = await _auth.currentUser();

UserUpdateInfo userUpdateInfo = UserUpdateInfo();

userUpdateInfo.displayName = 'Ayush';
userUpdateInfo.photoUrl = '<my photo url>';

await user.updateProfile(userUpdateInfo);

UPDATE 2021, FEB 2021 年 2 月更新

This is the updated way for changing the users displayName and photoURL这是更改用户displayNamephotoURL的更新方式

 void updateUserInfo() {
   var user = FirebaseAuth.instance.currentUser;
   user.updateProfile(displayName: "Abel", photoURL: "photoPath").then((value){
      print("Profile has been changed successfully");
      //DO Other compilation here if you want to like setting the state of the app
   }).catchError((e){
      print("There was an error updating profile");
   });
 }

you can read more about this on the official firebase flutter doc.您可以在官方 firebase flutter doc 上阅读更多相关信息。 here 这里

UPDATE MARCH 2022. VERSIONS: 2022 年 3 月更新。版本:

firebase_core: ^1.13.1

firebase_auth: ^3.3.10

final FirebaseAuth _auth = FirebaseAuth.instance;

User? currentUser = await _auth.currentUser;
currentUser?.updateDisplayName("name...");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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