Reputation: 683
The following code throws this error "The method '[]' can't be unconditionally invoked because the receiver can be 'null'"
if (snapshot.hasData == true) {
return ListView(
children: snapshot.data!.docs.map((DocumentSnapshot document) {
return ListTile(
title: Text(document.data()['title']),
);
}).toList(),
);
}
Is it related to null-safety? how to fix it?
Upvotes: 2
Views: 827
Reputation: 683
This problem is related to a Flutter update.
In the newest Flutter update, there is no need in adding the .data()
.
Removing the.data()
from the code in the description solves the issue.
Upvotes: 8