【问题标题】:The method 'updateProfile' isn't defined for the class 'FirebaseAuth'没有为“FirebaseAuth”类定义方法“updateProfile”
【发布时间】:2020-09-10 21:05:35
【问题描述】:

我想更改用户个人资料(用户名和照片)。但它给出了错误没有为类“FirebaseAuth”定义方法“updateProfile”。这是代码

onPressed: (){
                    var createUserWithEmailAndPassword = FirebaseAuth.instance.
                    createUserWithEmailAndPassword(

                      email: _email,
                       password: _password);
                    createUserWithEmailAndPassword.then((signedInUser){
                        var userUpdateInfo = new UserUpdateInfo();
                        userUpdateInfo.displayName = _userName;
                        userUpdateInfo.photoUrl='https://www.google.com/url?sa=i&url=https%3A%2F%2Forangefootballclub.com%2Fen%2Farticles%2Fcristiano-ronaldo-says-will-fight-to-win-champions-league-for-juventus%2F&psig=AOvVaw3W_YulXC1W9I_Hpf0njprF&ust=1590379669136000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCOj-3ZDQy-kCFQAAAAAdAAAAABAJ';
                       FirebaseAuth.instance.updateProfile(userUpdateInfo).
                       then((user){
                       FirebaseAuth.instance.currentUser().then((user){
                       UserManagement().storeNewUser(signedInUser.user, context);
                       }).catchError((e){
                           print(e);
                       });
                       }).catchError((e){
                           print(e);
                       });


                       }).catchError((e){
                         print(e.toString());
                       });

                  },

请告诉我纠正此代码的方法

【问题讨论】:

  • 抱歉,我的回答似乎有些错误,现在可以了吗?

标签: firebase flutter dart firebase-authentication user-profile


【解决方案1】:

FirebaseAuth.instance 返回 FirebaseAuth 类的实例。您必须获取当前用户,然后更新配置文件。

Firebase.auth.currentUser

这将返回当前用户

替换这个

FirebaseAuth.instance.updateProfile(userUpdateInfo)

FirebaseAuth.instance.currentUser.updateProfile(userUpdateInfo)

如文档中所述

https://firebase.google.com/docs/auth/android/manage-users#kotlin+ktx

【讨论】:

    猜你喜欢
    • 2019-06-24
    • 2021-06-26
    • 2019-08-14
    • 2021-05-24
    • 2020-05-21
    • 2020-09-23
    • 1970-01-01
    • 2023-01-25
    • 2021-04-14
    相关资源
    最近更新 更多