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)) {
      this.maxTime = maxTime;
    }
    if (minTime != null && currentTime.isAfter(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!)) {
    this.minTime = null;
    this.maxTime = null;
  }

  _currentIndex[0] = 0;
  _currentIndex[1] = this.currentTime.hour;
  _currentIndex[2] = this.currentTime.minute;
  if (this.minTime != null && isAtSameDay(this.minTime, this.currentTime)) {
    _currentIndex[1] = this.currentTime.hour - this.minTime!.hour;
    if (_currentIndex[1] == 0) {
      _currentIndex[2] = this.currentTime.minute - this.minTime!.minute;
    }
  }
}