Flutter Date Range Picker limit to certain days

1.1k Views Asked by At

How can we allow only selection of 30 days with any start date in DateRangePicker?

Only firstDate and lastDate can be provided, which can be restricted to 30 days starting from the provided firstDate only.

2

There are 2 best solutions below

2
Sachin Kumawat On BEST ANSWER
final picked = await showDateRangePicker(
  context: context,
  firstDate: (DateTime.now()).subtract(Duration(days: 30)),
  lastDate: DateTime.now(),
  currentDate: DateTime.now(),
  saveText: 'Done',
);
0
Hardik Hirpara On

Add below package to restrict certain dates in DateRangePicker

calendar_date_picker2: ^0.5.2

there is "selectableDayPredicate" function available for DateRangePicker.

You can simply pass list of dates which you wants to disable in selection in range.