Faseeh Hyder
Faseeh Hyder

Reputation: 73

I'm having issue with null safety in my todo app

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

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

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

Related Questions