|
@@ -148,7 +148,7 @@ class CalendarController extends GetxController {
|
|
|
final Schedule schedule = Schedule(
|
|
|
day: date,
|
|
|
type: scheduleTypeList[typeIndex],
|
|
|
- title: '${scheduleTypeList[typeIndex].typeName} - Mock标题',
|
|
|
+ title: '${scheduleTypeList[typeIndex].typeName}-Mock标题',
|
|
|
content: '日程内容',
|
|
|
);
|
|
|
scheduleList.add(schedule);
|
|
@@ -195,7 +195,7 @@ class CalendarController extends GetxController {
|
|
|
i++) {
|
|
|
miniViewDaysList.add(
|
|
|
MiniViewDayStructure(
|
|
|
- index: i + firstDayWeek,
|
|
|
+ index: i + firstDayWeekIndex,
|
|
|
date: DateTime(year, month, i + 1),
|
|
|
isToday:
|
|
|
today.year == year && today.month == month && today.day == i + 1,
|
|
@@ -254,6 +254,26 @@ class CalendarController extends GetxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// 根据日期选中指定的一天
|
|
|
+ void _selectDay(int day, List<MiniViewDayStructure> newList) {
|
|
|
+ for (var element in newList) {
|
|
|
+ if (element.date.day == day && element.isCurrentMonth) {
|
|
|
+ handleSelectedDayByIndex(element.index);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int nextSearchDay = day - 1;
|
|
|
+ while (nextSearchDay > 0) {
|
|
|
+ for (var element in newList) {
|
|
|
+ if (element.date.day == nextSearchDay && element.isCurrentMonth) {
|
|
|
+ handleSelectedDayByIndex(element.index);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ nextSearchDay--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// 选中今天
|
|
|
void selectToday() {
|
|
|
/// 如果当前不是当月,则切换到当月
|
|
@@ -294,8 +314,9 @@ class CalendarController extends GetxController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// 上个月
|
|
|
- void handleLastMonth() {
|
|
|
+ /// 上个月 (keepSelectedDay 是否保持选中的日期)
|
|
|
+ void handleLastMonth([bool keepSelectedDay = false]) {
|
|
|
+ final currDay = miniViewDaysList[selectedDayIndex].date.day;
|
|
|
if (currentMonth == 1) {
|
|
|
currentMonth = 12;
|
|
|
currentYear--;
|
|
@@ -304,14 +325,17 @@ class CalendarController extends GetxController {
|
|
|
}
|
|
|
miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
_setMiniCalendarSchedule();
|
|
|
-
|
|
|
- _selectFirstDay();
|
|
|
-
|
|
|
+ if (keepSelectedDay) {
|
|
|
+ _selectDay(currDay, miniViewDaysList);
|
|
|
+ } else {
|
|
|
+ _selectFirstDay();
|
|
|
+ }
|
|
|
onDaysListChange.emit(this, null);
|
|
|
}
|
|
|
|
|
|
- /// 下个月
|
|
|
- void handleNextMonth() {
|
|
|
+ /// 下个月 (keepSelectedDay 是否保持选中的日期)
|
|
|
+ void handleNextMonth([bool keepSelectedDay = false]) {
|
|
|
+ final currDay = miniViewDaysList[selectedDayIndex].date.day;
|
|
|
if (currentMonth == 12) {
|
|
|
currentMonth = 1;
|
|
|
currentYear++;
|
|
@@ -320,8 +344,11 @@ class CalendarController extends GetxController {
|
|
|
}
|
|
|
miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
_setMiniCalendarSchedule();
|
|
|
- _selectFirstDay();
|
|
|
-
|
|
|
+ if (keepSelectedDay) {
|
|
|
+ _selectDay(currDay, miniViewDaysList);
|
|
|
+ } else {
|
|
|
+ _selectFirstDay();
|
|
|
+ }
|
|
|
onDaysListChange.emit(this, null);
|
|
|
}
|
|
|
|