简体   繁体   English

Flutter/Firebase/Firestore - 注册不会将数据推送到数据库

[英]Flutter/Firebase/Firestore - Signup not pushing data to database

I am trying to record some additional user data when they sign up to my app.当他们注册我的应用程序时,我试图记录一些额外的用户数据。 My signup process looks like this:我的注册过程如下所示:

    String ref = "users";
    Future<bool> signUp(
    String email,
    String password,
    String firstName,
    String lastName,
  ) async {
    try {
      _status = Status.Authenticating;
      notifyListeners();
      await    _auth
          .createUserWithEmailAndPassword(email: email, password: password);
      FirebaseFirestore.instance.collection(ref).doc(user.uid).set({
        'id': user.uid,
        'displayName': firstName.trim() + " " + lastName.trim(),
        'email': email.trim(),
        'createdat': DateTime.now()
      });
      return true;
    } catch (e) {
      _status = Status.Unauthenticated;
      notifyListeners();
    } return false;
  }

I can't work out why, when the user enters their data and signs up, the specified values aren't pushed to firestore.我不明白为什么当用户输入他们的数据并注册时,指定的值不会被推送到 firestore。 Can someone help me out?有人可以帮我吗? Thanks.谢谢。 Here is where I have implemented my code:这是我实现我的代码的地方:

           child: RaisedButton(
                      child: Text('Create an Account', style: TextStyle(color: Colors.white),),
                      onPressed: ()  async {
                        if (validate()) {
                          _formKey.currentState.reset();
                          user.signUp(_emailController.text, _passwordController.text, _firstNameController.text, _lastNameController.text);
                          Navigator.pushReplacement(
                              context, MaterialPageRoute(builder: (context) => Home()));
                        }
                      }),

So, as mentioned in the comments, it should be like this:所以,正如评论中提到的,它应该是这样的:

  await FirebaseFirestore.instance.collection(ref).doc(user.uid).set({
    'id': user.uid,
    'displayName': firstName.trim() + " " + lastName.trim(),
    'email': email.trim(),
    'createdat': DateTime.now()
  });

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

相关问题 更新 Flutter Firebase 的 Firestore 数据库中的嵌套数据 - Updating Nested Data in Flutter Firebase's Firestore database 如何从 Flutter firebase firestore 数据库中获取这些数据? - How to get this data from Flutter firebase firestore database? 将日期和时间选择器数据保存到 Flutter 中的 Firebase Cloud Firestore 数据库中 - Save date and time picker data into Firebase Cloud Firestore database in Flutter Firebase 电话号码 OTP 身份验证可用于在 Flutter 的 Firestore 数据库中创建用户(注册/注册)吗? 如果是,如何? (安卓) - Can Firebase phone number OTP auth be used for creating a user (registration/signup) in Firestore database in Flutter? If yes, how? (android) Flutter Firebase firestore.data[“”] 错误 - Flutter Firebase firestore .data[“”] error 在Firebase Firestore数据库上进行Dart / Flutter验证/验证 - Dart/Flutter verification/validation on Firebase Firestore database 在没有 ID 的情况下将数据推送到 Firebase 数据库 - Pushing Data into Firebase Database without ID 无法使用flutter和firebase将数据写入firestore - Failing to write data to firestore using flutter and firebase 在 Flutter 的 Firebase Firestore 中的事务中保存数据的问题 - Problem with saving data in Transaction in Firebase Firestore for Flutter Flutter - 无法将数据保存到 Firebase Firestore - Flutter - Unable to save data to Firebase Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM