Emir Bolat
Emir Bolat

Reputation: 1049

Flutter - Unable to save data to Firebase Firestore

I'm building an app with Flutter. On the registration page I create account with Auth and try to save user's information with Firestore. User account is created with Auth but I cannot open a document for user information in 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.

Upvotes: 0

Views: 520

Answers (1)

Rohit Krishna
Rohit Krishna

Reputation: 202

Try await on storing the data to 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(),
});

Upvotes: 2

Related Questions