【发布时间】:2020-04-08 15:24:00
【问题描述】:
我正在尝试从注册页面对新注册的用户进行身份验证,并在他们通过身份验证后将其添加到我的 cloud-firestore 数据库中。目前,用户已通过身份验证,并且代码在该阶段运行良好。但是,它们不会添加到 cloud-firestore 数据库中。请帮忙!
Container(
width: 150.0,
child: FlatButton(
child: Text('Sign Up'),
color: Colors.grey,
onPressed: () {
if (_registerFormKey.currentState.validate()) {
if (pwdInputController.text ==
confirmPwdInputController.text) {
FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: emailInputController.text,
password: pwdInputController.text)
.then((currentUser) => Firestore.instance
.collection("users")
.document(currentUser.user.uid)
.setData({
"uid": currentUser.user.uid,
"first-name":
firstNameInputController.text,
"last-name":
lastNameInputController.text,
"email": emailInputController.text,
'password': pwdInputController.text,
})
.then((result) => {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) =>
MyApp()),
(_) => false),
firstNameInputController.clear(),
lastNameInputController.clear(),
emailInputController.clear(),
pwdInputController.clear(),
confirmPwdInputController.clear()
})
.catchError((err) => print(err)))
.catchError((err) => print(err));
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Error"),
content:
Text("The passwords do not match"),
actions: <Widget>[
FlatButton(
child: Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
}
},
),
),
【问题讨论】:
-
你有没有打印在控制台上的日志?
-
不,我不知道。 :-(
-
我还注意到它没有重定向到主页 - MyApp()
-
打印firestore插入后的结果,看看返回值是什么
-
我该怎么做?
标签: firebase flutter google-cloud-firestore