未为“UserCredential”类型定义 getter“uid”

时间:2021-07-29 09:38:51

标签: firebase flutter dart firebase-authentication flutter-dependencies

我在集成 firebase 电子邮件、密码注册时遇到了这个错误。 “没有为‘UserCredential’类型定义 getter uid。”不仅适用于 uid,还适用于 displayNmaeemail。有人可以帮我吗?

void ValidateForm() async {
  FormState? formState = _formkey.currentState;
    Map value;
   if (formState!.validate()) {
       User user = await firebaseAuth.currentUser!;
   if (user == null) {
       firebaseAuth
          .createUserWithEmailAndPassword(
              email: _emailTextController.text,
              password: _passwordTextController.text)
          .then((user) => {
                _userServices.createUser(
                  user.uid,
                  {
                    "username": user..displayName,
                    "email": user.email,
                    "userId": user.uid,
                    "gender": gender,
                  },
                ),
              })
          .catchError((err) => {print(err.toDtring())});
      Navigator.pushReplacement(
          (context), MaterialPageRoute(builder: (context) => a_n()));
      }
    }
  }                                                                                                                                                                                                                                                                                                                                                              

1 个答案:

答案 0 :(得分:1)

您的 user 值是一个 UserCredential 对象,要获取 uid,您需要访问其中的 user

  "userId": user.user.uid