I made what I believe were the correct changes, however, now I'm getting an error that says I can't use forEach here because it may return null. I can't force it by using '!' because then I get another error about not being able to because the method 'forEach' isn't defined for the type 'Object'.
void loadStudentList(){
// function that loads all students from firebase database and display them in list view
FirebaseDatabase.instance.ref("students").once()
.then((databaseEvent) {
print("Successfully loaded the data");
print(databaseEvent);
print("Key:");
print(databaseEvent.snapshot.key);
print("value:");
print(databaseEvent.snapshot.value);
print("Iterating the value map");
var studentTmpList = [];
databaseEvent.snapshot.value!.forEach((k, v) {
print(k);
print(v);
studentTmpList.add(v);
});
print("Final student list");
print(studentTmpList);
studentList = studentTmpList;
setState(() {
});
}).catchError((error) {
print("Failed to load the data");
print(error);
});
}