I'm getting a "NoSuchMethodError: The method 'get' was called on null. Receiver: null Tried calling: get("legpressReps")"
This is my calender log class which accesses documents which based on a specific sport name and time that is entered.
class CalendarLog {
getCalendarLog(String sportName, Timestamp date) {
return FirebaseFirestore.instance
.collection('users')
.where('sport', isEqualTo: sportName)
.get();
}
}
This is where I override the initState to access the documents which have a sport name 'weightlifting' and date set to 10-27-2021
bool calendarLogFlag = false;
var calendarLogs;
@override
void initState(){
super.initState();
DateTime date1 = DateTime.utc(2021, 10, 27);
Timestamp date = Timestamp.fromDate(date1);
CalendarLog().getCalendarLog('weightlifting', date).then((QuerySnapshot docs){
if(docs.docs.isNotEmpty){
calendarLogFlag = true;
calendarLogs = docs.docs[0];
}
});
When we try to display a data field in the home page, this is how we are trying to access it:
label: Text(calendarLogs.get('legPressReps') ?? 0),