123 lines
4.0 KiB
Dart
123 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_calendar_carousel/classes/event.dart';
|
|
import 'package:flutter_calendar_carousel/classes/event_list.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:intl/intl.dart';
|
|
import '../../ftc_mobile_app.dart';
|
|
|
|
class CalendarViewScreenController extends GetxController {
|
|
GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
RxBool isLoading = false.obs;
|
|
|
|
// Rx<EventList<Event>> markedDatesMap = EventList<Event>(events: {},).obs;
|
|
Rx<DateTime> targetDateTime = DateTime(2024, 1, 1).obs;
|
|
RxString currentMonthName =
|
|
DateFormat.yMMM().format(DateTime(2024, 1, 1)).obs;
|
|
Rx<EventList<Event>> events = EventList<Event>(
|
|
events: {},
|
|
).obs;
|
|
// RxList<MarkDatesModel> markedDatesList = RxList();
|
|
RxList<RotaShift> datesToShowList = RxList();
|
|
Rx<MarkDatesModel> selectedDate = MarkDatesModel.empty().obs;
|
|
|
|
// RxList<MonthWiseRecord> monthWiseRecord = RxList();
|
|
RxList<RotaShift> rotaShiftList = RxList();
|
|
|
|
@override
|
|
void onInit() {
|
|
fetchRecords();
|
|
super.onInit();
|
|
}
|
|
|
|
void markDatesOnCalendar() {
|
|
// markedDatesList.removeAt(0); //for removing late initialization error
|
|
// for (var rotaShift in rotaShiftList) {
|
|
// markedDatesList.add(
|
|
// MarkDatesModel.addDate(date: rotaShift.shiftTime, title: "Possible"));
|
|
// datesToShowList.add(rotaShift);
|
|
// }
|
|
|
|
// for (var markedDate in markedDatesList) {
|
|
// markedDatesMap.value.add(
|
|
// DateTime(
|
|
// markedDate.date.year, markedDate.date.month, markedDate.date.day),
|
|
// Event(
|
|
// date: DateTime(
|
|
// markedDate.date.year, markedDate.date.month, markedDate.date.day),
|
|
// // date: markedDate.date,
|
|
// title: markedDate.title,
|
|
// icon: markedDate.title == "Possible"
|
|
// ? _underlineIcon(
|
|
// markedDate.date.day.toString(),
|
|
// )
|
|
// : _shiftIcon(
|
|
// markedDate.date.day.toString(),
|
|
// ),
|
|
// ),
|
|
// );
|
|
// }
|
|
// datesToShowList = datesToShowList; // to ask from panday G
|
|
}
|
|
|
|
Widget _shiftIcon(String day) => CircleAvatar(
|
|
backgroundColor: CustomAppColors.kSecondaryColor,
|
|
child: Text(
|
|
day,
|
|
style:
|
|
const TextStyle(color: CustomAppColors.kWhiteColor, fontSize: 13),
|
|
),
|
|
);
|
|
|
|
Widget _underlineIcon(String day) => Container(
|
|
alignment: Alignment.center,
|
|
decoration: const BoxDecoration(
|
|
border: Border(
|
|
bottom: BorderSide(
|
|
color: CustomAppColors.kSecondaryColor,
|
|
width: 3.0,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
void onNextMonthTap() {
|
|
targetDateTime.value = DateTime(targetDateTime.value.year,
|
|
targetDateTime.value.month + 1, targetDateTime.value.day);
|
|
currentMonthName.value = DateFormat.yMMM().format(targetDateTime.value);
|
|
}
|
|
|
|
void onPreviousMonthTap() {
|
|
targetDateTime.value = DateTime(targetDateTime.value.year,
|
|
targetDateTime.value.month - 1, targetDateTime.value.day);
|
|
currentMonthName.value = DateFormat.yMMM().format(targetDateTime.value);
|
|
}
|
|
|
|
void removeFocus() {
|
|
FocusScope.of(scaffoldKey.currentContext!).unfocus();
|
|
}
|
|
|
|
Future<void> fetchRecords() async {
|
|
isLoading.value = true;
|
|
// markedDatesList.add(MarkDatesModel.addDate(
|
|
// date: DateTime(2022, 6, 1),
|
|
// title: "Possible")); //for removing late initialization error
|
|
for (var index = 1; index <= 12; index++) {
|
|
var result = await RotaService().serviceUserShifts(
|
|
serviceUserId: "65682ad0a01b6c9e6dcde088", month: index, year: 2024);
|
|
if (result is MonthWiseRecord) {
|
|
// monthWiseRecord.add(result);
|
|
rotaShiftList.addAll(FrequentFunctions().findDaysWithData(result));
|
|
} else {
|
|
|
|
}
|
|
}
|
|
|
|
targetDateTime = rotaShiftList.first.shiftTime.obs;
|
|
currentMonthName =
|
|
DateFormat.yMMM().format(rotaShiftList.first.shiftTime).obs;
|
|
isLoading.value = false;
|
|
markDatesOnCalendar();
|
|
}
|
|
}
|