I’m trying to get DocumentSnapshot from collection
this my code
Stream<QuerySnapshot> streamState() => collectionRef.snapshots();
return StreamBuilder<QuerySnapshot>(
stream: auth.streamState(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if (snapshot.hasData){
DocumentSnapshot doc = snapshot.data!.docs.elementAt(0);
print(doc.id);
}
return Container(
color: Colors.white,
);
}
);
it work fine but as you see I use elementAt(0)
I want to get doc by its id
I try with docs.where but fail.
3
Answers
The data that you are getting from auth.streamState() is I suppose about authentication? You should get it by id there probably
If you know the ID of the document you want to listen to, you can do:
And then the
StreamBuilder
becomes:it will return all documents