LunarPickerModel constructor

LunarPickerModel({
  1. DateTime? currentTime,
  2. DateTime? maxTime,
  3. DateTime? minTime,
  4. bool? showLunarYear = false,
})

Implementation

LunarPickerModel(
    {DateTime? currentTime, DateTime? maxTime, DateTime? minTime,bool? showLunarYear = false}) {
  this.maxTime = maxTime ?? DateTime(2049, 12, 31);
  this.minTime = minTime ?? DateTime(1970, 1, 1);
  this.showLunarYear = showLunarYear ?? false;
  currentTime = currentTime ?? DateTime.now();
  // 阳历转阴历
  maxLunarTime = Solar.fromDate(this.maxTime).getLunar();
  minLunarTime = Solar.fromDate(this.minTime).getLunar();
  // 获取当前阴历
  currentLunarTime = Solar.fromDate(currentTime).getLunar();
  debugPrint("currentLunarTime:$currentLunarTime");
  if (currentTime.compareTo(this.maxTime) > 0) {
    currentTime = this.maxTime;
    currentLunarTime = maxLunarTime;
  } else if (currentTime.compareTo(this.minTime) < 0) {
    currentTime = this.minTime;
    currentLunarTime = minLunarTime;
  }

  this.currentTime = currentTime;

  _fillLeftLists();
  _fillMiddleLists();
  _fillRightLists();
  int minDay = _minDayOfCurrentMonth();
  _currentLeftIndex = currentLunarTime.getYear() - minLunarTime.getYear();
  _currentMiddleIndex = _getCurrentMiddleIndex();
  _currentRightIndex = currentLunarTime.getDay() - minDay;
  _currentHourIndex = this.currentTime.hour;
  _currentMinuteIndex = this.currentTime.minute;
}