Home > Net >  How to disable the current dates along with past date in showDatePicker?
How to disable the current dates along with past date in showDatePicker?

Time:06-24

I want to disable the current date in showDatePicker. I was able to disable the past date in the showDatePicker but i also want to disable the current date in showDatePicker

here is my code:

showDatePicker(
                                        context: context,
                                        initialDate: DateTime.now(),
                                        firstDate: DateTime.now()
                                            .subtract(Duration(days: 0)),
                                        lastDate: DateTime(2025),
                                        // selectableDayPredicate:
                                        //     _decideWhichDayToEnable,
                                      );

the calender

i have updated, user can still press the 24 but i want it to be disable..

CodePudding user response:

intialDate property is the key here.

DateTime intialDate = DateTime.now().add(Duration(days: 1));
showDatePicker(
    context: context,
    initialDate: intialDate,
    initialDatePickerMode: DatePickerMode.day,
    firstDate: intialDate,
    lastDate: DateTime(2025));

This is the output am getting. enter image description here

CodePudding user response:

From your code what I understand is that you have to set Tomorrow as the firstDate and inialDate. You just need to set those values like DateTime.now().add(const Duration(days: 1)). I hope that will work.

  • Related