selectRange method

void selectRange(
  1. DateTime start,
  2. DateTime end
)

Sets both range endpoints at once, swapping them when reversed. No-op when detached, outside SelectionMode.range, or when either date is outside the rendered range. Does not scroll and fires no callbacks.

Implementation

void selectRange(DateTime start, DateTime end) {
  final state = _datePickerState;
  if (state == null) return;
  if (state.widget.selectionMode != SelectionMode.range) return;
  if (state._indexOf(start) == null || state._indexOf(end) == null) return;
  var a = state._unitKey(start);
  var b = state._unitKey(end);
  if (b.isBefore(a)) {
    final t = a;
    a = b;
    b = t;
  }
  state._applyProgrammaticSelection(<DateTime>[a, b], anchor: b);
}