3

Currently, this is how my Cupertino date picker look like

enter image description here

My code is as shown:

CupertinoDatePicker(
                      initialDateTime: DateTime.now(),
                      onDateTimeChanged: (val) {
                        setState(() {
                          dateSelected = val;
                        });
                      })

How can I make it such that I only allow the user to pick timing after 6 pm and before 3 am, every day?

scott lee
  • 546
  • 5
  • 23
  • I don't think it's possible with the built in widget, you could use this one https://pub.dev/packages/flutter_cupertino_date_picker – Er1 Mar 04 '22 at 13:33
  • 1
    I'd prefer to use the original cupertino package as it looks nicer. Thanks for the suggestion though – scott lee Mar 05 '22 at 05:01

1 Answers1

2

We cannot limit the timer. We can instead check if the current picked time is equal to our expectations. If not so show the user a dialog or a message to re enter the data and the current data entered is not available. Maybe this works for you.

Usama majid
  • 186
  • 16
  • Yup, that's a workaround I thought about as well. It ain't optimal but I shall stick to it for now. Thanks. – scott lee Mar 05 '22 at 05:04