From beba61ae868cf77819e3e6cf721404821e620803 Mon Sep 17 00:00:00 2001 From: b3ni15 Date: Tue, 2 Sep 2025 23:12:57 +0200 Subject: [PATCH] Refactor date handling logic in HomeTimetableScreen to improve active date selection --- .../lib/ui/phone/pages/home/home_timetable.dart | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/firka/lib/ui/phone/pages/home/home_timetable.dart b/firka/lib/ui/phone/pages/home/home_timetable.dart index 28b6a17..99e101a 100644 --- a/firka/lib/ui/phone/pages/home/home_timetable.dart +++ b/firka/lib/ui/phone/pages/home/home_timetable.dart @@ -80,13 +80,19 @@ class _HomeTimetableScreen extends State { if (!mounted) return; setState(() { this.dates = dates; - if (now.isAfter(dates.last)) { + final todayMid = now.getMidnight(); + int idx = dates.indexWhere((d) => + d.year == todayMid.year && + d.month == todayMid.month && + d.day == todayMid.day); + + if (idx >= 0) { + active = idx; + } else if (now.isAfter(dates.last)) { active = dates.length - 1; } else { - active = dates.indexWhere((d) => - d.isAfter(now.getMidnight()) && - d.isBefore( - now.getMidnight().add(Duration(hours: 23, minutes: 59)))); + idx = dates.indexWhere((d) => d.isAfter(todayMid)); + active = idx >= 0 ? idx : 0; } }); }