You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
323 lines
15 KiB
Dart
323 lines
15 KiB
Dart
import 'package:car_provider_app/views/appoinments/widget/sheets.dart';
|
|
import 'package:car_provider_app/views/dashboard/widget/general_appointment_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
import 'package:mc_common_app/config/dependency_injection.dart';
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
import 'package:mc_common_app/models/appointments_models/appointment_list_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/utils/navigator.dart';
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
import 'package:mc_common_app/view_models/appointments_view_model.dart';
|
|
import 'package:mc_common_app/widgets/bottom_sheet.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
class UpdateAppointmentPage extends StatefulWidget {
|
|
const UpdateAppointmentPage({super.key});
|
|
|
|
@override
|
|
State<UpdateAppointmentPage> createState() => _UpdateAppointmentPageState();
|
|
}
|
|
|
|
class _UpdateAppointmentPageState extends State<UpdateAppointmentPage> {
|
|
late AppointmentListModel appointmentListModel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(title: LocaleKeys.updateAppointment.tr()),
|
|
body: SizedBox(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Consumer(builder: (BuildContext context, AppointmentsVM appointmentsVM, Widget? child) {
|
|
appointmentListModel = appointmentsVM.myFilteredAppointmentsForProvider[appointmentsVM.selectedAppointmentIndex].customerAppointmentList![appointmentsVM.selectedAppointmentSubIndex];
|
|
if (appointmentsVM.state == ViewState.busy) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else {
|
|
return RefreshIndicator(
|
|
onRefresh: () async => _updateAppointment(context, appointmentListModel.branchId ?? 0),
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView(
|
|
padding: const EdgeInsets.all(21),
|
|
children: [
|
|
GeneralAppointmentWidget(
|
|
appointmentListModel: appointmentListModel,
|
|
isNeedTotalPayment: true,
|
|
isNeedToShowItems: true,
|
|
isNeedToShowToMoreText: false,
|
|
isFromUpdateAppointmentPage: true,
|
|
onTap: () {},
|
|
),
|
|
21.height,
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.confirmed ||
|
|
appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.arrived ||
|
|
appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.workStarted) ...[
|
|
ShowFillButton(
|
|
title: ("+ ${LocaleKeys.addNewService.tr()}"),
|
|
txtColor: MyColors.darkPrimaryColor,
|
|
isFilled: false,
|
|
onPressed: () {
|
|
navigateWithName(
|
|
context,
|
|
AppRoutes.addServiceInAppointment,
|
|
arguments: appointmentListModel,
|
|
);
|
|
},
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.cancelled) ...[
|
|
Utils.buildStatusContainer(LocaleKeys.appointmentCancelled.tr()).paddingAll(10),
|
|
],
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.booked)
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(child: showPayNowButton(context, appointmentsVM, color: MyColors.greenColor)),
|
|
12.width,
|
|
Expanded(child: showCancelButton(context, appointmentsVM)),
|
|
],
|
|
).paddingAll(21),
|
|
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.confirmed &&
|
|
(appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.payPartial ||
|
|
appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.defaultStatus))
|
|
Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(child: showArrivedButton(context, appointmentsVM)),
|
|
12.width,
|
|
Expanded(child: showCancelButton(context, appointmentsVM)),
|
|
],
|
|
),
|
|
],
|
|
).paddingAll(21),
|
|
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.arrived &&
|
|
(appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.payPartial ||
|
|
appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.defaultStatus))
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(child: showPayNowButton(context, appointmentsVM)),
|
|
12.width,
|
|
Expanded(child: showPayLaterButton(context, appointmentsVM)),
|
|
],
|
|
).paddingAll(21),
|
|
|
|
if ((appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.arrived || appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.workStarted) &&
|
|
appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.payNow)
|
|
Utils.buildStatusContainer(LocaleKeys.waitingPaymentfromtheCustomer.tr()).paddingAll(10),
|
|
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.arrived &&
|
|
(appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.paid ||
|
|
appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.payLater))
|
|
Column(
|
|
children: [
|
|
showWorkStartButton(context, appointmentsVM),
|
|
],
|
|
).paddingAll(21),
|
|
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.workStarted && appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.payPartial)
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(child: showPayNowButton(context, appointmentsVM)),
|
|
12.width,
|
|
Expanded(child: showPayLaterButton(context, appointmentsVM)),
|
|
],
|
|
).paddingAll(21),
|
|
// "Show Pay Now".toText(),
|
|
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.workStarted && appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.paid)
|
|
Column(
|
|
children: [
|
|
showCompleteButton(context, appointmentsVM),
|
|
],
|
|
).paddingAll(21),
|
|
// "Show Complete Button".toText(),
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.workStarted && appointmentListModel.appointmentPaymentStatusEnum == AppointmentPaymentStatusEnum.payLater)
|
|
showPayNowButton(context, appointmentsVM).paddingAll(21),
|
|
|
|
if (appointmentListModel.appointmentStatusEnum == AppointmentStatusEnum.visitCompleted) ...[
|
|
Utils.buildStatusContainer(LocaleKeys.appointmentisCompleted.tr()).paddingAll(10),
|
|
],
|
|
|
|
//TODO: THIS NEEDS TO BE CHECKED. IMPORTANT
|
|
// Padding(
|
|
// padding: const EdgeInsets.all(21.0),
|
|
// child: Column(
|
|
// children: [
|
|
// ShowFillButton(
|
|
// title: "Confirm Arrive",
|
|
// maxWidth: double.infinity,
|
|
// onPressed: () {
|
|
// showMyBottomSheet(
|
|
// context,
|
|
// child: ShowCollectPaymentSheet(
|
|
// onClickYes: () {},
|
|
// onClickNo: () {},
|
|
// ),
|
|
// );
|
|
// },
|
|
// ),
|
|
// 12.height,
|
|
// ShowFillButton(
|
|
// title: "Cancel Appointment",
|
|
// maxWidth: double.infinity,
|
|
// isFilled: false,
|
|
// txtColor: MyColors.redColor,
|
|
// borderColor: MyColors.redColor,
|
|
// onPressed: () {
|
|
// showMyBottomSheet(context,
|
|
// child: CancelAppointmentReasonSheet(
|
|
// onCancelClick: (String reason) {},
|
|
// ));
|
|
// },
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
})),
|
|
);
|
|
}
|
|
|
|
Widget showWorkStartButton(BuildContext context, AppointmentsVM appointmentsVM) {
|
|
return ShowFillButton(
|
|
title: LocaleKeys.workStart.tr(),
|
|
maxWidth: double.infinity,
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
bool status = await appointmentsVM.updateAppointmentStatus(appointmentId: appointmentListModel.id!, appointmentStatusEnum: AppointmentStatusEnum.workStarted);
|
|
|
|
if (status) {
|
|
_updateAppointment(context, appointmentListModel.branchId ?? 0);
|
|
}
|
|
|
|
Utils.hideLoading(context);
|
|
// pop(context);
|
|
|
|
// showMyBottomSheet(
|
|
// context,
|
|
// child: ShowCollectPaymentSheet(
|
|
// onClickYes: () {},
|
|
// onClickNo: () {},
|
|
// ),
|
|
// );
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget showPayNowButton(BuildContext context, AppointmentsVM appointmentsVM, {Color? color}) {
|
|
return ShowFillButton(
|
|
title: LocaleKeys.payNow.tr(),
|
|
maxWidth: double.infinity,
|
|
backgroundColor: color ?? MyColors.darkPrimaryColor,
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
bool status = await appointmentsVM.updateAppointmentPaymentStatus({"appointmentID": appointmentListModel.id.toString(), "appointmentServicePaymentStatusID": 2});
|
|
if (status) {
|
|
_updateAppointment(context, appointmentListModel.branchId ?? 0);
|
|
}
|
|
Utils.hideLoading(context);
|
|
pop(context);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget showArrivedButton(BuildContext context, AppointmentsVM appointmentsVM) {
|
|
return ShowFillButton(
|
|
title: LocaleKeys.arrived.tr(),
|
|
maxWidth: double.infinity,
|
|
txtColor: MyColors.white,
|
|
backgroundColor: MyColors.greenColor,
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
bool status = await appointmentsVM.updateAppointmentStatus(appointmentId: appointmentListModel.id!, appointmentStatusEnum: AppointmentStatusEnum.arrived);
|
|
if (status) {
|
|
_updateAppointment(context, appointmentListModel.branchId ?? 0);
|
|
}
|
|
Utils.hideLoading(context);
|
|
pop(context);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget showPayLaterButton(BuildContext context, AppointmentsVM appointmentsVM) {
|
|
return ShowFillButton(
|
|
title: LocaleKeys.payLater.tr(),
|
|
maxWidth: double.infinity,
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
await appointmentsVM.updateAppointmentPaymentStatus({"appointmentID": appointmentListModel.id.toString(), "appointmentServicePaymentStatusID": 4});
|
|
_updateAppointment(context, appointmentListModel.branchId ?? 0);
|
|
Utils.hideLoading(context);
|
|
pop(context);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget showCompleteButton(BuildContext context, AppointmentsVM appointmentsVM) {
|
|
return ShowFillButton(
|
|
title: LocaleKeys.complete.tr(),
|
|
maxWidth: double.infinity,
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
await appointmentsVM.updateAppointmentStatus(appointmentId: appointmentListModel.id!, appointmentStatusEnum: AppointmentStatusEnum.visitCompleted);
|
|
_updateAppointment(context, appointmentListModel.branchId ?? 0);
|
|
Utils.hideLoading(context);
|
|
pop(context);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget showCancelButton(BuildContext pContext, AppointmentsVM appointmentsVM) {
|
|
return ShowFillButton(
|
|
title: LocaleKeys.cancel.tr(),
|
|
maxWidth: double.infinity,
|
|
txtColor: MyColors.white,
|
|
backgroundColor: MyColors.redColor,
|
|
onPressed: () {
|
|
showModalBottomSheet(
|
|
context: pContext,
|
|
isScrollControlled: true,
|
|
builder: (context) => CancelAppointmentReasonSheet(
|
|
onCancelClick: (String reason) async {
|
|
pop(context);
|
|
await appointmentsVM.onCancelAppointmentPressed(context: pContext, appointmentListModel: appointmentListModel).whenComplete(() async {
|
|
await _updateAppointment(pContext, appointmentListModel.branchId ?? 0);
|
|
pop(pContext);
|
|
pop(pContext);
|
|
});
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> _updateAppointment(BuildContext context, int branchId) async {
|
|
await context.read<AppointmentsVM>().applyFilterOnAppointmentsVMForProviders(
|
|
branchID: branchId,
|
|
appointmentStatusEnum: AppointmentStatusEnum.allAppointments,
|
|
isNeedCustomerFilter: true,
|
|
);
|
|
}
|
|
}
|