I have this code
Stream<List<Ticket>> readTicket() => FirebaseFirestore.instance
.collection('tickets')
.where("added_by", isEqualTo: member?.uid)
.snapshots()
.map(
(snapshots) => snapshots.docs
.map(
(doc) => Ticket.fromJson(
doc.data(),
),
)
.toList(),
);
It does exactly want I wanted to do but I want the one that will return a single document from database instead of list of documents.
Here is the UI
StreamBuilder<List<Ticket>>(
stream: TicketController().readTicket(),
builder: (context, snapshot) {
//.......
}
);
I want this code to fetch only the first document and not the list of documents.
2
Answers
Try
Then in your UI
To fetch one doucment try this code snippet;
suppose this is your ticket Model class:
Create Stream method like below:
}
Now call readTicket method check code snippet