[英]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.