I have an ordering application. after user create account i can see name and address in firebase table. How can I save the user’s name and address in firebase after clicking the place order button? Or is there another way to receive the order?
TextButton kayitButon(BuildContext context) {
return TextButton(
onPressed: () async {
AuthService().registerUser(kadi: nameController.text, sifre: sifreController.text, adres: adresController.text);
userData = {
"name": nameController.text,
"sifre": sifreController.text,
"adres": adresController.text
};
await kullaniciRef.doc(nameController.text).set(userData);
if (formkey.currentState!.validate()) {
formkey.currentState!.save();
try {
await fireBaseAuth.createUserWithEmailAndPassword(
email: kadi,
password: sifre,
);
formkey.currentState!.reset();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Kayıt İşlemi Başarılı"),
),
);
Navigator.pushReplacementNamed(context, "/loginpage");
} catch (e) {
print(e.toString());
}
}
},
child: Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: const Color.fromARGB(255, 83, 188, 83),
),
child: const Text(
"Kayıt Ol",
style: TextStyle(
color: Colors.white,
// fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
);
}
2
Answers
}
The then method is called when the order is saved successfully, and the catchError method is called if there’s an error during the saving process.
You can call this placeOrder function when the user clicks the "Place Order" button, passing the user’s name and address as arguments.
This approach allows you to store the user’s order information in Firebase Firestore, making it accessible for further processing or retrieval.