0

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) {}
    }
  }

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.