From 9505fe9bedde270be3342a5882bc4b15e518b22c Mon Sep 17 00:00:00 2001 From: Armand <4831c0@proton.me> Date: Thu, 4 Sep 2025 10:43:39 +0200 Subject: [PATCH] home/main: show next test --- firka/lib/ui/phone/pages/home/home_main.dart | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/firka/lib/ui/phone/pages/home/home_main.dart b/firka/lib/ui/phone/pages/home/home_main.dart index 256b001..3865624 100644 --- a/firka/lib/ui/phone/pages/home/home_main.dart +++ b/firka/lib/ui/phone/pages/home/home_main.dart @@ -6,14 +6,18 @@ import 'package:firka/ui/phone/widgets/info_board_item.dart'; import 'package:firka/ui/phone/widgets/lesson_small.dart'; import 'package:firka/ui/widget/delayed_spinner.dart'; import 'package:flutter/material.dart'; +import 'package:majesticons_flutter/majesticons_flutter.dart'; import '../../../../helpers/api/model/notice_board.dart'; import '../../../../helpers/api/model/student.dart'; +import '../../../../helpers/api/model/test.dart'; import '../../../../helpers/api/model/timetable.dart'; import '../../../../helpers/debug_helper.dart'; +import '../../../../helpers/ui/firka_card.dart'; import '../../../../helpers/update_notifier.dart'; import '../../../../main.dart'; import '../../../model/style.dart'; +import '../../../widget/firka_icon.dart'; import '../../widgets/home_main_welcome.dart'; import '../../widgets/lesson_big.dart'; @@ -36,6 +40,7 @@ class _HomeMainScreen extends State { List? lessons; List? noticeBoard; List? infoBoard; + List? tests; Student? student; Timer? timer; @@ -77,6 +82,9 @@ class _HomeMainScreen extends State { var respStudent = await widget.data.client.getStudent(forceCache: forceCache); + var testsResp = await widget.data.client.getTests(forceCache: forceCache); + tests = testsResp.response; + return Future.value(( respTT.response!, respNB.response!, @@ -128,6 +136,7 @@ class _HomeMainScreen extends State { Widget build(BuildContext context) { Widget welcomeWidget = SizedBox(); Widget nextClass = SizedBox(); + Widget? nextTest; bool lessonActive = false; if (lessons != null && noticeBoard != null && lessons!.isNotEmpty) { @@ -157,6 +166,42 @@ class _HomeMainScreen extends State { if (nextLesson != null) { nextClass = LessonSmallWidget(widget.data.l10n, nextLesson, lessonActive); + + if (tests != null) { + final testsOnDate = tests! + .where((test) => + test.date.isAfter(nextLesson.start + .getMidnight() + .subtract(Duration(seconds: 1))) && + test.date.isBefore(nextLesson.end + .getMidnight() + .add(Duration(hours: 23, minutes: 59))) && + test.subject.uid == nextLesson.subject?.uid) + .toList(); + + if (testsOnDate.isNotEmpty) { + final test = testsOnDate.first; + + nextTest = FirkaCard( + left: [ + FirkaIconWidget( + FirkaIconType.majesticons, + Majesticon.editPen4Solid, + color: appStyle.colors.accent, + ), + SizedBox(width: 6), + Text(test.theme, + style: appStyle.fonts.B_14SB + .apply(color: appStyle.colors.textSecondary)) + ], + right: [ + Text(test.method.description ?? "N/A", + style: appStyle.fonts.B_14R + .apply(color: appStyle.colors.textTertiary)) + ], + ); + } + } } } @@ -182,6 +227,9 @@ class _HomeMainScreen extends State { welcomeWidget, lessonActive ? SizedBox(height: 5) : SizedBox(height: 0), nextClass, + nextTest != null ? SizedBox(height: 12) : SizedBox(height: 0), + nextTest ?? SizedBox(), + nextTest != null ? SizedBox(height: 12) : SizedBox(height: 0), Expanded( child: ListView( children: noticeBoardWidgets,