1
0
forked from firka/firka

implement lesson/big

This commit is contained in:
2025-07-14 21:44:07 +02:00
parent 284d97a02b
commit 1e3c3d5000
3 changed files with 297 additions and 23 deletions

View File

@@ -5,28 +5,59 @@ import '../../ui/model/style.dart';
class FirkaCard extends StatelessWidget {
List<Widget> left;
List<Widget>? right;
Widget? extra;
FirkaCard({required this.left, this.right, super.key});
FirkaCard({required this.left, this.right, this.extra, super.key});
@override
Widget build(BuildContext context) {
var right = this.right ?? [];
return SizedBox(
width: MediaQuery.of(context).size.width,
child: Card(
color: appStyle.colors.card,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: left),
Row(children: right),
],
if (extra != null) {
return SizedBox(
width: MediaQuery
.of(context)
.size
.width,
child: Card(
color: appStyle.colors.card,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: left),
Row(children: right),
],
),
extra ?? SizedBox(),
],
),
),
),
),
);
);
} else {
return SizedBox(
width: MediaQuery
.of(context)
.size
.width,
child: Card(
color: appStyle.colors.card,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: left),
Row(children: right),
],
),
),
),
);
}
}
}

View File

@@ -11,6 +11,7 @@ import '../../../../helpers/api/model/timetable.dart';
import '../../../../helpers/debug_helper.dart';
import '../../../../main.dart';
import '../../widgets/home_main_welcome.dart';
import '../../widgets/lesson_big.dart';
class HomeMainScreen extends StatefulWidget {
final AppInitialization data;
@@ -69,17 +70,34 @@ class _HomeMainScreen extends State<HomeMainScreen> {
@override
Widget build(BuildContext context) {
Widget startingSoon = SizedBox();
Widget welcomeWidget = SizedBox();
Widget nextClass = SizedBox();
if (lessons != null &&
lessons!.isNotEmpty &&
now.isBefore(lessons!.first.start)) {
startingSoon = StartingSoonWidget(now, lessons!);
if (lessons != null && lessons!.isNotEmpty) {
if (now.isBefore(lessons!.first.start)) {
welcomeWidget = StartingSoonWidget(now, lessons!);
} else {
var currentLesson = lessons!.firstWhereOrNull(
(lesson) => now.isAfter(lesson.start) && now.isBefore(lesson.end));
// "fun" fact if your clock was exactly when the class ends then isBefore
// and isAfter would fail, so to work around that we just add 1ms to the
// current time
var prevLesson = lessons!.firstWhereOrNull((lesson) =>
lesson.end.isBefore(now.add(Duration(milliseconds: 1))));
var nextLesson = lessons!.firstWhereOrNull((lesson) =>
lesson.start.isAfter(now.add(Duration(milliseconds: 1))));
int? lessonIndex;
if (currentLesson != null) lessonIndex = currentLesson.getNo(lessons!);
welcomeWidget = LessonBigWidget(
now, lessonIndex, currentLesson, prevLesson, nextLesson);
}
}
if (lessons != null && lessons!.isNotEmpty) {
var nextLessons = lessons!.where((lesson) => lesson.start.isAfter(now));
if (nextLessons.isNotEmpty) nextClass = LessonSmallWidget(nextLessons.first);
var nextLesson =
lessons!.firstWhereOrNull((lesson) => lesson.start.isAfter(now));
if (nextLesson != null) nextClass = LessonSmallWidget(nextLesson);
}
if (student != null && lessons != null) {
@@ -95,7 +113,7 @@ class _HomeMainScreen extends State<HomeMainScreen> {
children: [
WelcomeWidget(now, student!, lessons!),
SizedBox(height: 48),
startingSoon,
welcomeWidget,
nextClass
],
),

View File

@@ -0,0 +1,225 @@
import 'package:firka/helpers/extensions.dart';
import 'package:firka/helpers/ui/firka_card.dart';
import 'package:firka/l10n/app_localizations.dart';
import 'package:firka/ui/model/style.dart';
import 'package:firka/ui/widget/firka_icon.dart';
import 'package:flutter/material.dart';
import '../../../helpers/api/model/timetable.dart';
import '../../widget/class_icon_widget.dart';
class LessonBigWidget extends StatelessWidget {
final DateTime now;
final int? lessonNo;
final Lesson? lesson;
final Lesson? prevLesson;
final Lesson? nextLesson;
const LessonBigWidget(
this.now, this.lessonNo, this.lesson, this.prevLesson, this.nextLesson,
{super.key});
@override
Widget build(BuildContext context) {
var hasLesson = lesson != null;
var hasPrevLesson = prevLesson != null;
var hasNextLesson = nextLesson != null;
if (!hasLesson && (!hasPrevLesson || !hasNextLesson)) {
throw Exception(
'!hasLesson($hasLesson) && (!hasPrevLesson($hasPrevLesson) || '
'!hasNextLesson($hasNextLesson))');
}
if (hasLesson) {
var timeLeft = lesson!.end.difference(now);
var duration = lesson!.end.difference(lesson!.start).inMilliseconds;
var progress = now.difference(lesson!.start).inMilliseconds;
var minsLeft = timeLeft.inMinutes;
var secsLeft = timeLeft.inSeconds;
var timeLeftStr =
"$minsLeft ${minsLeft == 1 ? AppLocalizations.of(context)!.starting_min : AppLocalizations.of(context)!.starting_min_plural}";
if (minsLeft < 1) {
timeLeftStr =
"$secsLeft ${secsLeft == 1 ? AppLocalizations.of(context)!.starting_sec : AppLocalizations.of(context)!.starting_sec_plural}";
}
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
FirkaCard(
left: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Card(
// TODO: improve this to match design
shadowColor: Colors.transparent,
color: appStyle.colors.a15p,
child: Padding(
padding: EdgeInsets.all(4),
child: Text(lessonNo.toString(),
style: appStyle.fonts.B_12R
.apply(color: appStyle.colors.secondary)),
),
),
Card(
shadowColor: Colors.transparent,
color: appStyle.colors.a15p,
child: Padding(
padding: EdgeInsets.all(4),
child: ClassIconWidget(
color: wearStyle.colors.accent,
size: 24,
uid: lesson!.uid,
className: lesson!.name,
category: lesson!.subject?.name ?? '',
),
),
),
Text(lesson!.subject?.name ?? 'N/A',
style: appStyle.fonts.B_16SB
.apply(color: appStyle.colors.textPrimary)),
],
),
Row(
children: [
Text(timeLeftStr,
style: appStyle.fonts.B_12R
.apply(color: appStyle.colors.textSecondary)),
],
),
],
)
],
right: [
Column(
children: [
Row(
children: [
Text(
lesson!.start
.toLocal()
.format(context, FormatMode.hmm),
style: appStyle.fonts.B_14R
.apply(color: appStyle.colors.textPrimary)),
Card(
shadowColor: Colors.transparent,
color: appStyle.colors.a15p,
child: Padding(
padding: EdgeInsets.all(4),
child: Text(lesson!.roomName ?? '?',
style: appStyle.fonts.B_12R
.apply(color: appStyle.colors.secondary)),
),
)
],
),
Row(
children: [
SizedBox(width: 18),
Text(
lesson!.end.toLocal().format(context, FormatMode.hmm),
style: appStyle.fonts.B_12R
.apply(color: appStyle.colors.textSecondary)),
],
)
],
)
],
extra: LinearProgressIndicator(
// TODO: Make this rounded
value: progress / duration,
backgroundColor: appStyle.colors.a15p,
color: appStyle.colors.accent,
),
)
],
);
} else {
var duration =
nextLesson!.start.difference(prevLesson!.end).inMilliseconds;
var progress =
duration - nextLesson!.start.difference(now).inMilliseconds;
var timeLeft = nextLesson!.start.difference(now);
var timeLeftStr =
AppLocalizations.of(context)!.timeLeft(timeLeft.inMinutes + 1);
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
FirkaCard(
left: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Card(
shadowColor: Colors.transparent,
color: appStyle.colors.a15p,
child: Padding(
padding: EdgeInsets.all(4),
child: FirkaIconWidget(
FirkaIconType.MajesticonsLocal, 'cupFilled',
color: wearStyle.colors.accent, size: 24),
),
),
Text(AppLocalizations.of(context)!.breakTxt,
style: appStyle.fonts.B_16SB
.apply(color: appStyle.colors.textPrimary)),
],
),
Row(
children: [
Text(timeLeftStr,
style: appStyle.fonts.B_12R
.apply(color: appStyle.colors.textSecondary)),
],
),
],
)
],
right: [
Column(
children: [
Row(
children: [
Text(
prevLesson!.end
.toLocal()
.format(context, FormatMode.hmm),
style: appStyle.fonts.B_14R
.apply(color: appStyle.colors.textPrimary)),
],
),
Row(
children: [
Text(
nextLesson!.start
.toLocal()
.format(context, FormatMode.hmm),
style: appStyle.fonts.B_14R
.apply(color: appStyle.colors.textPrimary)),
],
)
],
)
],
extra: LinearProgressIndicator(
// TODO: Make this rounded
value: progress / duration,
backgroundColor: appStyle.colors.a15p,
color: appStyle.colors.accent,
),
)
],
);
}
}
}