Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable previous days in calendar in flutter?

I have a datepicker in flutter. Now I need to disable all the previous days from present date in calendar in flutter. When I tried to do , it only disable the one previous day. If someone can try this, it will be helpful.

final DateTime picked = await showDatePicker(
    selectableDayPredicate: (DateTime val) =>
    val.day == DateTime.now().day - 1 ? false : true,
    context: context,
    initialDate: DateTime.now(),
    firstDate: new DateTime.now().subtract(new Duration(days: 30)),
    lastDate: DateTime(2101));
like image 750
john Avatar asked Oct 29 '25 08:10

john


1 Answers

I got the solution as this for my question, might be useful for someone. If it helped anybody then accept my answer as correct.

final DateTime picked = await showDatePicker(
  context: context,
  initialDate: DateTime.now(),
  firstDate: DateTime.now().subtract(Duration(days: 1)),
  lastDate: DateTime(2100),
);
like image 50
john Avatar answered Oct 31 '25 00:10

john



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!