At this point, I'm spinning my wheels, but going nowhere and could use some help. I have an array/List of weekdays that I want to disable on my calendar using the enabledPredicateDay function. for example ['sunday', 'monday', 'tuesday'].
return TableCalendar(
calendarBuilders: CalendarBuilders(dowBuilder: (context, day) {
if (day.weekday == DateTime.sunday) {
final text = DateFormat.E().format(day);
return Center(
child: Text(
text,
style: TextStyle(color: Colors.red),
),
);
}
}),
firstDay: kFirstDay,
lastDay: kLastDay,
focusedDay: _focusedDay,
calendarFormat: _calendarFormat,
enabledDayPredicate: (date) {
// this is where we disable any days that the user is not available OR is booked up
var disabledDays = "";
unavailableDays.asMap().forEach((index, value) {
if (index == 0) {
disabledDays = disabledDays + "date.weekday != DateTime.$value";
} else {
disabledDays = disabledDays + " && date.weekday != DateTime.$value";
}
});
date.weekday != disabledDays; // here I'm trying to get some sort of boolean back.
return date.weekday != disabledDays;
}
The problem I'm running into is that I can either only return one day programmatically, let's say in a 'for in' loop, or I need to hardcode it. This is because the return value needs to be a boolean.
I tried combining everything into a string and then converting it to a method so that each day I need disabled can be the return statement like this:
return date.weekday != DateTime.$value && date.weekday != DateTime.$value && date.weekday != DateTime.$value
Everything works fine if I hardcode it like this:
return date.weekday != DateTime.sunday && date.weekday != DateTime.monday && date.weekday != DateTime.tuesday
But I haven't been able to get to this point because I'm getting a string back, but I need a bool.
How do I return multiple days to this particular function?