【问题标题】:Is there any feature to add/update firebase user name and photo url in flutter?是否有任何功能可以在颤振中添加/更新 firebase 用户名和照片 url?
【发布时间】:2020-01-12 03:35:53
【问题描述】:

有没有像我们在原生 android 中使用 UserProfileChangeRqeust() 一样在颤振中添加/更新 firebase 用户名和照片 url?

【问题讨论】:

    标签: firebase flutter dart firebase-authentication


    【解决方案1】:

    是的,有。

    收到FirebaseUser 后,您可以在对象上调用updateProfile() 方法以提供新的详细信息。此方法将接受UserUpdateInfo 类型的输入。

    例如,

    FirebaseUser user = await _auth.currentUser();
    
    UserUpdateInfo userUpdateInfo = UserUpdateInfo();
    
    userUpdateInfo.displayName = 'Ayush';
    userUpdateInfo.photoUrl = '<my photo url>';
    
    await user.updateProfile(userUpdateInfo);
    

    【讨论】:

    • UserUpdateInfo 在最新版本的 Firebase 身份验证中已弃用。请更新答案。
    【解决方案2】:

    2021 年 2 月更新

    这是更改用户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");
       });
     }
    

    您可以在官方 firebase flutter 文档中阅读更多相关信息。 here

    【讨论】:

      猜你喜欢
      • 2021-04-27
      • 2021-12-11
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      • 2020-10-03
      • 1970-01-01
      相关资源
      最近更新 更多