NEW: MIH Calendar Provider Setup

This commit is contained in:
2025-10-21 13:00:52 +02:00
parent b2ed1e0b51
commit 926b749fa8
12 changed files with 576 additions and 484 deletions

View File

@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mih_calendar_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:provider/provider.dart';
import 'package:table_calendar/table_calendar.dart';
class MIHCalendar extends StatefulWidget {
@@ -19,16 +22,29 @@ class MIHCalendar extends StatefulWidget {
}
class _MIHCalendarState extends State<MIHCalendar> {
DateTime selectedDay = DateTime.now();
late DateTime selectedDay;
CalendarFormat _calendarFormat = CalendarFormat.week;
void onDaySelected(DateTime day, DateTime focusedDay) {
KenLogger.success("Selected Day: $day");
setState(() {
selectedDay = day;
});
widget.setDate(selectedDay.toString().split(" ")[0]);
}
@override
void initState() {
super.initState();
MihCalendarProvider mihCalendarProvider =
context.read<MihCalendarProvider>();
if (mihCalendarProvider.selectedDay.isNotEmpty) {
selectedDay = DateTime.parse(mihCalendarProvider.selectedDay);
} else {
selectedDay = DateTime.now();
}
}
@override
Widget build(BuildContext context) {
return SizedBox(

View File

@@ -1,7 +1,11 @@
import 'package:flutter/foundation.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/appointment.dart';
class MihCalendarProvider extends ChangeNotifier {
int toolIndex;
String selectedDay = DateTime.now().toString().split(" ")[0];
List<Appointment>? personalAppointments;
List<Appointment>? businessAppointments;
MihCalendarProvider({
this.toolIndex = 0,
@@ -11,4 +15,66 @@ class MihCalendarProvider extends ChangeNotifier {
toolIndex = index;
notifyListeners();
}
void setSelectedDay(String day) {
selectedDay = day;
notifyListeners();
}
void resetSelectedDay() {
selectedDay = DateTime.now().toString().split(" ")[0];
notifyListeners();
}
void setPersonalAppointments({required List<Appointment> appointments}) {
personalAppointments = appointments;
notifyListeners();
}
void setBusinessAppointments({required List<Appointment> appointments}) {
businessAppointments = appointments;
notifyListeners();
}
void addPersonalAppointment({required Appointment newAppointment}) {
personalAppointments?.add(newAppointment);
notifyListeners();
}
void addBusinessAppointment({required Appointment newAppointment}) {
businessAppointments?.add(newAppointment);
notifyListeners();
}
void editPersonalAppointment({required Appointment updatedAppointment}) {
int index = personalAppointments?.indexWhere((appointment) =>
appointment.idappointments == updatedAppointment.idappointments) ??
-1;
if (index != -1) {
personalAppointments?[index] = updatedAppointment;
notifyListeners();
}
}
void editBusinessAppointment({required Appointment updatedAppointment}) {
int index = businessAppointments?.indexWhere((appointment) =>
appointment.idappointments == updatedAppointment.idappointments) ??
-1;
if (index != -1) {
businessAppointments?[index] = updatedAppointment;
notifyListeners();
}
}
void deletePersonalAppointment({required int appointmentId}) {
personalAppointments?.removeWhere(
(appointment) => appointment.idappointments == appointmentId);
notifyListeners();
}
void deleteBusinessAppointment({required int appointmentId}) {
businessAppointments?.removeWhere(
(appointment) => appointment.idappointments == appointmentId);
notifyListeners();
}
}