Skip to content

Commit e53a2ba

Browse files
committed
fix: output time arragement no experiments and exam
1 parent ff5f0e0 commit e53a2ba

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

lib/page/classtable/classtable_state.dart

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,38 @@ class ClassTableWidgetState with ChangeNotifier {
348348
}
349349
}
350350
}
351+
352+
// Add exam data and experiment data here.
353+
for (var i in subjects) {
354+
String summary = "SUMMARY:"
355+
"${i.subject} ${i.typeStr}"
356+
"@${i.place} ${i.seat != null ? "-${i.seat}" : ""}\n";
357+
String description = "DESCRIPTION:"
358+
"考试信息:${i.subject}\n"
359+
"类型:${i.typeStr}\n"
360+
"地点:${i.place} ${i.seat != null ? "-${i.seat}" : ""}\n";
361+
String vevent = "BEGIN:VEVENT\n$summary";
362+
vevent +=
363+
"DTSTART;TZID:Asia/Shanghai:${i.startTime!.format(pattern: 'yyyyMMddTHHmmss')}\n";
364+
vevent +=
365+
"DTEND;TZID:Asia/Shanghai:${i.stopTime!.format(pattern: 'yyyyMMddTHHmmss')}\n";
366+
toReturn += "$vevent${description}END:VEVENT\n";
367+
}
368+
369+
for (var i in experiments) {
370+
String summary = "SUMMARY:"
371+
"${i.name}@${i.classroom}}\n";
372+
String description = "DESCRIPTION:"
373+
"物理实验:${i.name}\n"
374+
"地点:${i.classroom}\n";
375+
String vevent = "BEGIN:VEVENT\n$summary";
376+
vevent +=
377+
"DTSTART;TZID:Asia/Shanghai:${Jiffy.parseFromDateTime(i.time.first).format(pattern: 'yyyyMMddTHHmmss')}\n";
378+
vevent +=
379+
"DTEND;TZID:Asia/Shanghai:${Jiffy.parseFromDateTime(i.time.last).format(pattern: 'yyyyMMddTHHmmss')}\n";
380+
toReturn += "$vevent${description}END:VEVENT\n";
381+
}
382+
351383
return "${toReturn}END:VCALENDAR";
352384
}
353385

@@ -508,6 +540,73 @@ class ClassTableWidgetState with ChangeNotifier {
508540
}
509541
}
510542
}
543+
544+
// Add exam data and experiment data here.
545+
for (var i in subjects) {
546+
String title = "${i.subject} ${i.typeStr}"
547+
"@${i.place} ${i.seat != null ? "-${i.seat}" : ""}";
548+
String description = "考试信息:${i.subject}\n"
549+
"类型:${i.typeStr}\n"
550+
"地点:${i.place} ${i.seat != null ? "-${i.seat}" : ""}";
551+
552+
Result<String>? addEventResult =
553+
await deviceCalendarPlugin.createOrUpdateEvent(Event(
554+
calendarId,
555+
title: title,
556+
description: description,
557+
start: TZDateTime.from(
558+
i.startTime!.dateTime,
559+
currentLocation,
560+
),
561+
end: TZDateTime.from(
562+
i.stopTime!.dateTime,
563+
currentLocation,
564+
),
565+
));
566+
// If got error, return with false.
567+
if (addEventResult == null ||
568+
addEventResult.data == null ||
569+
addEventResult.data!.isEmpty) {
570+
log.info(
571+
"[Classtable][outputToCalendar] "
572+
"Add failed: "
573+
"${hasPermitted.errors.map((e) => e.errorMessage).join(",")}",
574+
);
575+
return false;
576+
}
577+
}
578+
579+
for (var i in experiments) {
580+
String title = "${i.name}@${i.classroom}}";
581+
String description = "物理实验:${i.name}\n"
582+
"地点:${i.classroom}";
583+
Result<String>? addEventResult =
584+
await deviceCalendarPlugin.createOrUpdateEvent(Event(
585+
calendarId,
586+
title: title,
587+
description: description,
588+
start: TZDateTime.from(
589+
i.time.first,
590+
currentLocation,
591+
),
592+
end: TZDateTime.from(
593+
i.time.last,
594+
currentLocation,
595+
),
596+
));
597+
// If got error, return with false.
598+
if (addEventResult == null ||
599+
addEventResult.data == null ||
600+
addEventResult.data!.isEmpty) {
601+
log.info(
602+
"[Classtable][outputToCalendar] "
603+
"Add failed: "
604+
"${hasPermitted.errors.map((e) => e.errorMessage).join(",")}",
605+
);
606+
return false;
607+
}
608+
}
609+
511610
return true;
512611
}
513612

0 commit comments

Comments
 (0)