[!Here is the code where i got an error, I could not use [] for this code
return ListView.builder(
reverse: true,
itemCount: chatDocs?.length,
itemBuilder: (ctx, index) => MessageBubble(
chatDocs[index].data()['text'],
chatDocs[index].data()['username'],
chatDocs[index].data()['userImage'],
chatDocs[index].data()['userId'] == user.uid,
),
// Container(
// padding: const EdgeInsets.all(8),
// child: Text(chatDocs?[index]['text']),)
);
I also tried null check and ‘as Map’ to chat-Docs, But both are didnot work
3
Answers
add
.toList()
in chatDocs declaration lineso it becomes like this:
.map
returns anIterable
which doesn’t have the[]
operator. You can solve this by turning it into a list by callingtoList()
on it. SoBut it looks like your
map()
is already wrong. Note the error there. Do you really need to map it? If not then this already should workOr actually this to handle it in case it’s
null
You can use this way,