DateTimePickerModel constructor

DateTimePickerModel({
  1. DateTime? currentTime,
  2. DateTime? maxTime,
  3. DateTime? minTime,
  4. LocaleType? locale,
})

Implementation

DateTimePickerModel(
    {DateTime? currentTime,
    DateTime? maxTime,
    DateTime? minTime,
    LocaleType? locale})
    : super(locale: locale) {
  if (currentTime != null) {
    this.currentTime = currentTime;
    if (maxTime != null &&
        (currentTime.isBefore(maxTime) ||
            currentTime.isAtSameMomentAs(maxTime))) {
      this.maxTime = maxTime;
    }
    if (minTime != null &&
        (currentTime.isAfter(minTime) ||
            currentTime.isAtSameMomentAs(minTime))) {
      this.minTime = minTime;
    }
  } else {
    this.maxTime = maxTime;
    this.minTime = minTime;
    var now = DateTime.now();
    if (this.minTime != null && this.minTime!.isAfter(now)) {
      this.currentTime = this.minTime!;
    } else if (this.maxTime != null && this.maxTime!.isBefore(now)) {
      this.currentTime = this.maxTime!;
    } else {
      this.currentTime = now;
    }
  }

  if (this.minTime != null &&
      this.maxTime != null &&
      this.maxTime!.isBefore(this.minTime!)) {
    // invalid
    this.minTime = null;
    this.maxTime = null;
  }

  _currentLeftIndex = 0;
  _currentMiddleIndex = this.currentTime.hour;
  _currentRightIndex = this.currentTime.minute;
  if (this.minTime != null && isAtSameDay(this.minTime!, this.currentTime)) {
    _currentMiddleIndex = this.currentTime.hour - this.minTime!.hour;
    if (_currentMiddleIndex == 0) {
      _currentRightIndex = this.currentTime.minute - this.minTime!.minute;
    }
  }
}