I'm trying to delete the todos in the Map data-type (todoDate) I have created.
the Map<String, List> data type variable problem (todoDate) problem:
I want every key in the Map to be deleted but instead what happens is that only the key with index 0 is deleted and the rest remain. Thanks for helping.
String uid = FirebaseAuth.instance.currentUser!.uid.toString();
final todo =
FirebaseFirestore.instance.collection('users').doc(uid).collection('todos');
void Function()? deleteTodoCollection(Map<String, List<String>> todoDate) {
//delete from firebase
todo.get().then((snapshot) {
for (DocumentSnapshot doc in snapshot.docs) {
doc.reference.delete();
}
});
//delete from the todoDate map
for (var key in todoDate.keys) {
todoDate.remove(key);
print(todoDate);
}
return null;
}
CodePudding user response:
try toList()
...
for (var key in todoDate.keys.toList()) {
...