I tried fetching the data without using the StreamBuilder
and all the data was fetched successfully but when I used the StreamBuilder
it didn't work
StreamBuilder(
stream: Firestore.instance.collection('chats/IClRN96vdYSpdtfT4PZh/messeges').snapshots(),
builder: (ctx , snap) {
if(snap.connectionState == ConnectionState.waiting){
return Center(child: CircularProgressIndicator(),);
}
return ListView.builder(
itemCount: snap.data.documents.length,
itemBuilder: (ctx, i) => Container(
padding: EdgeInsets.all(10),
child: Text('Text Chat messeges'),
));
})
CodePudding user response:
replace snap.data.documents.length
with snap.data.docs.length
CodePudding user response:
add AsyncSnapshot<QuerySnapshot>
to snap
StreamBuilder(
stream: Firestore.instance.collection('chats/IClRN96vdYSpdtfT4PZh/messeges').snapshots(),
builder: (ctx , AsyncSnapshot<QuerySnapshot> snap) {
if(snap.connectionState == ConnectionState.waiting){
return Center(child: CircularProgressIndicator(),);
}
return ListView.builder(
itemCount: snap.data!.documents.length,
itemBuilder: (ctx, i) => Container(
padding: EdgeInsets.all(10),
child: Text('Text Chat messeges'),
));
})
**And before the documents
put !
**