|
@@ -45,8 +45,7 @@ class CommonPickerModel extends BasePickerModel {
|
|
|
|
|
|
|
|
LocaleType locale;
|
|
LocaleType locale;
|
|
|
|
|
|
|
|
- CommonPickerModel({this.currentTime, locale})
|
|
|
|
|
- : this.locale = locale ?? LocaleType.en;
|
|
|
|
|
|
|
+ CommonPickerModel({this.currentTime, locale}) : this.locale = locale ?? LocaleType.en;
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
String leftStringAtIndex(int index) {
|
|
String leftStringAtIndex(int index) {
|
|
@@ -119,11 +118,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
DateTime maxTime;
|
|
DateTime maxTime;
|
|
|
DateTime minTime;
|
|
DateTime minTime;
|
|
|
|
|
|
|
|
- DatePickerModel(
|
|
|
|
|
- {DateTime currentTime,
|
|
|
|
|
- DateTime maxTime,
|
|
|
|
|
- DateTime minTime,
|
|
|
|
|
- LocaleType locale})
|
|
|
|
|
|
|
+ DatePickerModel({DateTime currentTime, DateTime maxTime, DateTime minTime, LocaleType locale})
|
|
|
: super(locale: locale) {
|
|
: super(locale: locale) {
|
|
|
this.maxTime = maxTime ?? DateTime(2049, 12, 31);
|
|
this.maxTime = maxTime ?? DateTime(2049, 12, 31);
|
|
|
this.minTime = minTime ?? DateTime(1970, 1, 1);
|
|
this.minTime = minTime ?? DateTime(1970, 1, 1);
|
|
@@ -165,17 +160,13 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
|
|
|
|
|
int _maxDayOfCurrentMonth() {
|
|
int _maxDayOfCurrentMonth() {
|
|
|
int dayCount = calcDateCount(currentTime.year, currentTime.month);
|
|
int dayCount = calcDateCount(currentTime.year, currentTime.month);
|
|
|
- return currentTime.year == maxTime.year &&
|
|
|
|
|
- currentTime.month == maxTime.month
|
|
|
|
|
|
|
+ return currentTime.year == maxTime.year && currentTime.month == maxTime.month
|
|
|
? maxTime.day
|
|
? maxTime.day
|
|
|
: dayCount;
|
|
: dayCount;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int _minDayOfCurrentMonth() {
|
|
int _minDayOfCurrentMonth() {
|
|
|
- return currentTime.year == minTime.year &&
|
|
|
|
|
- currentTime.month == minTime.month
|
|
|
|
|
- ? minTime.day
|
|
|
|
|
- : 1;
|
|
|
|
|
|
|
+ return currentTime.year == minTime.year && currentTime.month == minTime.month ? minTime.day : 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void _fillMiddleLists() {
|
|
void _fillMiddleLists() {
|
|
@@ -193,6 +184,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
this.rightList = List.generate(maxDay - minDay + 1, (int index) {
|
|
this.rightList = List.generate(maxDay - minDay + 1, (int index) {
|
|
|
return '${minDay + index}${_localeDay()}';
|
|
return '${minDay + index}${_localeDay()}';
|
|
|
});
|
|
});
|
|
|
|
|
+ print('this.rightList ${this.rightList}');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -243,10 +235,12 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
int minDay = _minDayOfCurrentMonth();
|
|
int minDay = _minDayOfCurrentMonth();
|
|
|
_currentMiddleIndex = currentTime.month - minMonth;
|
|
_currentMiddleIndex = currentTime.month - minMonth;
|
|
|
_currentRightIndex = currentTime.day - minDay;
|
|
_currentRightIndex = currentTime.day - minDay;
|
|
|
|
|
+ print('_currentRightIndex $_currentRightIndex');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
void setMiddleIndex(int index) {
|
|
void setMiddleIndex(int index) {
|
|
|
|
|
+ print('setMiddleIndex $index');
|
|
|
super.setMiddleIndex(index);
|
|
super.setMiddleIndex(index);
|
|
|
//adjust right
|
|
//adjust right
|
|
|
int minMonth = _minMonthOfCurrentYear();
|
|
int minMonth = _minMonthOfCurrentYear();
|
|
@@ -281,6 +275,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
void setRightIndex(int index) {
|
|
void setRightIndex(int index) {
|
|
|
|
|
+ print('setRightIndex $index');
|
|
|
super.setRightIndex(index);
|
|
super.setRightIndex(index);
|
|
|
int minDay = _minDayOfCurrentMonth();
|
|
int minDay = _minDayOfCurrentMonth();
|
|
|
currentTime = currentTime.isUtc
|
|
currentTime = currentTime.isUtc
|
|
@@ -298,6 +293,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
String leftStringAtIndex(int index) {
|
|
String leftStringAtIndex(int index) {
|
|
|
|
|
+ print('leftStringAtIndex $index');
|
|
|
if (index >= 0 && index < leftList.length) {
|
|
if (index >= 0 && index < leftList.length) {
|
|
|
return leftList[index];
|
|
return leftList[index];
|
|
|
} else {
|
|
} else {
|
|
@@ -307,6 +303,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
String middleStringAtIndex(int index) {
|
|
String middleStringAtIndex(int index) {
|
|
|
|
|
+ print('middleStringAtIndex $index');
|
|
|
if (index >= 0 && index < middleList.length) {
|
|
if (index >= 0 && index < middleList.length) {
|
|
|
return middleList[index];
|
|
return middleList[index];
|
|
|
} else {
|
|
} else {
|
|
@@ -316,6 +313,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
String rightStringAtIndex(int index) {
|
|
String rightStringAtIndex(int index) {
|
|
|
|
|
+ print('rightStringAtIndex $index');
|
|
|
if (index >= 0 && index < rightList.length) {
|
|
if (index >= 0 && index < rightList.length) {
|
|
|
return rightList[index];
|
|
return rightList[index];
|
|
|
} else {
|
|
} else {
|
|
@@ -364,7 +362,7 @@ class DatePickerModel extends CommonPickerModel {
|
|
|
class TimePickerModel extends CommonPickerModel {
|
|
class TimePickerModel extends CommonPickerModel {
|
|
|
bool showSecondsColumn;
|
|
bool showSecondsColumn;
|
|
|
|
|
|
|
|
- TimePickerModel({DateTime currentTime, LocaleType locale, this.showSecondsColumn : true})
|
|
|
|
|
|
|
+ TimePickerModel({DateTime currentTime, LocaleType locale, this.showSecondsColumn: true})
|
|
|
: super(locale: locale) {
|
|
: super(locale: locale) {
|
|
|
this.currentTime = currentTime ?? DateTime.now();
|
|
this.currentTime = currentTime ?? DateTime.now();
|
|
|
|
|
|
|
@@ -414,20 +412,20 @@ class TimePickerModel extends CommonPickerModel {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
- List<int> layoutProportions(){
|
|
|
|
|
|
|
+ List<int> layoutProportions() {
|
|
|
if (showSecondsColumn)
|
|
if (showSecondsColumn)
|
|
|
- return [1,1,1];
|
|
|
|
|
|
|
+ return [1, 1, 1];
|
|
|
else
|
|
else
|
|
|
- return [1,1,0];
|
|
|
|
|
|
|
+ return [1, 1, 0];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
@override
|
|
|
DateTime finalTime() {
|
|
DateTime finalTime() {
|
|
|
return currentTime.isUtc
|
|
return currentTime.isUtc
|
|
|
- ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day,
|
|
|
|
|
- _currentLeftIndex, _currentMiddleIndex, _currentRightIndex)
|
|
|
|
|
- : DateTime(currentTime.year, currentTime.month, currentTime.day,
|
|
|
|
|
- _currentLeftIndex, _currentMiddleIndex, _currentRightIndex);
|
|
|
|
|
|
|
+ ? DateTime.utc(currentTime.year, currentTime.month, currentTime.day, _currentLeftIndex,
|
|
|
|
|
+ _currentMiddleIndex, _currentRightIndex)
|
|
|
|
|
+ : DateTime(currentTime.year, currentTime.month, currentTime.day, _currentLeftIndex,
|
|
|
|
|
+ _currentMiddleIndex, _currentRightIndex);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -435,18 +433,16 @@ class TimePickerModel extends CommonPickerModel {
|
|
|
class DateTimePickerModel extends CommonPickerModel {
|
|
class DateTimePickerModel extends CommonPickerModel {
|
|
|
DateTime maxTime;
|
|
DateTime maxTime;
|
|
|
DateTime minTime;
|
|
DateTime minTime;
|
|
|
- DateTimePickerModel(
|
|
|
|
|
- {DateTime currentTime,
|
|
|
|
|
- DateTime maxTime,
|
|
|
|
|
- DateTime minTime,
|
|
|
|
|
- LocaleType locale})
|
|
|
|
|
|
|
+ DateTimePickerModel({DateTime currentTime, DateTime maxTime, DateTime minTime, LocaleType locale})
|
|
|
: super(locale: locale) {
|
|
: super(locale: locale) {
|
|
|
if (currentTime != null) {
|
|
if (currentTime != null) {
|
|
|
this.currentTime = currentTime;
|
|
this.currentTime = currentTime;
|
|
|
- if (maxTime != null && currentTime.isBefore(maxTime)) {
|
|
|
|
|
|
|
+ if (maxTime != null &&
|
|
|
|
|
+ (currentTime.isBefore(maxTime) || currentTime.isAtSameMomentAs(maxTime))) {
|
|
|
this.maxTime = maxTime;
|
|
this.maxTime = maxTime;
|
|
|
}
|
|
}
|
|
|
- if (minTime != null && currentTime.isAfter(minTime)) {
|
|
|
|
|
|
|
+ if (minTime != null &&
|
|
|
|
|
+ (currentTime.isAfter(minTime) || currentTime.isAtSameMomentAs(minTime))) {
|
|
|
this.minTime = minTime;
|
|
this.minTime = minTime;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -462,9 +458,7 @@ class DateTimePickerModel extends CommonPickerModel {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (this.minTime != null &&
|
|
|
|
|
- this.maxTime != null &&
|
|
|
|
|
- this.maxTime.isBefore(this.minTime)) {
|
|
|
|
|
|
|
+ if (this.minTime != null && this.maxTime != null && this.maxTime.isBefore(this.minTime)) {
|
|
|
// invalid
|
|
// invalid
|
|
|
this.minTime = null;
|
|
this.minTime = null;
|
|
|
this.maxTime = null;
|
|
this.maxTime = null;
|
|
@@ -513,8 +507,7 @@ class DateTimePickerModel extends CommonPickerModel {
|
|
|
if (_currentRightIndex > maxIndex) {
|
|
if (_currentRightIndex > maxIndex) {
|
|
|
_currentRightIndex = maxIndex;
|
|
_currentRightIndex = maxIndex;
|
|
|
}
|
|
}
|
|
|
- } else if (isAtSameDay(maxTime, time) &&
|
|
|
|
|
- _currentMiddleIndex == maxTime.hour) {
|
|
|
|
|
|
|
+ } else if (isAtSameDay(maxTime, time) && _currentMiddleIndex == maxTime.hour) {
|
|
|
var maxIndex = maxTime.minute;
|
|
var maxIndex = maxTime.minute;
|
|
|
if (_currentRightIndex > maxIndex) {
|
|
if (_currentRightIndex > maxIndex) {
|
|
|
_currentRightIndex = maxIndex;
|
|
_currentRightIndex = maxIndex;
|
|
@@ -525,13 +518,9 @@ class DateTimePickerModel extends CommonPickerModel {
|
|
|
@override
|
|
@override
|
|
|
String leftStringAtIndex(int index) {
|
|
String leftStringAtIndex(int index) {
|
|
|
DateTime time = currentTime.add(Duration(days: index));
|
|
DateTime time = currentTime.add(Duration(days: index));
|
|
|
- if (minTime != null &&
|
|
|
|
|
- time.isBefore(minTime) &&
|
|
|
|
|
- !isAtSameDay(minTime, time)) {
|
|
|
|
|
|
|
+ if (minTime != null && time.isBefore(minTime) && !isAtSameDay(minTime, time)) {
|
|
|
return null;
|
|
return null;
|
|
|
- } else if (maxTime != null &&
|
|
|
|
|
- time.isAfter(maxTime) &&
|
|
|
|
|
- !isAtSameDay(maxTime, time)) {
|
|
|
|
|
|
|
+ } else if (maxTime != null && time.isAfter(maxTime) && !isAtSameDay(maxTime, time)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
return formatDate(time, [ymdw], locale);
|
|
return formatDate(time, [ymdw], locale);
|
|
@@ -570,8 +559,7 @@ class DateTimePickerModel extends CommonPickerModel {
|
|
|
} else {
|
|
} else {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- } else if (isAtSameDay(maxTime, time) &&
|
|
|
|
|
- _currentMiddleIndex >= maxTime.hour) {
|
|
|
|
|
|
|
+ } else if (isAtSameDay(maxTime, time) && _currentMiddleIndex >= maxTime.hour) {
|
|
|
if (index >= 0 && index <= maxTime.minute) {
|
|
if (index >= 0 && index <= maxTime.minute) {
|
|
|
return digits(index, 2);
|
|
return digits(index, 2);
|
|
|
} else {
|
|
} else {
|