So I am making a custom function for my timetable app. It is given the list of a custom data type lessonBlock (string name, dateTime startTime, dateTime endTime) as well as the current time in dateTime. When trying to use .isBefore and .isAfter to check if the current time is in between the start and end times, FlutterFlow the following error [The argument type 'DateTime?' can't be assigned to the parameter type 'DateTime'.]
My function settings and code are as below.
Any help would be appreciated ๐
List<LessonBlockStruct> why(
DateTime? currentTime,
List<LessonBlockStruct>? listOfLessons,
) {
/// MODIFY CODE ONLY BELOW THIS LINE
int currentLessonIndex = 0;
if (currentTime.isBefore(listOfLessons[0].startTime)) {
// Return the original list if the current time is before the start time of the first lesson
return listOfLessons;
} else {
while (currentLessonIndex < listOfLessons.length) {
if (currentTime.isAfter(listOfLessons[currentLessonIndex].startTime) &&
currentTime.isBefore(listOfLessons[currentLessonIndex].endTime)) {
listOfLessons.removeRange(0, currentLessonIndex);
break;
}
currentLessonIndex++;
}
}
return listOfLessons;
/// MODIFY CODE ONLY ABOVE THIS LINE
}