Skip to content

Commit 34b8020

Browse files
committed
next week on weekend
1 parent 0601b6f commit 34b8020

File tree

4 files changed

+187
-270
lines changed

4 files changed

+187
-270
lines changed

lib/core/injection.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,9 @@ Future<void> init() async {
9696
//! Repositories
9797
//!
9898

99-
sl.registerLazySingleton(() {
100-
final Client client = Client().setEndpoint(appwrite).setProject('campus_app');
101-
return BackendRepository(client: client);
102-
});
99+
sl.registerLazySingleton(
100+
() => BackendRepository(client: sl()),
101+
);
103102

104103
sl.registerSingletonWithDependencies(
105104
() => NewsRepository(newsDatasource: sl()),
@@ -120,10 +119,6 @@ Future<void> init() async {
120119
() => TicketRepository(ticketDataSource: sl(), secureStorage: sl()),
121120
);
122121

123-
sl.registerLazySingleton(
124-
() => BackendRepository(client: sl()),
125-
);
126-
127122
//!
128123
//! Usecases
129124
//!

lib/pages/mensa/mensa_page.dart

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ class MensaPageState extends State<MensaPage> with WidgetsBindingObserver, Autom
4949
late List<DishEntity> unikidsDishes = [];
5050
late List<Failure> failures = [];
5151

52-
late int selectedDay;
52+
// Weekday to show as selected
53+
int selectedDay = -1;
5354

54-
DateTime selectedDate = DateTime.now().weekday == 6
55-
? DateTime.now().subtract(const Duration(days: 1))
56-
: DateTime.now().weekday == 7
57-
? DateTime.now().subtract(const Duration(days: 2))
58-
: DateTime.now();
55+
// Weekday that is selected
56+
DateTime selectedDate = DateTime.now();
5957

6058
StreamController<DateTime> streamController = StreamController<DateTime>.broadcast();
6159

@@ -258,28 +256,17 @@ class MensaPageState extends State<MensaPage> with WidgetsBindingObserver, Autom
258256
@override
259257
void initState() {
260258
super.initState();
259+
final DateTime today = DateTime.now();
260+
final DateTime startOfWeek = today.subtract(Duration(days: today.weekday - 1));
261261

262-
// Add observer in order to listen to `didChangeAppLifecycleState`
263-
WidgetsBinding.instance.addObserver(this);
262+
// Choose selected day: Mo -> 0 ... Fr -> 4, Sa & So -> 5 (next monday)
263+
selectedDay = today.weekday > 5 ? today.weekday - 1 : 5;
264264

265-
switch (DateTime.now().weekday) {
266-
case 1: // Monday
267-
selectedDay = 0;
268-
break;
269-
case 2: // Tuesday
270-
selectedDay = 1;
271-
break;
272-
case 3: // Wednesday
273-
selectedDay = 2;
274-
break;
275-
case 4: // Thursday
276-
selectedDay = 3;
277-
break;
278-
default: // Friday, Saturday or Sunday
279-
selectedDay = 4;
280-
break;
281-
}
265+
// Choose selected date to load data: today or next monday on weekend
266+
selectedDate = today.weekday > 5 ? today : startOfWeek.add(const Duration(days: 7));
282267

268+
// Add observer in order to listen to `didChangeAppLifecycleState`
269+
WidgetsBinding.instance.addObserver(this);
283270
loadData();
284271
}
285272

0 commit comments

Comments
 (0)