Reputation: 73
I'm trying to assign values but flutter is showing null safety error...
List<Todo> todoFromFirestore(QuerySnapshot snapshot) {
if (snapshot != null) {
return snapshot.docs.map((e) {
return Todo(
isComplet: e.data()["isComplet"],
title: e.data()["title"],
uid: e.id,
);
}).toList();
} else {
return [];
}
}
Upvotes: 0
Views: 44
Reputation: 63669
Try this way
List<Todo> todoFromFirestore(QuerySnapshot snapshot) {
if (snapshot != null) {
return snapshot.docs.map((e) {
final map = e.data() as Map?;
return Todo(
isComplet: map?["isComplet"] ?? false,
title: map?["title"] ?? "null",
uid: e.id,
);
}).toList();
} else {
return [];
}
}
Upvotes: 2