|
@@ -1,17 +1,44 @@
|
|
|
+import 'dart:math';
|
|
|
+
|
|
|
import 'package:calendar_view/utils/calendar_util.dart';
|
|
|
import 'package:calendar_view/utils/event_type.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
class CalendarController extends GetxController {
|
|
|
CalendarController();
|
|
|
|
|
|
+
|
|
|
+ final List<DateTime> mockSchedule = [
|
|
|
+ DateTime(2022, 12, 1),
|
|
|
+ DateTime(2022, 12, 4),
|
|
|
+ DateTime(2022, 12, 5),
|
|
|
+ DateTime(2022, 12, 6),
|
|
|
+ DateTime(2022, 12, 7),
|
|
|
+ DateTime(2022, 12, 12),
|
|
|
+ DateTime(2022, 12, 13),
|
|
|
+ DateTime(2022, 12, 14),
|
|
|
+ DateTime(2022, 12, 15),
|
|
|
+ DateTime(2022, 12, 16),
|
|
|
+ DateTime(2022, 12, 17),
|
|
|
+ DateTime(2022, 12, 18),
|
|
|
+ DateTime(2022, 12, 19),
|
|
|
+ DateTime(2022, 12, 20),
|
|
|
+ DateTime(2022, 12, 27),
|
|
|
+ DateTime(2022, 12, 28),
|
|
|
+ DateTime(2022, 12, 29),
|
|
|
+ DateTime(2022, 12, 30),
|
|
|
+ DateTime(2022, 12, 31),
|
|
|
+ ];
|
|
|
+
|
|
|
|
|
|
int currentYear = 2022;
|
|
|
int currentMonth = 12;
|
|
|
int selectedDayIndex = 0;
|
|
|
int maxDaysLength = 35;
|
|
|
- List<Schedule> scheduleList = [];
|
|
|
+ List<Schedule> scheduleList = [];
|
|
|
List<ScheduleType> scheduleTypeList = [];
|
|
|
+ List<String> needDisplayTypeNameList = [];
|
|
|
List<MiniViewDayStructure> miniViewDaysList = [];
|
|
|
|
|
|
List<MonthViewDayStructure> get monthViewDaysList {
|
|
@@ -30,13 +57,13 @@ class CalendarController extends GetxController {
|
|
|
}
|
|
|
for (final Schedule schedule in scheduleList) {
|
|
|
final DateTime scheduleDate = schedule.day;
|
|
|
- final int scheduleDay = scheduleDate.day;
|
|
|
+
|
|
|
for (int i = 0; i < maxDaysLength; i++) {
|
|
|
final MiniViewDayStructure miniViewDayStructure = miniViewDaysList[i];
|
|
|
final MonthViewDayStructure monthViewDayStructure =
|
|
|
monthViewDaysList[i];
|
|
|
if (miniViewDayStructure.isCurrentMonth &&
|
|
|
- miniViewDayStructure.date.day == scheduleDay) {
|
|
|
+ miniViewDayStructure.date == scheduleDate) {
|
|
|
monthViewDayStructure.scheduleList.add(schedule);
|
|
|
}
|
|
|
}
|
|
@@ -44,7 +71,7 @@ class CalendarController extends GetxController {
|
|
|
return monthViewDaysList;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
String get currentYearMonth => '$currentYear年$currentMonth月';
|
|
|
bool get isToday => miniViewDaysList[selectedDayIndex].isToday;
|
|
|
int get calendarLines => maxDaysLength ~/ 7;
|
|
@@ -62,43 +89,77 @@ class CalendarController extends GetxController {
|
|
|
currentMonth = now.month;
|
|
|
miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
selectToday();
|
|
|
-
|
|
|
-
|
|
|
- final List<DateTime> mockSchedule = [
|
|
|
- DateTime(2022, 12, 1),
|
|
|
- DateTime(2022, 12, 4),
|
|
|
- DateTime(2022, 12, 5),
|
|
|
- DateTime(2022, 12, 6),
|
|
|
- DateTime(2022, 12, 7),
|
|
|
- DateTime(2022, 12, 12),
|
|
|
- DateTime(2022, 12, 13),
|
|
|
- DateTime(2022, 12, 14),
|
|
|
- DateTime(2022, 12, 15),
|
|
|
- DateTime(2022, 12, 16),
|
|
|
- DateTime(2022, 12, 17),
|
|
|
- DateTime(2022, 12, 18),
|
|
|
- DateTime(2022, 12, 19),
|
|
|
- DateTime(2022, 12, 20),
|
|
|
- DateTime(2022, 12, 27),
|
|
|
- DateTime(2022, 12, 28),
|
|
|
- DateTime(2022, 12, 29),
|
|
|
- DateTime(2022, 12, 30),
|
|
|
- DateTime(2022, 12, 31),
|
|
|
- ];
|
|
|
-
|
|
|
_initMockScheduleType();
|
|
|
_initMockSchedule(mockSchedule);
|
|
|
- _setSchedule(mockSchedule);
|
|
|
- print("CalendarController 全局临时控制器初始化");
|
|
|
+
|
|
|
+ updateScheduleTypeList();
|
|
|
+ _setMiniCalendarSchedule();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
void _initMockScheduleType() {
|
|
|
-
|
|
|
+ scheduleTypeList = [
|
|
|
+ ScheduleType(
|
|
|
+ typeName: '我的日程',
|
|
|
+ color: Colors.red,
|
|
|
+ isSelected: true,
|
|
|
+ ),
|
|
|
+ ScheduleType(
|
|
|
+ typeName: '工作日程',
|
|
|
+ color: Colors.blue,
|
|
|
+ isSelected: true,
|
|
|
+ ),
|
|
|
+ ScheduleType(
|
|
|
+ typeName: '会议日程',
|
|
|
+ color: Colors.green,
|
|
|
+ isSelected: true,
|
|
|
+ ),
|
|
|
+ ScheduleType(
|
|
|
+ typeName: '其他日程',
|
|
|
+ color: Colors.orange,
|
|
|
+ isSelected: true,
|
|
|
+ ),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void updateScheduleTypeList() {
|
|
|
+
|
|
|
+ needDisplayTypeNameList = [];
|
|
|
+ for (var element in scheduleTypeList) {
|
|
|
+ if (element.isSelected) {
|
|
|
+ needDisplayTypeNameList.add(element.typeName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _setMiniCalendarSchedule();
|
|
|
+
|
|
|
+ onDaysListChange.emit(this, null);
|
|
|
}
|
|
|
|
|
|
|
|
|
- void _initMockSchedule(List<DateTime> scheduleList) {
|
|
|
-
|
|
|
+ void _initMockSchedule(List<DateTime> mockSchedule) {
|
|
|
+
|
|
|
+ for (final DateTime date in mockSchedule) {
|
|
|
+ int num = _getRandomInt(0, 10);
|
|
|
+ for (int i = 0; i < num; i++) {
|
|
|
+ int typeIndex = _getRandomInt(0, scheduleTypeList.length);
|
|
|
+ final Schedule schedule = Schedule(
|
|
|
+ day: date,
|
|
|
+ type: scheduleTypeList[typeIndex],
|
|
|
+ title: '${scheduleTypeList[typeIndex].typeName} - Mock标题',
|
|
|
+ content: '日程内容',
|
|
|
+ );
|
|
|
+ scheduleList.add(schedule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int _getRandomInt(int min, int max) {
|
|
|
+ final Random random = Random();
|
|
|
+ return min + random.nextInt(max - min);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -201,6 +262,7 @@ class CalendarController extends GetxController {
|
|
|
currentYear = now.year;
|
|
|
currentMonth = now.month;
|
|
|
miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ _setMiniCalendarSchedule();
|
|
|
}
|
|
|
for (var element in miniViewDaysList) {
|
|
|
if (element.isToday) {
|
|
@@ -211,14 +273,22 @@ class CalendarController extends GetxController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- void _setSchedule(List<DateTime> scheduleList) {
|
|
|
-
|
|
|
- for (var element in scheduleList) {
|
|
|
- for (var day in miniViewDaysList) {
|
|
|
- if (element.year == day.date.year &&
|
|
|
- element.month == day.date.month &&
|
|
|
- element.day == day.date.day) {
|
|
|
+ void _setMiniCalendarSchedule() {
|
|
|
+
|
|
|
+ for (var day in miniViewDaysList) {
|
|
|
+ day.hasSchedule = false;
|
|
|
+ for (var element in scheduleList) {
|
|
|
+ var existSchedule = false;
|
|
|
+ if (element.day.year == day.date.year &&
|
|
|
+ element.day.month == day.date.month &&
|
|
|
+ element.day.day == day.date.day) {
|
|
|
+ if (_isDisplayScheduleType(element.type.typeName)) {
|
|
|
+ existSchedule = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (existSchedule) {
|
|
|
day.hasSchedule = true;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -233,6 +303,8 @@ class CalendarController extends GetxController {
|
|
|
currentMonth--;
|
|
|
}
|
|
|
miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ _setMiniCalendarSchedule();
|
|
|
+
|
|
|
_selectFirstDay();
|
|
|
|
|
|
onDaysListChange.emit(this, null);
|
|
@@ -247,8 +319,28 @@ class CalendarController extends GetxController {
|
|
|
currentMonth++;
|
|
|
}
|
|
|
miniViewDaysList = _countDaysList(currentYear, currentMonth);
|
|
|
+ _setMiniCalendarSchedule();
|
|
|
_selectFirstDay();
|
|
|
|
|
|
onDaysListChange.emit(this, null);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ List<Schedule> scheduleListFilter(List<Schedule> scheduleList) {
|
|
|
+ final List<Schedule> result = [];
|
|
|
+ for (Schedule element in scheduleList) {
|
|
|
+ if (_isDisplayScheduleType(element.type.typeName)) {
|
|
|
+ result.add(element);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bool _isDisplayScheduleType(String typeName) {
|
|
|
+ if (needDisplayTypeNameList.contains(typeName)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|