gavin.chen před 2 roky
rodič
revize
c5d0b86ec9

+ 38 - 11
lib/calendar_controller/controller.dart

@@ -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);
   }
 

+ 8 - 3
lib/calendar_view/calendar_main_panel.dart

@@ -104,8 +104,13 @@ class _CalendarMainPanelState extends State<CalendarMainPanel> {
     return SizedBox(
       width: 50,
       height: 32,
-      child: ElevatedButton(
+      child: OutlinedButton(
         style: ButtonStyle(
+          overlayColor: MaterialStateProperty.all<Color>(
+              const Color.fromARGB(255, 235, 235, 235)),
+          foregroundColor: MaterialStateProperty.all<Color>(
+              _isToday ? Colors.black26 : Colors.black),
+          backgroundColor: MaterialStateProperty.all<Color>(Colors.transparent),
           padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
               const EdgeInsets.all(0)),
           shadowColor: MaterialStateProperty.all<Color>(Colors.transparent),
@@ -130,7 +135,7 @@ class _CalendarMainPanelState extends State<CalendarMainPanel> {
             height: 32,
             child: ElevatedButton(
               style: iconButtonStyle,
-              onPressed: calendarController.handleNextMonth,
+              onPressed: () => calendarController.handleLastMonth(true),
               child: const Icon(
                 Icons.keyboard_arrow_left,
                 size: 20,
@@ -143,7 +148,7 @@ class _CalendarMainPanelState extends State<CalendarMainPanel> {
             height: 32,
             child: ElevatedButton(
               style: iconButtonStyle,
-              onPressed: calendarController.handleLastMonth,
+              onPressed: () => calendarController.handleNextMonth(true),
               child: const Icon(
                 Icons.keyboard_arrow_right,
                 size: 20,

+ 23 - 8
lib/calendar_view/month_calendar/schedule_list.dart

@@ -100,10 +100,10 @@ class ScheduleListState extends State<ScheduleList> {
                   borderRadius: BorderRadius.circular(5),
                 ),
               ),
-              const SizedBox(width: 10),
+              const SizedBox(width: 5),
               Expanded(
                 child: Text(
-                  schedule.title,
+                  breakWord(schedule.title),
                   style: const TextStyle(fontSize: 12),
                   overflow: TextOverflow.ellipsis,
                 ),
@@ -138,12 +138,15 @@ class ScheduleListState extends State<ScheduleList> {
                   borderRadius: BorderRadius.circular(5),
                 ),
               ),
-              const SizedBox(width: 10),
-              Text(
-                '还有$moreNum项...',
-                style: const TextStyle(
-                  fontSize: 12,
-                  color: Colors.black38,
+              const SizedBox(width: 5),
+              Expanded(
+                child: Text(
+                  breakWord('还有$moreNum项...'),
+                  style: const TextStyle(
+                    fontSize: 12,
+                    color: Colors.black38,
+                    overflow: TextOverflow.ellipsis,
+                  ),
                 ),
               ),
             ],
@@ -152,4 +155,16 @@ class ScheduleListState extends State<ScheduleList> {
       ),
     );
   }
+
+  static String breakWord(String text) {
+    if (text.isEmpty) {
+      return text;
+    }
+    String breakWord = ' ';
+    text.runes.forEach((element) {
+      breakWord += String.fromCharCode(element);
+      breakWord += '\u200B';
+    });
+    return breakWord;
+  }
 }