DatePickerModel constructor Null safety

DatePickerModel(
  1. {DateTime? currentTime,
  2. DateTime? maxTime,
  3. DateTime? minTime,
  4. List<String>? formats,
  5. List<bool>? labels,
  6. List<int>? weights,
  7. List<String>? dividers}
)

Implementation

DatePickerModel({
  DateTime? currentTime,
  DateTime? maxTime,
  DateTime? minTime,
  List<String>? formats,
  List<bool>? labels,
  List<int>? weights,
  List<String>? dividers,
})  : assert(weights == null || weights.length == 3),
      assert(dividers == null || dividers.length == 2),
      assert(formats == null || formats.length == 3),
      assert(labels == null || labels.length == 3) {
  _weights = weights ?? [1, 1, 1];
  _dividers = dividers ?? ['', ''];
  _labels = labels ?? [true, true, true];
  _formats = formats ?? [yyyy, MM, dd];

  this.maxTime = maxTime ?? DateTime(2049, 12, 31);
  this.minTime = minTime ?? DateTime(1970, 1, 1);

  currentTime = currentTime ?? DateTime.now();
  if (currentTime.compareTo(this.maxTime) > 0) {
    currentTime = this.maxTime;
  } else if (currentTime.compareTo(this.minTime) < 0) {
    currentTime = this.minTime;
  }
  this.currentTime = currentTime;

  _fillYearList();
  _fillMonthList();
  _fillDayList();
  int minMonth = _minMonthOfCurrentYear();
  int minDay = _minDayOfCurrentMonth();

  firstIndex = this.currentTime.year - this.minTime.year;
  secondIndex = this.currentTime.month - minMonth;
  thirdIndex = this.currentTime.day - minDay;
}