|
...
|
...
|
@@ -22,7 +22,7 @@ const Duration _monthScrollDuration = Duration(milliseconds: 200); |
|
|
|
|
|
|
|
const double _dayPickerRowHeight = 42.0;
|
|
|
|
const int _maxDayPickerRowCount = 6; // A 31 day month that starts on Saturday.
|
|
|
|
const double _monthPickerHorizontalPadding = 8.0;
|
|
|
|
const double _monthPickerHorizontalPadding = 0;
|
|
|
|
|
|
|
|
const int _yearPickerColumnCount = 3;
|
|
|
|
const double _yearPickerPadding = 16.0;
|
|
...
|
...
|
@@ -224,6 +224,45 @@ class _CalendarDatePicker2State extends State<CalendarDatePicker2> { |
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleDisplayedMonthDateChangedMy(DateTime date, bool isAdd) {
|
|
|
|
_vibrate();
|
|
|
|
setState(() {
|
|
|
|
_currentDisplayedMonthDate =
|
|
|
|
DateTime(isAdd ? date.year + 1 : date.year - 1, date.month);
|
|
|
|
widget.onDisplayedMonthChanged?.call(_currentDisplayedMonthDate);
|
|
|
|
// final currentDisplayedMonthDate = DateTime(
|
|
|
|
// _currentDisplayedMonthDate.year,
|
|
|
|
// _currentDisplayedMonthDate.month,
|
|
|
|
// );
|
|
|
|
// var newDisplayedMonthDate = currentDisplayedMonthDate;
|
|
|
|
|
|
|
|
// if (_currentDisplayedMonthDate.year != date.year ||
|
|
|
|
// _currentDisplayedMonthDate.month != date.month) {
|
|
|
|
// newDisplayedMonthDate = DateTime(date.year-1, date.month);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (fromYearPicker) {
|
|
|
|
// final selectedDatesInThisYear = _selectedDates
|
|
|
|
// .where((d) => d?.year == date.year)
|
|
|
|
// .toList()
|
|
|
|
// ..sort((d1, d2) => d1!.compareTo(d2!));
|
|
|
|
// if (selectedDatesInThisYear.isNotEmpty) {
|
|
|
|
// newDisplayedMonthDate =
|
|
|
|
// DateTime(date.year-1, selectedDatesInThisYear[0]!.month);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (currentDisplayedMonthDate.year != newDisplayedMonthDate.year ||
|
|
|
|
// currentDisplayedMonthDate.month != newDisplayedMonthDate.month) {
|
|
|
|
// _currentDisplayedMonthDate = DateTime(
|
|
|
|
// newDisplayedMonthDate.year,
|
|
|
|
// newDisplayedMonthDate.month,
|
|
|
|
// );
|
|
|
|
// widget.onDisplayedMonthChanged?.call(_currentDisplayedMonthDate);
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleMonthChanged(DateTime value) {
|
|
|
|
_vibrate();
|
|
|
|
setState(() {
|
|
...
|
...
|
@@ -247,6 +286,21 @@ class _CalendarDatePicker2State extends State<CalendarDatePicker2> { |
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleYearChangedMy(DateTime value, bool isAdd) {
|
|
|
|
_vibrate();
|
|
|
|
|
|
|
|
// if (value.isBefore(widget.config.firstDate)) {
|
|
|
|
// value = widget.config.firstDate;
|
|
|
|
// } else if (value.isAfter(widget.config.lastDate)) {
|
|
|
|
// value = widget.config.lastDate;
|
|
|
|
// }
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_mode = CalendarDatePicker2Mode.day;
|
|
|
|
_handleDisplayedMonthDateChangedMy(value, isAdd);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleDayChanged(DateTime value) {
|
|
|
|
_vibrate();
|
|
|
|
setState(() {
|
|
...
|
...
|
@@ -317,6 +371,14 @@ class _CalendarDatePicker2State extends State<CalendarDatePicker2> { |
|
|
|
initialMonth: _currentDisplayedMonthDate,
|
|
|
|
selectedDates: _selectedDates,
|
|
|
|
onChanged: _handleDayChanged,
|
|
|
|
onChangedYearAdd: (value) {
|
|
|
|
dynamic date = value;
|
|
|
|
_handleYearChangedMy(date, true);
|
|
|
|
},
|
|
|
|
onChangedYearReduce: (value) {
|
|
|
|
dynamic date = value;
|
|
|
|
_handleYearChangedMy(date, false);
|
|
|
|
},
|
|
|
|
onDisplayedMonthChanged: _handleDisplayedMonthDateChanged,
|
|
|
|
);
|
|
|
|
case CalendarDatePicker2Mode.month:
|
|
...
|
...
|
@@ -379,40 +441,57 @@ class _CalendarDatePicker2State extends State<CalendarDatePicker2> { |
|
|
|
return widget.config.calendarViewMode == CalendarDatePicker2Mode.scroll
|
|
|
|
? _buildPicker()
|
|
|
|
: Stack(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(
|
|
|
|
height: (widget.config.controlsHeight ?? _subHeaderHeight) +
|
|
|
|
maxContentHeight,
|
|
|
|
child: _buildPicker(),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
// left: 150,
|
|
|
|
top: ((widget.config.controlsHeight ?? _subHeaderHeight) -
|
|
|
|
20) /
|
|
|
|
2,
|
|
|
|
child: Container(
|
|
|
|
height: 20,
|
|
|
|
child: Text(_currentDisplayedMonthDate.year.toString() +
|
|
|
|
'年' +
|
|
|
|
_currentDisplayedMonthDate.month.toString() +
|
|
|
|
'月',style:TextStyle(
|
|
|
|
color: Color(0xffF8F9FD),
|
|
|
|
fontSize: 18
|
|
|
|
|
|
|
|
|
|
|
|
))))
|
|
|
|
// Put the mode toggle button on top so that it won't be covered up by the _CalendarView
|
|
|
|
_DatePickerModeToggleButton(
|
|
|
|
config: widget.config,
|
|
|
|
mode: _mode,
|
|
|
|
monthDate: _currentDisplayedMonthDate,
|
|
|
|
onMonthPressed: () {
|
|
|
|
if (_mode == CalendarDatePicker2Mode.year) {
|
|
|
|
_handleModeChanged(CalendarDatePicker2Mode.month);
|
|
|
|
} else {
|
|
|
|
_handleModeChanged(
|
|
|
|
_mode == CalendarDatePicker2Mode.month
|
|
|
|
? CalendarDatePicker2Mode.day
|
|
|
|
: CalendarDatePicker2Mode.month,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onYearPressed: () {
|
|
|
|
if (_mode == CalendarDatePicker2Mode.month) {
|
|
|
|
_handleModeChanged(CalendarDatePicker2Mode.year);
|
|
|
|
} else {
|
|
|
|
_handleModeChanged(
|
|
|
|
_mode == CalendarDatePicker2Mode.year
|
|
|
|
? CalendarDatePicker2Mode.day
|
|
|
|
: CalendarDatePicker2Mode.year,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
// _DatePickerModeToggleButton(
|
|
|
|
// config: widget.config,
|
|
|
|
// mode: _mode,
|
|
|
|
// monthDate: _currentDisplayedMonthDate,
|
|
|
|
// onMonthPressed: () {
|
|
|
|
// if (_mode == CalendarDatePicker2Mode.year) {
|
|
|
|
// _handleModeChanged(CalendarDatePicker2Mode.month);
|
|
|
|
// } else {
|
|
|
|
// _handleModeChanged(
|
|
|
|
// _mode == CalendarDatePicker2Mode.month
|
|
|
|
// ? CalendarDatePicker2Mode.day
|
|
|
|
// : CalendarDatePicker2Mode.month,
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// onYearPressed: () {
|
|
|
|
// if (_mode == CalendarDatePicker2Mode.month) {
|
|
|
|
// _handleModeChanged(CalendarDatePicker2Mode.year);
|
|
|
|
// } else {
|
|
|
|
// _handleModeChanged(
|
|
|
|
// _mode == CalendarDatePicker2Mode.year
|
|
|
|
// ? CalendarDatePicker2Mode.day
|
|
|
|
// : CalendarDatePicker2Mode.year,
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
...
|
...
|
|