简体   繁体   English

Flutter - 无法将数据保存到 Firebase Firestore

[英]Flutter - Unable to save data to Firebase Firestore

I'm building an app with Flutter.我正在用 Flutter 构建一个应用程序。 On the registration page I create account with Auth and try to save user's information with Firestore.在注册页面上,我使用 Auth 创建帐户并尝试使用 Firestore 保存用户信息。 User account is created with Auth but I cannot open a document for user information in Firestore.用户帐户是使用 Auth 创建的,但我无法在 Firestore 中打开用户信息文档。

My codes:我的代码:

await _auth.createUserWithEmailAndPassword(
  email: _emailController.text,
  password: _passwordController.text,
);
inspect("user ID: " + _auth.currentUser!.uid);
_firestore.collection("Users").doc(_auth.currentUser!.uid).set({
  "ID": _auth.currentUser!.uid,
  "Email": _emailController.text,
  "Phone": _phoneController.text,
  "Name": _nameController.text,
  "Surname": _surnameController.text,
  "Photo": "https://firebasestorage.googleapis.com/v0/b/teen-software-stock-tracking.appspot.com/o/default.jpg?alt=media&token=0eec2e1f-2ccf-4bda-8664-3d3f018621b3",
  "Level": 0,
  "ProductRight": 10,
  "AddedProduct": 0,
  "AccountCreate": FullDate.toString(),
});
_auth.signOut();

Why could this be?为什么会这样? I would be glad if you help.如果你能帮忙,我会很高兴。 Thanks in advance for your help.在此先感谢您的帮助。

Try await on storing the data to Firestore.尝试等待将数据存储到 Firestore。

await _firestore.collection("Users").doc(_auth.currentUser!.uid).set({
  "ID": _auth.currentUser!.uid,
  "Email": _emailController.text,
  "Phone": _phoneController.text,
  "Name": _nameController.text,
  "Surname": _surnameController.text,
  "Photo": "https://firebasestorage.googleapis.com/v0/b/teen-software-stock-tracking.appspot.com/o/default.jpg?alt=media&token=0eec2e1f-2ccf-4bda-8664-3d3f018621b3",
  "Level": 0,
  "ProductRight": 10,
  "AddedProduct": 0,
  "AccountCreate": FullDate.toString(),
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM