Skip to content

Commit

Permalink
[timetable] display courses in timetable details
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Mar 19, 2024
1 parent 70456a5 commit 145107e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
11 changes: 7 additions & 4 deletions lib/timetable/page/mine.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:collection/collection.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -370,6 +371,7 @@ class _TimetableDetailsPageState extends State<TimetableDetailsPage> {
final actions = widget.actions;
final palette = TimetableInit.storage.palette.selectedRow ?? BuiltinTimetablePalettes.classic;
final courses = timetable.courses.values.toList();
final code2Courses = courses.groupListsBy((c) => c.courseCode).entries.toList();
return Scaffold(
body: CustomScrollView(
slivers: [
Expand All @@ -396,12 +398,13 @@ class _TimetableDetailsPageState extends State<TimetableDetailsPage> {
const Divider(),
]),
SliverList.builder(
itemCount: courses.length,
itemCount: code2Courses.length,
itemBuilder: (ctx, i) {
final course = courses[i];
final MapEntry(key:code,value:courses) = code2Courses[i];
return TimetableCourseCard(
course,
color: resolver.resolveColor(palette, course).byTheme(context.theme),
courses: courses,
courseName: courses.first.courseName,
color: resolver.resolveColor(palette, courses.first).byTheme(context.theme),
);
},
)
Expand Down
37 changes: 26 additions & 11 deletions lib/timetable/widgets/course.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
import 'package:flutter/material.dart';
import 'package:rettulf/rettulf.dart';
import 'package:sit/design/widgets/card.dart';
import 'package:sit/design/widgets/expansion_tile.dart';
import 'package:sit/l10n/time.dart';
import 'package:sit/school/widgets/course.dart';
import 'package:sit/timetable/entity/timetable.dart';

class TimetableCourseCard extends StatelessWidget {
final SitCourse course;
final String courseName;
final List<SitCourse> courses;
final Color color;

const TimetableCourseCard(
this.course, {
const TimetableCourseCard({
super.key,
required this.courseName,
required this.courses,
required this.color,
});

@override
Widget build(BuildContext context) {
return FilledCard(
child: ListTile(
isThreeLine: true,
leading: CourseIcon(courseName: course.courseName),
title: course.courseName.text(),
subtitle: [
if (course.place.isNotEmpty) course.place.text(),
if (course.teachers.isNotEmpty) course.teachers.join(", ").text(),
].column(caa: CrossAxisAlignment.start),
clip: Clip.hardEdge,
child: AnimatedExpansionTile(
leading: CourseIcon(courseName: courseName),
initiallyExpanded: true,
rotateTrailing: false,
title: courseName.text(),
trailing: FilledCard(
color: color,
child: const SizedBox(width: 32, height: 32),
),
children: courses.map((course) {
final weekNumbers = course.weekIndices.l10n();
final (:begin, :end) = course.calcBeginEndTimePoint();
return ListTile(
isThreeLine: true,
title: course.place.text(),
trailing: course.teachers.join(", ").text(),
subtitle: [
"${Weekday.fromIndex(course.dayIndex).l10n()} ${begin.l10n(context)}–${end.l10n(context)}".text(),
...weekNumbers.map((n) => n.text()),
].column(mas: MainAxisSize.min, caa: CrossAxisAlignment.start),
);
}).toList(),
),
);
}
Expand Down

0 comments on commit 145107e

Please sign in to comment.