Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/src/controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class RangePickerController {
this.minimumDateRangeLength,
this.maximumDateRangeLength,
this.disabledDates = const [],
this.allowSingleTapDaySelection = false}) {
this.allowSingleTapDaySelection = false,
this.allowBackwardsDaySelection = true})
: origMinDate = minDate {
if (dateRange != null) {
startDate = dateRange.start;
endDate = dateRange.end;
Expand All @@ -29,11 +31,16 @@ class RangePickerController {

final bool allowSingleTapDaySelection;

/// Whether the user can select a date range backwards (i.e. start date is after end date).
final bool allowBackwardsDaySelection;

final ValueChanged<DateRange?> onDateRangeChanged;

/// The minimum date that can be selected. (inclusive)
DateTime? minDate;

final DateTime? origMinDate;

/// The maximum date that can be selected. (inclusive)
DateTime? maxDate;

Expand Down Expand Up @@ -84,6 +91,9 @@ class RangePickerController {
onDateRangeChanged(DateRange(startDate!, startDate!));
}
}
if (!allowBackwardsDaySelection) {
minDate = startDate != null && endDate == null ? startDate : origMinDate;
}
}

/// Returns whether the [date] is in the selected range or not.
Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/date_range_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class DateRangePickerWidget extends StatefulWidget {
this.displayMonthsSeparator = true,
this.separatorThickness = 1,
this.allowSingleTapDaySelection = false,
this.allowBackwardsDaySelection = true,
this.firstDayOfWeek = 0,
this.lengthOfDateName = 3,
}) : assert(
Expand Down Expand Up @@ -197,6 +198,10 @@ class DateRangePickerWidget extends StatefulWidget {
/// day twice).
final bool allowSingleTapDaySelection;

/// Set [allowBackwardsDaySelection] to false to prevent the user from selecting
/// a date range backwards (i.e. start date is after end date).
final bool allowBackwardsDaySelection;

/// The theme used to customize the appearance of the picker.
final CalendarTheme theme;

Expand Down Expand Up @@ -226,6 +231,7 @@ class DateRangePickerWidgetState extends State<DateRangePickerWidget> {
minimumDateRangeLength: widget.minimumDateRangeLength,
maximumDateRangeLength: widget.maximumDateRangeLength,
allowSingleTapDaySelection: widget.allowSingleTapDaySelection,
allowBackwardsDaySelection: widget.allowBackwardsDaySelection,
);

late final calendarController = CalendarWidgetController(
Expand Down