PeakGen
PeakGen

Reputation: 23035

Flutter: How to disable the past dates in `showDatePicker`?

How to disable the past dates in flutter showDatePicker ? Below is my code

DateTime picked = await showDatePicker(
                              context: context,
                              initialDate: DateTime.now(),
                              firstDate: DateTime(2020, 1),
                              lastDate: DateTime(2101));

Upvotes: 6

Views: 7751

Answers (2)

Rohit Soni
Rohit Soni

Reputation: 1447

initialDate : Default Selected Date In Picker Dialog

firstDate : From Minimum Date Of Your Date Picker

lastDate : Max Date Of To-Date Of Date Picker

You can select date between from first date and last date

 DateTime picked = await showDatePicker(
                                  context: context,
                                  initialDate: DateTime.now(),
                                  firstDate: DateTime.now(),
                                  lastDate: DateTime(2101));

Upvotes: 2

Aamil Silawat
Aamil Silawat

Reputation: 8239

Try out this

final DateTime picked = await showDatePicker(
  context: context,
  initialDate: DateTime.now(),
  firstDate: DateTime.now().subtract(Duration(days: 1)),
  lastDate: DateTime(2100),
);

Upvotes: 12

Related Questions