Skip to content
Snippets Groups Projects
Commit d165f484 authored by doodlezucc's avatar doodlezucc
Browse files

refactor lesson label into separate widget

parent b02dd74d
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import '../context.dart';
import '../util/simultaneous.dart';
import '../untis/lesson.dart';
import 'lesson_dialog.dart';
import 'lesson_label.dart';
typedef FloatingLesson = SimultaneousInstance<Lesson>;
......@@ -19,11 +20,6 @@ class LessonWidget extends StatelessWidget {
: floatingLesson.fractionPosition /
(floatingLesson.simultaneousCount - 1);
String get text => [
lesson.lecture.name,
lesson.rooms.firstOrNull?.name ?? '(Kein Raum)',
].join('\n');
const LessonWidget({
super.key,
required this.floatingLesson,
......@@ -50,7 +46,7 @@ class LessonWidget extends StatelessWidget {
widthFactor: 1 / floatingLesson.simultaneousCount,
alignment: Alignment(-1 + 2 * widthFactor, 0),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
padding: const EdgeInsets.symmetric(horizontal: 1),
child: Material(
elevation: 2,
color: Theme.of(context).primaryColor,
......@@ -60,14 +56,11 @@ class LessonWidget extends StatelessWidget {
onTap: () => onTap(context),
child: Container(
height: (lesson.endMinutes - lesson.startMinutes) * zoom,
padding: const EdgeInsets.all(8),
child: Center(
child: Text(
text,
textAlign: TextAlign.center,
style: Theme.of(context).primaryTextTheme.bodySmall!,
),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 8,
),
child: LessonLabel(lesson: lesson),
),
),
),
......
import 'package:flutter/material.dart';
import '../untis/lesson.dart';
class LessonLabel extends StatelessWidget {
final Lesson lesson;
String get room => lesson.rooms.firstOrNull?.nameSplit ?? '(Kein Raum)';
String get lecture => lesson.lecture.name;
const LessonLabel({super.key, required this.lesson});
@override
Widget build(BuildContext context) {
return RichText(
text: TextSpan(
children: [
TextSpan(
text: room,
style: const TextStyle(fontWeight: FontWeight.bold),
),
const TextSpan(text: '\n\n'),
WidgetSpan(
child: Text(
lecture.substring(0, lecture.length - 5),
style: const TextStyle(overflow: TextOverflow.ellipsis),
)),
TextSpan(text: lecture.substring(lecture.length - 5)),
],
style: Theme.of(context).primaryTextTheme.bodySmall!,
),
textAlign: TextAlign.center,
);
}
}
......@@ -7,7 +7,6 @@ import '../untis/lesson.dart';
import 'lesson.dart';
class TimeIndicator extends StatefulWidget {
static const double indicatorHeightPx = 2;
final int progressInMinutes;
const TimeIndicator({super.key, required this.progressInMinutes});
......@@ -25,17 +24,9 @@ class _TimeIndicatorState extends State<TimeIndicator> {
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
color: passedTimeOverlayColor,
height: max(0, yPosition - TimeIndicator.indicatorHeightPx),
),
Container(
height: TimeIndicator.indicatorHeightPx,
color: Theme.of(context).colorScheme.primaryContainer,
),
],
return Container(
color: passedTimeOverlayColor,
height: max(0, yPosition),
);
}
}
......@@ -8,5 +8,7 @@ class Room extends UntisElement {
? fullName.substring(0, fullName.indexOf('(')).trimRight()
: fullName;
String get nameSplit => name.replaceFirst('-', ' - ');
Room(super.json);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment