Skip to content

Can't select single-day range on multirange selection #2340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
enzo-santos opened this issue Apr 27, 2025 · 1 comment
Open

Can't select single-day range on multirange selection #2340

enzo-santos opened this issue Apr 27, 2025 · 1 comment
Labels
date range picker Date range picker component waiting for customer response Cannot make further progress until the customer responds.

Comments

@enzo-santos
Copy link

enzo-santos commented Apr 27, 2025

Use case

The current behavior of the date picker does not allow users to select a date range that spans only a single day. When a user clicks on May 5th to set the start date, and then clicks again on May 5th to also set it as the end date, followed by a click on May 7th, the picker resets the selection. Instead of interpreting the first two clicks as defining a one-day range (May 5th–May 5th), it treats the second click on May 5th as a new start date, and then the third click on May 7th as the end date. This results in an unintended selection of May 5th–May 7th. The expected behavior is for the second click on the same date to confirm a single-day range, rather than resetting the selection process.

Proposal

I understand that in some scenarios disallowing single-day ranges is acceptable, but other scenarios (such as mine) are essential having it as a feature.

I detected where that happens (at least in multirange selection): method void _drawRangesSelectionForMonth(dynamic) of class _PickerViewState. My working solution is:

void _drawRangesSelectionForMonth(dynamic selectedDate) {
    _pickerStateDetails.selectedRanges ??= <dynamic>[];
    int count = _pickerStateDetails.selectedRanges!.length;
    dynamic lastRange;
    if (count > 0) {
      lastRange = _pickerStateDetails.selectedRanges![count - 1];
    }
+   final bool allowSingleDaySelection = true;
    if (lastRange != null &&
        lastRange.startDate != null &&
        (lastRange.endDate == null ||
-           isSameDate(lastRange.startDate, lastRange.endDate))) {
+           (!allowSingleDaySelection && isSameDate(lastRange.startDate, lastRange.endDate)))) {
      dynamic startDate = lastRange.startDate;
      dynamic endDate = selectedDate;
      if (startDate.isAfter(endDate) == true) {
        final dynamic temp = startDate;
        startDate = endDate;
        endDate = temp;
      }

      final dynamic newRange = widget.picker.isHijri
          ? HijriDateRange(startDate, endDate)
          : PickerDateRange(startDate, endDate);
      _pickerStateDetails.selectedRanges![count - 1] = newRange;
    } else {
      _pickerStateDetails.selectedRanges!.add(widget.picker.isHijri
          ? HijriDateRange(selectedDate, null)
          : PickerDateRange(selectedDate, null));
    }

    count = _pickerStateDetails.selectedRanges!.length;
    _removeInterceptRanges(
        _pickerStateDetails.selectedRanges,
        _pickerStateDetails
            .selectedRanges![_pickerStateDetails.selectedRanges!.length - 1]);
    lastRange = _pickerStateDetails
        .selectedRanges![_pickerStateDetails.selectedRanges!.length - 1];
    if (count != _pickerStateDetails.selectedRanges!.length &&
        (lastRange.endDate == null ||
            isSameDate(lastRange.endDate, lastRange.startDate))) {
      _pickerStateDetails.selectedRanges!.removeLast();
    }
  }

My proposal is to add allowSingleDaySelection as a parameter of SfDateRangePicker, to make it easier to turn it on and off.

@enzo-santos enzo-santos changed the title Allow single day selection for multirange selection Can't select single-day range on multirange selection Apr 27, 2025
@VijayakumarMariappan VijayakumarMariappan added date range picker Date range picker component open Open labels Apr 28, 2025
@Mugunthan-Ramalingam
Copy link
Contributor

Hi @enzo-santos,

Currently, we don’t have a support for single date selection support in the multi range selection mode in SfDateRangePicker. However, we have already logged a feature request for it in our feedback portal. We will prioritize the features of every release based on demand and priority. So, this feature will be available in any of our upcoming releases. We will notify you here once the release has been rolled out, and we appreciate your patience in the meantime. You can also track the status of the feature using the feedback link provided below.

FR Link: Provide single date selection support in the multi range selection mode in the Date Range Picker in Flutter | Feedback Portal

Regards,
Mugunthan.

@LavanyaGowtham2021 LavanyaGowtham2021 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
date range picker Date range picker component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

4 participants