I'm having issues with getting messages fetched from Firebase Cloud Firestore. The error being displayed is: 'Error: The getter 'docs' isn't defined for the class 'Object' - 'Object' is from 'dart:core'.'
Below is my code:
class ChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder<Object>(
stream: FirebaseFirestore.instance
.collection('chats/EKLJIb8ZfRoDTqxkkJaB/messages')
.snapshots(),
builder: (context, chatSnapshot) {
return ListView.builder(
itemCount: chatSnapshot.data.**docs**.length,
itemBuilder: (ctx, index) => Container(
padding: EdgeInsets.all(8),
child: Text('this work'),
),
);
}),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: null,
),
);
}
}