Skip to content

Commit

Permalink
add highlight current day and lesson
Browse files Browse the repository at this point in the history
  • Loading branch information
smart7even committed Sep 4, 2024
1 parent 7652757 commit 324e189
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
37 changes: 31 additions & 6 deletions lib/feature/schedule/widget/lesson_tile.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:uneconly/common/localization/localization.dart';
import 'package:uneconly/feature/schedule/model/lesson.dart';

class LessonTile extends StatefulWidget {
const LessonTile({
super.key,
required this.lesson,
required this.currentTime,
});

final Lesson lesson;
final DateTime currentTime;

@override
State<LessonTile> createState() => _LessonTileState();
Expand Down Expand Up @@ -39,21 +42,43 @@ class _LessonTileState extends State<LessonTile> {

subtitle = _appendWithSpace(subtitle, location);

final isCurrentLesson = widget.currentTime.isAfter(widget.lesson.start) &&
widget.currentTime.isBefore(widget.lesson.end);

return ListTile(
title: Text(
widget.lesson.name,
maxLines: _isExpanded ? 5 : 1,
overflow: TextOverflow.ellipsis,
// style: isCurrentLesson
// ? TextStyle(color: Theme.of(context).primaryColor)
// : const TextStyle(),
),
subtitle: Text(
subtitle,
),
trailing: Text(
'${DateFormat('HH:mm').format(
widget.lesson.start,
)} - ${DateFormat('HH:mm').format(
widget.lesson.end,
)}',
trailing: Container(
padding: const EdgeInsets.symmetric(
horizontal: 2,
vertical: 2,
),
// rounded corners
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: isCurrentLesson ? Theme.of(context).primaryColor : null,
),
child: Text(
'${DateFormat('HH:mm').format(
widget.lesson.start,
)} - ${DateFormat('HH:mm').format(
widget.lesson.end,
)}',
style: TextStyle(
color: isCurrentLesson
? Theme.of(context).colorScheme.onPrimary
: null,
),
),
),
onTap: () {
setState(() {
Expand Down
14 changes: 14 additions & 0 deletions lib/feature/schedule/widget/schedule_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class _SchedulePageState extends State<SchedulePage>
final List<Group> favoriteGroups = [];
bool isFavorite = false;

Timer? _rebuildTimer;

/* #region Lifecycle */
@override
void initState() {
Expand Down Expand Up @@ -91,11 +93,23 @@ class _SchedulePageState extends State<SchedulePage>
});
},
);

_rebuildTimer = Timer.periodic(
const Duration(minutes: 1),
(timer) {
if (context.mounted) {
setState(() {
log('rebuild');
});
}
},
);
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_rebuildTimer?.cancel();
super.dispose();
}

Expand Down
14 changes: 9 additions & 5 deletions lib/feature/schedule/widget/schedule_widget.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:l/l.dart';
import 'package:octopus/octopus.dart';
import 'package:uneconly/common/localization/localization.dart';
import 'package:uneconly/common/routing/routes.dart';
Expand Down Expand Up @@ -44,14 +43,15 @@ class ScheduleWidget extends StatelessWidget {
return slivers;
}

final today = DateTime.now();

for (var daySchedule in currentSchedule.daySchedules) {
String sectionTitle = capitalize(
DateFormat('EEEE, d MMMM', 'ru').format(
daySchedule.day,
),
);

final today = DateTime.now();
final difference = calculateDifferenceInDays(daySchedule.day, today);

if (difference == 0) {
Expand All @@ -69,9 +69,10 @@ class ScheduleWidget extends StatelessWidget {
child: ListTile(
title: Text(
sectionTitle,
style: const TextStyle(
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: difference == 0 ? Theme.of(context).primaryColor : null,
),
),
),
Expand All @@ -92,7 +93,10 @@ class ScheduleWidget extends StatelessWidget {
(BuildContext context, int index) {
final lesson = daySchedule.lessons[index];

return LessonTile(lesson: lesson);
return LessonTile(
lesson: lesson,
currentTime: today,
);
},
childCount: daySchedule.lessons.length,
),
Expand Down

0 comments on commit 324e189

Please sign in to comment.