DateTimePickerModel constructor
DateTimePickerModel({
- DateTime? currentTime,
- DateTime? maxTime,
- DateTime? minTime,
- 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;
}
}
}