Reputation: 59
i have one question, i have created 1 docs that have id using Uuid().v4(), i want to know how do i call that docs using that id because i want to update the data inside that docs on the next page. Below is my code to create the docs. Before this i only try to update the user data and it was quite easy because i can use firebaseauth to get the id and i am not sure how to get data from other docs.
_payment() async {
if (balance >= price!) {
try {
final FirebaseAuth _auth = FirebaseAuth.instance;
User? user = _auth.currentUser;
final _uid = user!.uid;
final transactionId = Uuid().v4();
await FirebaseFirestore.instance
.collection('transaction')
.doc(transactionId)
.set({
'transactionId': transactionId,
'clientId': _uid,
'freelancerId': widget.uploadedBy,
'jobTitle': jobTitle,
'price': price,
'status': status,
});
await FirebaseFirestore.instance
.collection("users")
.doc(_uid)
.update({"balance": balance - price!});
} catch (error) {}
}
}
Upvotes: 0
Views: 45
Reputation: 1583
Split your expression into 3 parts.
The first part for getting document reference
final document = await FirebaseFirestore.instance
.collection('transaction')
.doc('transactionId');
Second, fill your document with data
document.set({
'transactionId': transactionId,
'clientId': _uid,
'freelancerId': widget.uploadedBy,
'jobTitle': jobTitle,
'price': price,
'status': status,
});
The last one is retrieving the document id
final documentId = document.id;
Upvotes: 1