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?

2
  • I don't think it's possible with the built in widget, you could use this one pub.dev/packages/flutter_cupertino_date_picker
    – Er1
    Mar 4, 2022 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 5, 2022 at 5:01

1 Answer 1

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.

1
  • 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 5, 2022 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.