Error text:
Null check operator used on a null value The relevant error-causing widget was StreamBuilder<List>
ChangeNotifierProvider(
create: (context) => getIt<ModelCreator>(),
child: StreamBuilder(
stream: getIt<ModelCreator>().chatList(),
builder: (context, AsyncSnapshot<List<ChatModel>> snapshot) {
var _data = snapshot.data!; <- The error is here
return Container();
}),
),
There is no problem with empty Container, that part is full.
Thats getChatList() func
Stream<List<ChatModel>> getChatList() {
var data = _firebase
.collection('Users')
.doc(_fireauth.currentUser!.uid)
.collection('Chat List')
.orderBy('Last Message Date', descending: true);
return data.snapshots().map(
(event) => event.docs.map((e) => ChatModel.fromSnapshot(e)).toList());
}
Thats it ChatModel
factory ChatModel.fromSnapshot(
QueryDocumentSnapshot<Map<String, dynamic>> doc) {
return ChatModel(
id: doc.id,
image: doc['Image'],
phone: doc['Phone'],
photo: doc['Photo'],
username: doc['Username'],
createdDate: doc['Created Date'],
displayMessage: doc['Display Message'],
lastMessageDate: doc['Last Message Date'],
);
}