I have a method like following:
void reverseWeekdayStatus({alarmClock,sundayIsSelected}){
alarmClock.sundayIsSelected = !alarmClock.sundayIsSelected ?? false;
update();
}
alarmClock is a model:
class AlarmClock {
bool sundayIsSelected;
bool mondayIsSelected;
bool tuesdaySelected;
bool wednesdayIsSelected;
bool thursdayIsSelected;
bool fridayIsSelected;
bool saturdayIsSelected;
AlarmClock({
this.sundayIsSelected = false,
this.mondayIsSelected = false,
this.tuesdaySelected = false,
this.wednesdayIsSelected = false,
this.thursdayIsSelected = false,
this.fridayIsSelected = false,
this.saturdayIsSelected = false,
});
}
so for this method I want to not just sundayIsSelected also the rest like mondayIsSelected could be reversed if I implement this method, what I did is following:
void reverseWeekdayStatus({alarmClock,whichDay}){
alarmClock.whichDay = !alarmClock.whichDay ?? false;
update();
}
And pass mondayIsSelected for example to whichDay, and then I got an error since whichDay does not exist in alarmClock, another way I thought is to create separate methods like from monday to sunday, is there a smarter way to do this job? thanks!