Reputation: 35
I have a recipes collection from different users. I'm referencing the author of the recipe by authorId, and I need to display the author firstName alongside with the recipe
ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot ds = snapshot.data.documents[index];
if ('${ds['authorId']}' != null) {
String authorName="";
String authorId='${ds['authorId']}';
print(authorId);
Firestore.instance.collection('Authors').document(authorId).get().then((author){
print(author.data);
if(author.data!=null)authorName=author.data["firstName"];
});}
The authorId is printed OK, but author.data is always null Is it possible to get data from another document inside a builder?
Upvotes: 1
Views: 856
Reputation: 5439
I think you are missing .data
after snapshot.data.documents[index]
in line 4.
Upvotes: 1