appointment list builder created
This commit is contained in:
@@ -1,26 +1,41 @@
|
|||||||
|
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_apis/mih_mzansi_calendar_apis.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_date_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_multiline_text_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_time_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_delete_message.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_env/env.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_objects/appointment.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../../main.dart';
|
|
||||||
import '../../../mih_components/mih_pop_up_messages/mih_warning_message.dart';
|
|
||||||
import '../../../mih_env/env.dart';
|
|
||||||
import '../../../mih_objects/app_user.dart';
|
|
||||||
import '../../../mih_objects/patient_queue.dart';
|
|
||||||
|
|
||||||
class BuildAppointmentList extends StatefulWidget {
|
class BuildAppointmentList extends StatefulWidget {
|
||||||
final List<PatientQueue> patientQueue;
|
final List<Appointment> appointmentList;
|
||||||
final AppUser signedInUser;
|
final AppUser signedInUser;
|
||||||
|
final TextEditingController titleController;
|
||||||
|
final TextEditingController descriptionIDController;
|
||||||
|
final TextEditingController dateController;
|
||||||
|
final TextEditingController timeController;
|
||||||
|
|
||||||
const BuildAppointmentList({
|
const BuildAppointmentList({
|
||||||
super.key,
|
super.key,
|
||||||
required this.patientQueue,
|
required this.appointmentList,
|
||||||
required this.signedInUser,
|
required this.signedInUser,
|
||||||
|
required this.titleController,
|
||||||
|
required this.descriptionIDController,
|
||||||
|
required this.dateController,
|
||||||
|
required this.timeController,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<BuildAppointmentList> createState() => _BuildPatientsListState();
|
State<BuildAppointmentList> createState() => _BuildAppointmentListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BuildPatientsListState extends State<BuildAppointmentList> {
|
class _BuildAppointmentListState extends State<BuildAppointmentList> {
|
||||||
String baseAPI = AppEnviroment.baseApiUrl;
|
String baseAPI = AppEnviroment.baseApiUrl;
|
||||||
TextEditingController dateController = TextEditingController();
|
TextEditingController dateController = TextEditingController();
|
||||||
TextEditingController timeController = TextEditingController();
|
TextEditingController timeController = TextEditingController();
|
||||||
@@ -29,83 +44,374 @@ class _BuildPatientsListState extends State<BuildAppointmentList> {
|
|||||||
TextEditingController lnameController = TextEditingController();
|
TextEditingController lnameController = TextEditingController();
|
||||||
TextEditingController daysExtensionController = TextEditingController();
|
TextEditingController daysExtensionController = TextEditingController();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
late double width;
|
||||||
|
late double height;
|
||||||
|
|
||||||
Widget displayQueue(int index) {
|
double getPaddingSize() {
|
||||||
String title = widget.patientQueue[index].business_name.toUpperCase();
|
if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") {
|
||||||
// widget.patientQueue[index].date_time.split('T')[1].substring(0, 5);
|
return (width / 10);
|
||||||
String line234 = "";
|
} else {
|
||||||
// var nowDate = DateTime.now();
|
return 0.0;
|
||||||
// var expireyDate = DateTime.parse(widget.patientQueue[index].revoke_date);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
line234 +=
|
Widget displayAppointment(int index) {
|
||||||
widget.patientQueue[index].date_time.split('T')[1].substring(0, 5);
|
String heading =
|
||||||
|
"${widget.appointmentList[index].date_time.split('T')[1].substring(0, 5)} - ${widget.appointmentList[index].title.toUpperCase()}";
|
||||||
|
String description = widget.appointmentList[index].description;
|
||||||
|
DateTime now = new DateTime.now();
|
||||||
|
int hourNow = int.parse(now.toString().split(' ')[1].substring(0, 2));
|
||||||
|
String date =
|
||||||
|
new DateTime(now.year, now.month, now.day).toString().split(' ')[0];
|
||||||
|
String appointDate = widget.appointmentList[index].date_time.split('T')[0];
|
||||||
|
int appointHour = int.parse(
|
||||||
|
widget.appointmentList[index].date_time.split('T')[1].substring(0, 2));
|
||||||
|
// print("Date Time Now: $now");
|
||||||
|
// print("Hour Now: $hourNow");
|
||||||
|
// print("Date: $date");
|
||||||
|
// print("Appointment Date: $appointDate");
|
||||||
|
// print("Appointment Hour: $appointHour");
|
||||||
|
Color appointmentColor =
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor();
|
||||||
|
if (date == appointDate) {
|
||||||
|
if (appointHour < hourNow) {
|
||||||
|
appointmentColor =
|
||||||
|
MzanziInnovationHub.of(context)!.theme.messageTextColor();
|
||||||
|
} else if (appointHour == hourNow) {
|
||||||
|
appointmentColor =
|
||||||
|
MzanziInnovationHub.of(context)!.theme.successColor();
|
||||||
|
}
|
||||||
|
} else if (DateTime.parse(appointDate).isBefore(DateTime.parse(date))) {
|
||||||
|
appointmentColor =
|
||||||
|
MzanziInnovationHub.of(context)!.theme.messageTextColor();
|
||||||
|
}
|
||||||
|
|
||||||
return ListTile(
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(5.0),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
width: 3.0,
|
||||||
|
color: appointmentColor,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(20)),
|
||||||
|
child: ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
title,
|
heading,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
color: appointmentColor,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
subtitle: RichText(
|
subtitle: Text(
|
||||||
text: TextSpan(
|
description,
|
||||||
text: "Time: $line234",
|
style: TextStyle(
|
||||||
style: DefaultTextStyle.of(context).style,
|
color: appointmentColor,
|
||||||
// children: [
|
overflow: TextOverflow.ellipsis,
|
||||||
// TextSpan(text: line5),
|
),
|
||||||
// accessWithColour,
|
),
|
||||||
// TextSpan(text: line6),
|
onTap: () {
|
||||||
// ]
|
setState(() {
|
||||||
|
widget.titleController.text = widget.appointmentList[index].title;
|
||||||
|
widget.descriptionIDController.text =
|
||||||
|
widget.appointmentList[index].description;
|
||||||
|
widget.dateController.text =
|
||||||
|
widget.appointmentList[index].date_time.split('T')[0];
|
||||||
|
widget.timeController.text = widget
|
||||||
|
.appointmentList[index].date_time
|
||||||
|
.split('T')[1]
|
||||||
|
.substring(0, 5);
|
||||||
|
});
|
||||||
|
appointmentDetailsWindow(index);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAccessExpired(String accessType) {
|
void appointmentDetailsWindow(int index) {
|
||||||
if (accessType == "EXPIRED") {
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) {
|
||||||
|
return MIHWindow(
|
||||||
|
fullscreen: false,
|
||||||
|
windowTitle: "Appointment Details",
|
||||||
|
windowTools: [
|
||||||
|
Visibility(
|
||||||
|
visible: canEditAppointment(index),
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
deleteAppointmentConfirmationWindow(index);
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
onWindowTapClose: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
widget.dateController.clear();
|
||||||
|
widget.timeController.clear();
|
||||||
|
widget.titleController.clear();
|
||||||
|
widget.descriptionIDController.clear();
|
||||||
|
},
|
||||||
|
windowBody: [
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
child: MIHTextField(
|
||||||
|
controller: widget.titleController,
|
||||||
|
hintText: "Title",
|
||||||
|
editable: false,
|
||||||
|
required: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
child: MIHTextField(
|
||||||
|
controller: widget.dateController,
|
||||||
|
hintText: "Date",
|
||||||
|
editable: false,
|
||||||
|
required: false,
|
||||||
|
)),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
child: MIHTextField(
|
||||||
|
controller: widget.timeController,
|
||||||
|
hintText: "Time",
|
||||||
|
editable: false,
|
||||||
|
required: false,
|
||||||
|
)),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
height: 250,
|
||||||
|
child: MIHMLTextField(
|
||||||
|
controller: widget.descriptionIDController,
|
||||||
|
hintText: "Description",
|
||||||
|
editable: false,
|
||||||
|
required: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Visibility(
|
||||||
|
visible: canEditAppointment(index),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 500,
|
||||||
|
height: 50,
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
appointmentUpdateWindow(index);
|
||||||
|
},
|
||||||
|
buttonText: "Edit",
|
||||||
|
buttonColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
textColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
// height: 50,
|
||||||
|
// child: MIHButton(
|
||||||
|
// onTap: () {
|
||||||
|
// addAppointmentCall();
|
||||||
|
// checkforchange();
|
||||||
|
// },
|
||||||
|
// buttonText: "Add",
|
||||||
|
// buttonColor:
|
||||||
|
// MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||||
|
// textColor:
|
||||||
|
// MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void appointmentUpdateWindow(int index) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) {
|
||||||
|
return MIHWindow(
|
||||||
|
fullscreen: false,
|
||||||
|
windowTitle: "Update Appointment",
|
||||||
|
windowTools: [],
|
||||||
|
onWindowTapClose: () {
|
||||||
|
setState(() {
|
||||||
|
widget.titleController.text = widget.appointmentList[index].title;
|
||||||
|
widget.descriptionIDController.text =
|
||||||
|
widget.appointmentList[index].description;
|
||||||
|
widget.dateController.text =
|
||||||
|
widget.appointmentList[index].date_time.split('T')[0];
|
||||||
|
widget.timeController.text = widget
|
||||||
|
.appointmentList[index].date_time
|
||||||
|
.split('T')[1]
|
||||||
|
.substring(0, 5);
|
||||||
|
});
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
windowBody: [
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
child: MIHTextField(
|
||||||
|
controller: widget.titleController,
|
||||||
|
hintText: "Title",
|
||||||
|
editable: true,
|
||||||
|
required: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
child: MIHDateField(
|
||||||
|
controller: widget.dateController,
|
||||||
|
lableText: "Date",
|
||||||
|
required: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
child: MIHTimeField(
|
||||||
|
controller: widget.timeController,
|
||||||
|
lableText: "Time",
|
||||||
|
required: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
SizedBox(
|
||||||
|
// width: 500,
|
||||||
|
height: 250,
|
||||||
|
child: MIHMLTextField(
|
||||||
|
controller: widget.descriptionIDController,
|
||||||
|
hintText: "Description",
|
||||||
|
editable: true,
|
||||||
|
required: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Wrap(
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
|
runSpacing: 10,
|
||||||
|
spacing: 10,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 500,
|
||||||
|
height: 50,
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
updateAppointmentCall(index);
|
||||||
|
},
|
||||||
|
buttonText: "Update",
|
||||||
|
buttonColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||||
|
textColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 500,
|
||||||
|
height: 50,
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
widget.titleController.text =
|
||||||
|
widget.appointmentList[index].title;
|
||||||
|
widget.descriptionIDController.text =
|
||||||
|
widget.appointmentList[index].description;
|
||||||
|
widget.dateController.text = widget
|
||||||
|
.appointmentList[index].date_time
|
||||||
|
.split('T')[0];
|
||||||
|
widget.timeController.text = widget
|
||||||
|
.appointmentList[index].date_time
|
||||||
|
.split('T')[1]
|
||||||
|
.substring(0, 5);
|
||||||
|
});
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
buttonText: "Cancel",
|
||||||
|
buttonColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||||
|
textColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isAppointmentInputValid() {
|
||||||
|
if (widget.titleController.text.isEmpty ||
|
||||||
|
widget.descriptionIDController.text.isEmpty ||
|
||||||
|
widget.dateController.text.isEmpty ||
|
||||||
|
widget.timeController.text.isEmpty) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteAppointmentConfirmationWindow(int index) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) {
|
||||||
|
return MIHDeleteMessage(
|
||||||
|
deleteType: "Appointment",
|
||||||
|
onTap: () {
|
||||||
|
deleteAppointmentCall(index);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateAppointmentCall(int index) {
|
||||||
|
if (isAppointmentInputValid()) {
|
||||||
|
MihMzansiCalendarApis.updatePersonalAppointment(
|
||||||
|
widget.signedInUser,
|
||||||
|
widget.appointmentList[index].idappointments,
|
||||||
|
widget.titleController.text,
|
||||||
|
widget.descriptionIDController.text,
|
||||||
|
widget.dateController.text,
|
||||||
|
widget.timeController.text,
|
||||||
|
context,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const MIHErrorMessage(errorType: "Input Error");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteAppointmentCall(int index) {
|
||||||
|
MihMzansiCalendarApis.deleteLoyaltyCardAPICall(
|
||||||
|
widget.signedInUser,
|
||||||
|
widget.appointmentList[index].idappointments,
|
||||||
|
context,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canEditAppointment(int index) {
|
||||||
|
if (widget.appointmentList[index].business_id == "") {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void noAccessWarning() {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MIHWarningMessage(warningType: "No Access");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void accessDeclinedWarning() {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MIHWarningMessage(warningType: "Access Declined");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void appointmentCancelledWarning() {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MIHWarningMessage(warningType: "Appointment Canelled");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void expiredAccessWarning() {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MIHWarningMessage(warningType: "Expired Access");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
daysExtensionController.dispose();
|
daysExtensionController.dispose();
|
||||||
@@ -116,21 +422,21 @@ class _BuildPatientsListState extends State<BuildAppointmentList> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView.separated(
|
var size = MediaQuery.of(context).size;
|
||||||
|
setState(() {
|
||||||
|
width = size.width;
|
||||||
|
height = size.height;
|
||||||
|
});
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: getPaddingSize()),
|
||||||
|
child: ListView.builder(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
separatorBuilder: (BuildContext context, index) {
|
itemCount: widget.appointmentList.length,
|
||||||
return Divider(
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
itemCount: widget.patientQueue.length,
|
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
return displayAppointment(index);
|
||||||
//print(index);
|
|
||||||
|
|
||||||
return displayQueue(index);
|
|
||||||
},
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user