TimePickerModel constructor
TimePickerModel({
- DateTime? currentTime,
- DateTime? maxTime,
- DateTime? minTime,
- LocaleType? locale,
- bool showSecondsColumn = true,
Implementation
TimePickerModel(
{DateTime? currentTime,
DateTime? maxTime,
DateTime? minTime,
LocaleType? locale,
this.showSecondsColumn = true})
: super(locale: locale) {
this.currentTime = currentTime ?? DateTime.now();
// this.maxTime = maxTime ?? DateTime(2049, 12, 31);
// this.minTime = minTime ?? DateTime(1970, 1, 1);
// _currentLeftIndex = this.currentTime.hour;
// _currentMiddleIndex = this.currentTime.minute;
// _currentRightIndex = this.currentTime.second;
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 = this.currentTime.hour;
_currentMiddleIndex = this.currentTime.minute;
_currentRightIndex = this.currentTime.second;
if (this.minTime != null && isAtSameDay(this.minTime!, this.currentTime)) {
_currentLeftIndex = this.currentTime.hour - this.minTime!.hour;
if (_currentLeftIndex == 0) {
_currentMiddleIndex = this.currentTime.minute - this.minTime!.minute;
}
}
}