39 lines
1.3 KiB
Dart
39 lines
1.3 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:reverse_nn/application/services/schedule.dart';
|
|
import 'package:reverse_nn/ui/screens/calendar_screen.dart';
|
|
|
|
class CalendarScheduleController extends GetxController {
|
|
Rx<DateTime> date = DateTime.now().copyWith(hour: 12, minute: 00).obs;
|
|
RxBool loading = false.obs;
|
|
Rx<List<Map<String, dynamic>>?> schedule = null.obs;
|
|
|
|
@override void onReady() {
|
|
super.onReady();
|
|
loadSchedule(date.value);
|
|
}
|
|
|
|
void loadSchedule(DateTime date) async {
|
|
loading = true.obs; update();
|
|
schedule = (await ScheduleService().getScheduleByDate(date)).obs;
|
|
loading = false.obs; update();
|
|
}
|
|
|
|
static void openScreen() async { Get.to(() => const CalendarScreen()); }
|
|
|
|
void goToConcreteDay(DateTime day) async {
|
|
date = (day.copyWith(hour: 12, minute: 0, millisecond: 0, microsecond: 0)).obs;
|
|
loadSchedule(date.value);
|
|
}
|
|
|
|
void goToPrevDay() async {
|
|
if(date.value.isBefore(DateTime(2024, 8, 1, 23, 59))) return;
|
|
date = (date.value.copyWith().subtract(const Duration(days: 1)).copyWith(hour: 12, minute: 0)).obs;
|
|
loadSchedule(date.value);
|
|
}
|
|
|
|
void goToNextDay() async {
|
|
if(date.value.isAfter(DateTime(2025, 12, 31))) return;
|
|
date = (date.value.copyWith().add(const Duration(days: 1)).copyWith(hour: 12, minute: 0)).obs;
|
|
loadSchedule(date.value);
|
|
}
|
|
} |