I have a collection named 'room', inside which I've a document named 'users', inside the doc I've another collection named 'users' inside which I've filed named 'userName'. I want to access the 'userName'
Heres what I've tried
StreamBuilder(
stream: FirebaseFirestore.instance.collection(widget.roomId).doc("users").collection("users").snapshots(),
builder: (context, newSnapshot){
final documents = newSnapshot.data?.docs;
if (newSnapshot.connectionState == ConnectionState.waiting){
return Text("WAITING");
}
return ListView.builder(
itemCount: documents?.length,
itemBuilder: (context, index) => Container(
height: 25,
child: Text(documents![index]["usersName"] ?? "nothing found"),
));
},
),
CodePudding user response:
Seems like you have misspelled the userName key in your text widget
child: Text(documents![index['usersName']??'Nothing found');
should be
child: Text(documents![index]['userName']??'Nothing found');