How to limit the timing that can be picked from Cupertino date picker in Flutter?

Issue

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?

Solution

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.

Answered By – Usama majid

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.