Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter : How to disable dates in datepicker in flutter?

I want to disable the dates in the datepicker in flutter. Actually I am wokring on an application where user has to generate salary but I don’t want him to generate salary if the salary is already created.

suppose salary is created 1-10-2022 to 30-10-2022 then i want to disable all the previous dates from 30-10-2022…How can i do this ??

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 onTap: () async {
                          await showDatePicker(
                            context: context,
                            initialDate: DateTime.now(),
                            firstDate: DateTime(2000),
                            lastDate: DateTime(3000),
                          ).then((selectedDate) {
                            if (selectedDate != null) {
                              _startDatePickerController.text =
                                  DateFormat('d-MM-y')
                                      .format(selectedDate)
                                      .toString();
                            }
                            return null;
                          });
                        },

>Solution :

Try setting that date in the firstDate property, so previous dates than that will be disabled:

    firstDate: DateTime(2022, 10, 30),
    // ...

this will give you the idea, make a variable and then manage it with your logic.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading