Nihal Gurrala
Nihal Gurrala

Reputation: 79

CupertinoDatePicker disable hours and minutes before the current time

**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,
   )`

Upvotes: 4

Views: 1977

Answers (1)

Aziz
Aziz

Reputation: 479

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

Upvotes: 1

Related Questions