I want to disable the dates in the datepicker in flutter. Actually I am wokring on an application where user has to generate salary but I don’t want him to generate salary if the salary is already created.
suppose salary is created 1-10-2022 to 30-10-2022 then i want to disable all the previous dates from 30-10-2022…How can i do this ??
onTap: () async {
await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(3000),
).then((selectedDate) {
if (selectedDate != null) {
_startDatePickerController.text =
DateFormat('d-MM-y')
.format(selectedDate)
.toString();
}
return null;
});
},
2
Answers
Try setting that date in the
firstDate
property, so previous dates than that will be disabled:this will give you the idea, make a variable and then manage it with your logic.
I think your question is already answered here:
https://stackoverflow.com/a/53657221/5812524
Create a list of dates which you want to disable and check inside
if the date is inside your list.