import 'dart:ui'; import 'package:timemanagerapp/entity/Course.dart'; import 'package:timemanagerapp/setting/Setting.dart'; class CourseWidgetController { final double pixelToMinuteRatio = 0.9 * Setting.pixelToMinuteRatio_ratio; //old:0.9 late List courseList; late DateTime mondayTime; late int weekCount; late DateTime termStartDate; CourseWidgetController() { mondayTime = getmondayTime(); termStartDate = Setting.startdate; weekCount = getWeekCount(); } //getInstance static CourseWidgetController getInstance() { return new CourseWidgetController(); } static final List testcourseList = [ Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 18, 7, 20), end: DateTime(2023, 9, 18, 10, 0)), Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 19, 7, 20), end: DateTime(2023, 9, 19, 10, 0)), Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 20, 7, 20), end: DateTime(2023, 9, 20, 10, 0)), Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 21, 7, 20), end: DateTime(2023, 9, 21, 10, 0)), Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 22, 7, 20), end: DateTime(2023, 9, 22, 10, 0)), Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 23, 7, 20), end: DateTime(2023, 9, 23, 10, 0)), Course( userId: 1, courseId: 2, name: 'Math', credit: 3, teacher: 'Mr. Smith', location: 'Room 101', remark: "null", start: DateTime(2023, 9, 24, 7, 20), end: DateTime(2023, 9, 24, 10, 0)), ]; //时间转换为时间轴的piexl值的函数 List convertTimeList(List timePoints, double deviceWidth) { List convertedTimes = []; for (var time in timePoints) { int hour = time.hour; int minute = time.minute; int totalMinutes = (hour - 7) * 60 + minute; double convertedTime = totalMinutes * pixelToMinuteRatio; convertedTimes.add(Offset(deviceWidth * 0.015, convertedTime)); } return convertedTimes; } int getWeekCount() { weekCount = DateTime.now().difference(termStartDate).inDays ~/ 7 + 1; return weekCount; } DateTime getmondayTime() { mondayTime = DateTime.now(); //获取本周星期一是几号 while (mondayTime.weekday != 1) { mondayTime = mondayTime.subtract(Duration(days: 1)); } return mondayTime; } Map> transformCourseMap(List courseList) { Map> courseMap = {}; for (var course in courseList) { int weekCount = course.start.difference(termStartDate).inDays ~/ 7 + 1; // if (courseMap.containsKey(weekCount)) { courseMap[weekCount]!.add(course); } else { courseMap[weekCount] = [course]; } } return courseMap; } }