CupertinoDatePicker disable hours and minutes before the current time

1.7k Views Asked by At

**Example Image, we can't scroll to the time before current time & day

In the minimumDate param, we can't control the minimum time.

`  CupertinoDatePickerTest(                             
   onDateTimeChanged: (DateTime newdate) {
     print(newdate);
   },
   use24hFormat: false,
   maximumDate: DateTime.now().add(Duration(days: 2)),
   minimumDate:DateTime.now().subtract(Duration(days: 1)),
   minuteInterval: 1,
   mode: CupertinoDatePickerMode.dateAndTime,
   )`
1

There are 1 best solutions below

2
On

You can use minimumDate attribute inside CupertinoDatePicker widget, the following code will disable hours and minutes before the current time:

CupertinoDatePicker(
      minimumDate: DateTime.now(), //Min Date time is current time
  }

You can use maximumDate attribute as well if you would like to limit the maximum date:

maximumDate: DateTime.now().add(Duration(days: 2)), //Max Date is after tomorrow