rename container folders

This commit is contained in:
2026-01-29 11:11:45 +02:00
parent d5349d981c
commit 5b052a1fa9
654 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,309 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_objects/access_request.dart';
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:supertokens_flutter/http.dart' as http;
class BuildAccessRequestList extends StatefulWidget {
final List<AccessRequest> accessRequests;
final AppUser signedInUser;
const BuildAccessRequestList({
super.key,
required this.accessRequests,
required this.signedInUser,
});
@override
State<BuildAccessRequestList> createState() => _BuildPatientsListState();
}
class _BuildPatientsListState extends State<BuildAccessRequestList> {
String baseAPI = AppEnviroment.baseApiUrl;
late double popUpWidth;
late double? popUpheight;
late double popUpButtonWidth;
late double popUpTitleSize;
late double popUpSubtitleSize;
late double popUpBodySize;
late double popUpIconSize;
late double popUpPaddingSize;
late double width;
late double height;
Future<void> updateAccessAPICall(int index, String accessType) async {
var response = await http.put(
Uri.parse("$baseAPI/access-requests/update/"),
headers: <String, String>{
"Content-Type": "application/json; charset=UTF-8"
},
body: jsonEncode(<String, dynamic>{
"business_id": widget.accessRequests[index].business_id,
"app_id": widget.accessRequests[index].app_id,
"date_time": widget.accessRequests[index].date_time,
"access": accessType,
}),
);
if (response.statusCode == 200) {
//Navigator.of(context).pushNamed('/home');
Navigator.of(context).pop();
Navigator.of(context).pop();
Navigator.of(context).pushNamed(
'/patient-access-review',
arguments: widget.signedInUser,
);
String message = "";
if (accessType == "approved") {
message =
"You've successfully approved the access request! ${widget.accessRequests[index].Name} now has access to your profile until ${widget.accessRequests[index].revoke_date.substring(0, 16).replaceAll("T", " ")}.";
} else {
message =
"You've declined the access request. ${widget.accessRequests[index].Name} will not have access to your profile.";
}
MihAlertServices().successBasicAlert(
"Success!",
message,
context,
);
} else {
MihAlertServices().internetConnectionAlert(context);
}
}
Widget displayQueue(int index) {
String line1 =
"Appointment: ${widget.accessRequests[index].date_time.substring(0, 16).replaceAll("T", " ")}";
String line2 = "";
line2 += "Requestor: ${widget.accessRequests[index].Name}\n";
//subtitle += "Business Type: ${widget.accessRequests[index].type}\n";
String line3 = "Access: ";
String access = "";
var nowDate = DateTime.now();
var expireyDate = DateTime.parse(widget.accessRequests[index].revoke_date);
if (expireyDate.isBefore(nowDate)) {
access += "EXPIRED";
} else {
access += "${widget.accessRequests[index].access.toUpperCase()}";
}
String line4 = "";
if (widget.accessRequests[index].revoke_date.contains("9999")) {
line4 += "Access Expiration date: NOT SET";
} else {
line4 +=
"Access Expiration date: ${widget.accessRequests[index].revoke_date.substring(0, 10)}";
}
TextSpan accessWithColour;
if (access == "APPROVED") {
accessWithColour = TextSpan(
text: "$access\n",
style: TextStyle(
color: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark")));
} else if (access == "PENDING") {
accessWithColour = TextSpan(
text: "$access\n",
style: TextStyle(
color: MihColors.getGreyColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark")));
} else {
accessWithColour = TextSpan(
text: "$access\n",
style: TextStyle(
color: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark")));
}
return ListTile(
title: Text(
line1,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
),
subtitle: RichText(
text: TextSpan(
text: line2,
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: line3),
accessWithColour,
TextSpan(text: line4),
]),
),
// Text(
// subtitle,
// style: TextStyle(
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
// ),
onTap: () {
if (access == "CANCELLED") {
MihAlertServices().warningAlert(
"Access Cancelled",
"This appointment has been canceled. As a result, access has been cancelled and the doctor no longer have access to the patient's profile. If you would like them to view the patient's profile again, please book a new appointment through them.",
context,
);
} else {
viewApprovalPopUp(index);
}
},
// trailing: Icon(
// Icons.arrow_forward,
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
);
}
void checkScreenSize() {
if (MzansiInnovationHub.of(context)!.theme.screenType == "desktop") {
setState(() {
popUpWidth = (width / 4) * 2;
popUpheight = null;
popUpButtonWidth = 300;
popUpTitleSize = 25.0;
popUpSubtitleSize = 20.0;
popUpBodySize = 15;
popUpPaddingSize = 25.0;
popUpIconSize = 100;
});
} else {
setState(() {
popUpWidth = width - (width * 0.1);
popUpheight = null;
popUpButtonWidth = 300;
popUpTitleSize = 20.0;
popUpSubtitleSize = 18.0;
popUpBodySize = 15;
popUpPaddingSize = 15.0;
popUpIconSize = 100;
});
}
}
void viewApprovalPopUp(int index) {
String subtitle =
"Appointment: ${widget.accessRequests[index].date_time.substring(0, 16).replaceAll("T", " ")}\n";
subtitle += "Requestor: ${widget.accessRequests[index].Name}\n";
subtitle += "Business Type: ${widget.accessRequests[index].type}\n\n";
subtitle +=
"You are about to approve an access request to your patient profile.\nPlease be aware that once approved, ${widget.accessRequests[index].Name} will have access to your profile information until ${widget.accessRequests[index].revoke_date.substring(0, 16).replaceAll("T", " ")}.\nIf you are unsure about an upcoming appointment with ${widget.accessRequests[index].Name}, please contact ${widget.accessRequests[index].contact_no} for clarification before approving this request.\n";
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => MihPackageWindow(
fullscreen: false,
windowTitle: "Update Appointment Access",
windowBody: Column(
children: [
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Text(
subtitle,
textAlign: TextAlign.left,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: popUpBodySize,
//fontWeight: FontWeight.bold,
),
),
),
Wrap(
runAlignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.center,
runSpacing: 10,
spacing: 10,
children: [
MihButton(
onPressed: () {
updateAccessAPICall(index, "declined");
},
buttonColor: MihColors.getRedColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Decline",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
MihButton(
onPressed: () {
updateAccessAPICall(index, "approved");
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
width: 300,
child: Text(
"Approve",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
),
const SizedBox(
height: 10,
),
],
),
onWindowTapClose: () {
Navigator.pop(context);
}),
);
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
setState(() {
width = size.width;
height = size.height;
});
checkScreenSize();
return ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
separatorBuilder: (BuildContext context, index) {
return Divider(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
},
itemCount: widget.accessRequests.length,
itemBuilder: (context, index) {
//final patient = widget.patients[index].id_no.contains(widget.searchString);
//print(index);
return displayQueue(index);
},
);
}
}

View File

@@ -0,0 +1,765 @@
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_objects/appointment.dart';
import 'package:mzansi_innovation_hub/mih_providers/mih_calendar_provider.dart';
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_calendar_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_date_field.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_form.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_time_field.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class BuildAppointmentList extends StatefulWidget {
final bool inWaitingRoom;
final TextEditingController titleController;
final TextEditingController descriptionIDController;
final TextEditingController? patientIdController;
final TextEditingController dateController;
final TextEditingController timeController;
const BuildAppointmentList({
super.key,
required this.inWaitingRoom,
required this.titleController,
required this.descriptionIDController,
required this.patientIdController,
required this.dateController,
required this.timeController,
});
@override
State<BuildAppointmentList> createState() => _BuildAppointmentListState();
}
class _BuildAppointmentListState extends State<BuildAppointmentList> {
String baseAPI = AppEnviroment.baseApiUrl;
TextEditingController patientIdController = TextEditingController();
TextEditingController dateController = TextEditingController();
TextEditingController timeController = TextEditingController();
TextEditingController idController = TextEditingController();
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
TextEditingController daysExtensionController = TextEditingController();
final _formKey = GlobalKey<FormState>();
int counter = 0;
late double width;
late double height;
void clearControllers() {
widget.titleController.clear();
widget.descriptionIDController.clear();
widget.dateController.clear();
widget.timeController.clear();
}
double getPaddingSize() {
if (MzansiInnovationHub.of(context)!.theme.screenType == "desktop") {
return (width / 10);
} else {
return 0.0;
}
}
Widget displayAppointment(MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider, int index, double bodyWidth) {
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!
: mihCalendarProvider.businessAppointments!;
// SAFELY EXTRACT DATE AND TIME
String dateTimeString = appointmentList[index].date_time;
String timePart = "";
String datePart = "";
if (dateTimeString.contains("T")) {
List<String> parts = dateTimeString.split('T');
datePart = parts[0];
timePart = parts[1].substring(0, 5);
} else if (dateTimeString.contains(" ")) {
List<String> parts = dateTimeString.split(' ');
datePart = parts[0];
timePart = parts[1].substring(0, 5);
} else {
// Fallback if format is unexpected
datePart = dateTimeString;
timePart = "00:00";
}
String heading =
"$timePart - ${appointmentList[index].title.toUpperCase()}";
String description = appointmentList[index].description;
DateTime now = DateTime.now();
int hourNow = int.parse(now.toString().split(' ')[1].substring(0, 2));
String currentDate =
DateTime(now.year, now.month, now.day).toString().split(' ')[0];
int appointHour = int.parse(timePart.split(':')[0]);
Color appointmentColor = MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
if (currentDate == datePart) {
if (appointHour < hourNow) {
appointmentColor = MihColors.getGreyColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
} else if (appointHour == hourNow) {
appointmentColor = MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
}
} else if (DateTime.parse(datePart).isBefore(DateTime.parse(currentDate))) {
appointmentColor = MihColors.getGreyColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark");
}
return Container(
decoration: BoxDecoration(
border: Border.all(
width: 3.0,
color: appointmentColor,
),
borderRadius: BorderRadius.circular(20)),
child: ListTile(
title: Text(
heading,
style: TextStyle(
color: appointmentColor,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
description,
style: TextStyle(
color: appointmentColor,
overflow: TextOverflow.ellipsis,
),
),
onTap: () {
// SAFELY SET CONTROLLER VALUES
setState(() {
widget.titleController.text = appointmentList[index].title;
widget.descriptionIDController.text =
appointmentList[index].description;
widget.dateController.text = datePart;
widget.timeController.text = timePart;
});
if (widget.inWaitingRoom == false) {
appointmentDetailsWindow(
mzansiProfileProvider, mihCalendarProvider, index, bodyWidth);
} else {
waitingRoomAppointmentDetailsWindow(
mzansiProfileProvider, mihCalendarProvider, index, bodyWidth);
}
},
),
);
}
void appointmentDetailsWindow(MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider, int index, double bodyWidth) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Appointment Details",
menuOptions: [
SpeedDialChild(
child: Icon(
Icons.edit,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Edit Appointment",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
appointmentUpdateWindow(mzansiProfileProvider,
mihCalendarProvider, index, bodyWidth);
},
),
SpeedDialChild(
child: Icon(
Icons.delete,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Delete Appointment",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
deleteAppointmentConfirmationWindow(
mzansiProfileProvider, mihCalendarProvider, index);
},
),
],
onWindowTapClose: () {
context.pop();
clearControllers();
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.titleController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Appointment Title",
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.dateController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Date",
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.timeController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Time",
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.descriptionIDController,
multiLineInput: true,
height: 250,
requiredText: true,
readOnly: true,
hintText: "Appointment Description",
),
const SizedBox(height: 10),
],
),
),
);
},
);
}
void waitingRoomAppointmentDetailsWindow(
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
int index,
double bodyWidth) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Appointment Details",
menuOptions: [
SpeedDialChild(
child: Icon(
Icons.edit,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Edit Appointment",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
appointmentUpdateWindow(mzansiProfileProvider,
mihCalendarProvider, index, bodyWidth);
},
),
SpeedDialChild(
child: Icon(
Icons.delete,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
label: "Delete Appointment",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
deleteAppointmentConfirmationWindow(
mzansiProfileProvider, mihCalendarProvider, index);
},
),
],
onWindowTapClose: () {
context.pop();
clearControllers();
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.titleController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Appointment Title",
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.dateController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Date",
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.timeController,
multiLineInput: false,
requiredText: true,
readOnly: true,
hintText: "Time",
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
controller: widget.descriptionIDController,
multiLineInput: true,
height: 250,
requiredText: true,
readOnly: true,
hintText: "Appointment Description",
),
const SizedBox(height: 10),
// SizedBox(
// // width: 500,
// child: MIHTextField(
// controller: widget.titleController,
// hintText: "Patient ID Number",
// editable: false,
// required: false,
// ),
// ),
// const SizedBox(height: 10),
],
),
),
);
},
);
}
void appointmentUpdateWindow(MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider, int index, double bodyWidth) {
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!
: mihCalendarProvider.businessAppointments!;
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Update Appointment",
onWindowTapClose: () {
setState(() {
widget.titleController.text = appointmentList[index].title;
widget.descriptionIDController.text =
appointmentList[index].description;
widget.dateController.text =
appointmentList[index].date_time.split('T')[0];
widget.timeController.text = appointmentList[index]
.date_time
.split('T')[1]
.substring(0, 5);
});
context.pop();
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
MihForm(
formKey: _formKey,
formFields: [
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: widget.titleController,
multiLineInput: false,
requiredText: true,
hintText: "Appointment Title",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10),
MihDateField(
controller: widget.dateController,
labelText: "Date",
required: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10),
MihTimeField(
controller: widget.timeController,
labelText: "Time",
required: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: widget.descriptionIDController,
multiLineInput: true,
height: 250,
requiredText: true,
hintText: "Appointment Description",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 20),
Center(
child: Wrap(
runAlignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.center,
runSpacing: 10,
spacing: 10,
children: [
MihButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
updateAppointmentCall(mzansiProfileProvider,
mihCalendarProvider, index);
} else {
MihAlertServices().inputErrorAlert(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Update",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!
.theme
.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
],
),
],
),
),
);
},
);
}
bool isAppointmentInputValid() {
if (widget.dateController.text.isEmpty ||
widget.timeController.text.isEmpty) {
return false;
} else {
return true;
}
}
void deleteAppointmentConfirmationWindow(
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
int index) {
MihAlertServices().deleteConfirmationAlert(
"This appointment will be deleted permanently from your calendar. Are you certain you want to delete it?",
() {
deleteAppointmentCall(
mzansiProfileProvider, mihCalendarProvider, index);
},
context,
);
}
Future<void> updateAppointmentCall(
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
int index) async {
int statusCode;
if (isAppointmentInputValid()) {
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!
: mihCalendarProvider.businessAppointments!;
KenLogger.success("ersonalHome: ${mzansiProfileProvider.personalHome}");
if (mzansiProfileProvider.personalHome == true) {
statusCode = await MihMzansiCalendarApis.updatePersonalAppointment(
mzansiProfileProvider.user!,
mzansiProfileProvider.business,
null,
appointmentList[index].idappointments,
widget.titleController.text,
widget.descriptionIDController.text,
widget.dateController.text,
widget.timeController.text,
mihCalendarProvider,
context,
);
} else if (mzansiProfileProvider.personalHome == false &&
widget.inWaitingRoom == false) {
statusCode = await MihMzansiCalendarApis.updateBusinessAppointment(
mzansiProfileProvider.user!,
mzansiProfileProvider.business,
mzansiProfileProvider.businessUser,
appointmentList[index].idappointments,
widget.titleController.text,
widget.descriptionIDController.text,
widget.dateController.text,
widget.timeController.text,
mihCalendarProvider,
context,
);
} else {
statusCode = await MihMzansiCalendarApis.updatePatientAppointment(
mzansiProfileProvider.user!,
mzansiProfileProvider.business,
mzansiProfileProvider.businessUser,
appointmentList[index].idappointments,
widget.titleController.text,
widget.descriptionIDController.text,
widget.dateController.text,
widget.timeController.text,
context,
);
}
if (statusCode == 200) {
context.pop();
context.pop();
successPopUp("Successfully Updated Appointment",
"You appointment has been successfully updated.");
} else {
MihAlertServices().internetConnectionAlert(context);
}
} else {
MihAlertServices().inputErrorAlert(context);
}
}
Future<void> deleteAppointmentCall(
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
int index) async {
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!
: mihCalendarProvider.businessAppointments!;
int statucCode = await MihMzansiCalendarApis.deleteAppointmentAPICall(
mzansiProfileProvider.user!,
mzansiProfileProvider.personalHome,
mzansiProfileProvider.business,
mzansiProfileProvider.businessUser,
widget.inWaitingRoom,
appointmentList[index].idappointments,
mihCalendarProvider,
context,
);
if (statucCode == 200) {
context.pop();
context.pop();
clearControllers();
// successPopUp("Successfully Deleted Appointment",
// "You appointment has been successfully deleted from your calendar.");
} else {
MihAlertServices().internetConnectionAlert(context);
}
}
void successPopUp(String title, String message) {
MihAlertServices().successAdvancedAlert(
title,
message,
[
MihButton(
onPressed: () {
clearControllers();
Navigator.of(context).pop();
},
buttonColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
context,
);
}
bool canEditAppointment(MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider, int index) {
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!
: mihCalendarProvider.businessAppointments!;
if (mzansiProfileProvider.personalHome == true &&
appointmentList[index].app_id == mzansiProfileProvider.user!.app_id &&
appointmentList[index].business_id == "") {
return true;
} else if (mzansiProfileProvider.personalHome == false &&
appointmentList[index].business_id ==
mzansiProfileProvider.business!.business_id &&
appointmentList[index].app_id.isEmpty) {
return true;
} else if (mzansiProfileProvider.personalHome == false &&
appointmentList[index].business_id ==
mzansiProfileProvider.business!.business_id &&
appointmentList[index].app_id.isNotEmpty) {
return true;
} else {
return false;
}
}
@override
void dispose() {
daysExtensionController.dispose();
dateController.dispose();
timeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
setState(() {
width = size.width;
height = size.height;
});
return Consumer2<MzansiProfileProvider, MihCalendarProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
Widget? child) {
// List<Appointment> appointmentList = mzansiProfileProvider.personalHome
// ? mihCalendarProvider.personalAppointments!
// : mihCalendarProvider.businessAppointments!;
return Padding(
padding: EdgeInsets.symmetric(horizontal: getPaddingSize()),
child: ListView.builder(
itemCount: mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!.length
: mihCalendarProvider.businessAppointments!.length,
itemBuilder: (context, index) {
return displayAppointment(
mzansiProfileProvider, mihCalendarProvider, index, width);
},
),
);
},
);
}
}

View File

@@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_objects/patient_queue.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
class BuildQueueList extends StatefulWidget {
final List<PatientQueue> patientQueue;
final AppUser signedInUser;
const BuildQueueList({
super.key,
required this.patientQueue,
required this.signedInUser,
});
@override
State<BuildQueueList> createState() => _BuildQueueListState();
}
class _BuildQueueListState extends State<BuildQueueList> {
String baseAPI = AppEnviroment.baseApiUrl;
TextEditingController dateController = TextEditingController();
TextEditingController timeController = TextEditingController();
TextEditingController idController = TextEditingController();
TextEditingController fnameController = TextEditingController();
TextEditingController lnameController = TextEditingController();
TextEditingController daysExtensionController = TextEditingController();
int counter = 0;
Widget displayQueue(int index) {
String title = widget.patientQueue[index].business_name.toUpperCase();
// widget.patientQueue[index].date_time.split('T')[1].substring(0, 5);
String line234 = "";
// var nowDate = DateTime.now();
// var expireyDate = DateTime.parse(widget.patientQueue[index].revoke_date);
line234 +=
widget.patientQueue[index].date_time.split('T')[1].substring(0, 5);
return ListTile(
title: Text(
title,
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
),
subtitle: RichText(
text: TextSpan(
text: "Time: $line234",
style: DefaultTextStyle.of(context).style,
// children: [
// TextSpan(text: line5),
// accessWithColour,
// TextSpan(text: line6),
// ]
),
),
onTap: () {},
);
}
bool isAccessExpired(String accessType) {
if (accessType == "EXPIRED") {
return true;
} else {
return false;
}
}
@override
void dispose() {
daysExtensionController.dispose();
dateController.dispose();
timeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ListView.separated(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
separatorBuilder: (BuildContext context, index) {
return Divider(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
},
itemCount: widget.patientQueue.length,
itemBuilder: (context, index) {
//final patient = widget.patients[index].id_no.contains(widget.searchString);
//print(index);
return displayQueue(index);
},
);
}
}

View File

@@ -0,0 +1,115 @@
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_action.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tools.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_providers/mih_calendar_provider.dart';
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_packages/calendar/package_tools/appointments.dart';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_data_helper_services.dart';
import 'package:provider/provider.dart';
class MzansiCalendar extends StatefulWidget {
const MzansiCalendar({
super.key,
});
@override
State<MzansiCalendar> createState() => _MzansiCalendarState();
}
class _MzansiCalendarState extends State<MzansiCalendar> {
bool _isLoadingInitialData = true;
late final Appointments _appointments;
Future<void> _loadInitialData() async {
setState(() {
_isLoadingInitialData = true;
});
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
if (mzansiProfileProvider.user == null) {
await MihDataHelperServices().loadUserDataOnly(
mzansiProfileProvider,
);
}
setState(() {
_isLoadingInitialData = false;
});
}
@override
void initState() {
super.initState();
_appointments = Appointments();
_loadInitialData();
}
@override
Widget build(BuildContext context) {
return Consumer<MihCalendarProvider>(
builder: (BuildContext context, MihCalendarProvider calendarProvider,
Widget? child) {
if (_isLoadingInitialData) {
return Scaffold(
body: Center(
child: Mihloadingcircle(),
),
);
}
return MihPackage(
appActionButton: getAction(),
appTools: getTools(),
appBody: getToolBody(),
appToolTitles: getToolTitle(),
selectedbodyIndex: calendarProvider.toolIndex,
onIndexChange: (newIndex) {
calendarProvider.setToolIndex(newIndex);
},
);
},
);
}
MihPackageAction getAction() {
return MihPackageAction(
icon: const Icon(Icons.arrow_back),
iconSize: 35,
onTap: () {
context.read<MihCalendarProvider>().resetSelectedDay();
context.goNamed(
'mihHome',
);
FocusScope.of(context).unfocus();
},
);
}
MihPackageTools getTools() {
Map<Widget, void Function()?> temp = {};
temp[const Icon(Icons.calendar_month)] = () {
context.read<MihCalendarProvider>().setToolIndex(0);
};
return MihPackageTools(
tools: temp,
selcetedIndex: context.watch<MihCalendarProvider>().toolIndex,
);
}
List<Widget> getToolBody() {
return [
_appointments,
];
}
List<String> getToolTitle() {
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
List<String> toolTitles = [
mzansiProfileProvider.personalHome == true ? "Personal" : "Business",
];
return toolTitles;
}
}

View File

@@ -0,0 +1,45 @@
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tile.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
class MzansiCalendarTile extends StatefulWidget {
final double packageSize;
const MzansiCalendarTile({
super.key,
required this.packageSize,
});
@override
State<MzansiCalendarTile> createState() => _MzansiCalendarTileState();
}
class _MzansiCalendarTileState extends State<MzansiCalendarTile> {
@override
Widget build(BuildContext context) {
return MihPackageTile(
onTap: () {
context.goNamed(
"mihCalendar",
);
// Navigator.of(context).pushNamed(
// '/calendar',
// arguments: widget.arguments,
// );
},
appName: "Calendar",
appIcon: Icon(
MihIcons.calendar,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// size: widget.packageSize,
),
iconSize: widget.packageSize,
textColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
);
}
}

View File

@@ -0,0 +1,484 @@
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_calendar.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_icons.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_loading_circle.dart';
import 'package:mzansi_innovation_hub/mih_providers/mih_calendar_provider.dart';
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_calendar_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_button.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_date_field.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_form.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_tool_body.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_floating_menu.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_package_window.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_package_components/mih_time_field.dart';
import 'package:mzansi_innovation_hub/mih_objects/appointment.dart';
import 'package:mzansi_innovation_hub/mih_packages/calendar/builder/build_appointment_list.dart';
import 'package:provider/provider.dart';
class Appointments extends StatefulWidget {
const Appointments({
super.key,
});
@override
State<Appointments> createState() => _PatientAccessRequestState();
}
class _PatientAccessRequestState extends State<Appointments> {
TextEditingController selectedAppointmentDateController =
TextEditingController();
final TextEditingController _appointmentTitleController =
TextEditingController();
final TextEditingController _appointmentDescriptionIDController =
TextEditingController();
final TextEditingController _appointmentDateController =
TextEditingController();
final TextEditingController _appointmentTimeController =
TextEditingController();
bool isLoading = true;
final _formKey = GlobalKey<FormState>();
Widget displayAppointmentList(MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider) {
List<Appointment> appointmentList = mzansiProfileProvider.personalHome
? mihCalendarProvider.personalAppointments!
: mihCalendarProvider.businessAppointments!;
return appointmentList.isNotEmpty
? Expanded(
child: BuildAppointmentList(
inWaitingRoom: false,
titleController: _appointmentTitleController,
descriptionIDController: _appointmentDescriptionIDController,
patientIdController: null,
dateController: _appointmentDateController,
timeController: _appointmentTimeController,
),
)
: Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 50),
Icon(
MihIcons.calendar,
size: 165,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
),
const SizedBox(height: 10),
Text(
"No appointments for ${mihCalendarProvider.selectedDay}",
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
),
const SizedBox(height: 25),
Center(
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.normal,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
children: [
TextSpan(text: "Press "),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Icon(
Icons.menu,
size: 20,
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
),
TextSpan(
text:
" to add an appointment or select a different date"),
],
),
),
),
],
),
),
);
}
void addAppointmentWindow(MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider, double width) {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return MihPackageWindow(
fullscreen: false,
windowTitle: "Add Appointment",
onWindowTapClose: () {
context.pop();
_appointmentDateController.clear();
_appointmentTimeController.clear();
_appointmentTitleController.clear();
_appointmentDescriptionIDController.clear();
},
windowBody: Padding(
padding:
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05)
: const EdgeInsets.symmetric(horizontal: 0),
child: Column(
children: [
MihForm(
formKey: _formKey,
formFields: [
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: _appointmentTitleController,
multiLineInput: false,
requiredText: true,
hintText: "Appointment Title",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10),
MihDateField(
controller: _appointmentDateController,
labelText: "Date",
required: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10),
MihTimeField(
controller: _appointmentTimeController,
labelText: "Time",
required: true,
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 10),
MihTextFormField(
fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
inputColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
controller: _appointmentDescriptionIDController,
multiLineInput: true,
height: 250,
requiredText: true,
hintText: "Appointment Description",
validator: (value) {
return MihValidationServices().isEmpty(value);
},
),
const SizedBox(height: 20),
Center(
child: MihButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
addAppointmentCall(
mzansiProfileProvider, mihCalendarProvider);
} else {
MihAlertServices().inputErrorAlert(context);
}
},
buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
width: 300,
child: Text(
"Add",
style: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
],
),
),
);
},
);
}
bool isAppointmentInputValid() {
if (_appointmentTitleController.text.isEmpty ||
_appointmentDescriptionIDController.text.isEmpty ||
_appointmentDateController.text.isEmpty ||
_appointmentTimeController.text.isEmpty) {
return false;
} else {
return true;
}
}
Future<void> addAppointmentCall(
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
) async {
if (isAppointmentInputValid()) {
int statusCode;
if (mzansiProfileProvider.personalHome == false) {
statusCode = await MihMzansiCalendarApis.addBusinessAppointment(
mzansiProfileProvider.user!,
mzansiProfileProvider.business!,
mzansiProfileProvider.businessUser!,
false,
_appointmentTitleController.text,
_appointmentDescriptionIDController.text,
_appointmentDateController.text,
_appointmentTimeController.text,
mihCalendarProvider,
context,
);
} else {
statusCode = await MihMzansiCalendarApis.addPersonalAppointment(
mzansiProfileProvider.user!,
_appointmentTitleController.text,
_appointmentDescriptionIDController.text,
_appointmentDateController.text,
_appointmentTimeController.text,
mihCalendarProvider,
context,
);
}
if (statusCode == 201) {
context.pop();
successPopUp("Successfully Added Appointment",
"You appointment has been successfully added to your calendar.");
if (mzansiProfileProvider.personalHome == true) {
await MihMzansiCalendarApis.getPersonalAppointments(
mzansiProfileProvider.user!.app_id,
mihCalendarProvider.selectedDay,
mihCalendarProvider,
);
} else {
await MihMzansiCalendarApis.getBusinessAppointments(
mzansiProfileProvider.business!.business_id,
false,
mihCalendarProvider.selectedDay,
mihCalendarProvider,
);
}
} else {
MihAlertServices().internetConnectionAlert(context);
}
} else {
MihAlertServices().inputErrorAlert(context);
}
checkforchange();
}
void successPopUp(String title, String message) {
MihAlertServices().successAdvancedAlert(
title,
message,
[
MihButton(
onPressed: () {
context.pop();
setState(() {
_appointmentDateController.clear();
_appointmentTimeController.clear();
_appointmentTitleController.clear();
_appointmentDescriptionIDController.clear();
});
},
buttonColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
elevation: 10,
width: 300,
child: Text(
"Dismiss",
style: TextStyle(
color: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
],
context,
);
}
String getTitle(MzansiProfileProvider mzansiProfileProvider) {
if (mzansiProfileProvider.personalHome == false) {
return "Business Appointments";
} else {
return "Personal Appointments";
}
}
void checkforchange() {
setState(() {
isLoading = true;
});
_loadInitialAppointments();
}
Widget getBody(double width) {
if (isLoading) {
return const Center(
child: Mihloadingcircle(),
);
}
return Consumer2<MzansiProfileProvider, MihCalendarProvider>(
builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider,
MihCalendarProvider mihCalendarProvider,
Widget? child) {
return Stack(
children: [
Column(
children: [
MIHCalendar(
calendarWidth: 500,
rowHeight: 35,
setDate: (value) {
mihCalendarProvider.setSelectedDay(value);
setState(() {
selectedAppointmentDateController.text = value;
});
}),
// Divider(
// color: MihColors.getSecondaryColor(MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
// ),
displayAppointmentList(
mzansiProfileProvider,
mihCalendarProvider,
)
],
),
Positioned(
right: 10,
bottom: 10,
child: MihFloatingMenu(
icon: Icons.add,
animatedIcon: AnimatedIcons.menu_close,
children: [
SpeedDialChild(
child: Icon(
Icons.add,
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
),
label: "Add Appointment",
labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
labelStyle: TextStyle(
color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontWeight: FontWeight.bold,
),
backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
onTap: () {
addAppointmentWindow(
mzansiProfileProvider, mihCalendarProvider, width);
},
)
],
),
),
],
);
},
);
}
Future<void> _loadInitialAppointments() async {
MzansiProfileProvider mzansiProfileProvider =
context.read<MzansiProfileProvider>();
MihCalendarProvider mihCalendarProvider =
context.read<MihCalendarProvider>();
if (mzansiProfileProvider.personalHome == false) {
await MihMzansiCalendarApis.getBusinessAppointments(
mzansiProfileProvider.business!.business_id,
false,
mihCalendarProvider.selectedDay,
mihCalendarProvider,
);
} else {
await MihMzansiCalendarApis.getPersonalAppointments(
mzansiProfileProvider.user!.app_id,
mihCalendarProvider.selectedDay,
mihCalendarProvider,
);
}
setState(() {
isLoading = false;
});
}
@override
void dispose() {
selectedAppointmentDateController.dispose();
_appointmentDateController.dispose();
_appointmentTimeController.dispose();
_appointmentTitleController.dispose();
_appointmentDescriptionIDController.dispose();
super.dispose();
}
@override
void initState() {
selectedAppointmentDateController.addListener(checkforchange);
WidgetsBinding.instance.addPostFrameCallback((_) async {
_loadInitialAppointments();
});
super.initState();
}
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return MihPackageToolBody(
borderOn: false,
bodyItem: getBody(screenWidth),
);
}
}