diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 2ab3354f..e26dea78 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -9,7 +9,10 @@ "doYouWantToCreateAnotherSparePartRequest": "هل تريد إنشاء طلب قطعة غيار آخر؟", "sparePartActivitySuccess": "تم إنشاء نشاط طلب قطعة الغيار بنجاح", "confirm": "تاكيد", + "refreshQrCode": "تحديث رمز الاستجابة السريعة", "done": "تم", + "notArrived": "لم يصل", + "arrived": "وصل", "exit": "إغلاق", "requestDetails": "تفاصيل الطلب", "retirementType": "نوع التقاعد", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4f0ab30d..4e9cf024 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -6,8 +6,11 @@ "requestLockMessage": "Wait until your request complete", "cancel": "Cancel", "confirm": "Confirm", + "notArrived": "Not Arrived", + "arrived": "Arrived", "done": "Done", "exit": "Exit", + "refreshQrCode": "Refresh QR Code", "exitAlert": "Are you sure you want to exit?", "assetRetiredPendingOpManagementApproval": "Asset Retired. Pending OP Management Approval", "assetRetirementRequestSubmittedSuccessfully": "Asset retirement request submitted successfully", diff --git a/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart b/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart index c8c4458a..5127c053 100644 --- a/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart +++ b/lib/service_request_latest/views/components/bottom_sheets/service_request_bottomsheet.dart @@ -23,6 +23,7 @@ import 'package:test_sa/service_request_latest/views/forms/maintenance_request/m import 'package:test_sa/service_request_latest/views/forms/spare_part/spare_part_request.dart'; import 'package:test_sa/views/widgets/date_and_time/date_picker.dart'; import 'package:test_sa/views/widgets/e_signature/e_signature.dart'; +import 'package:test_sa/views/widgets/loaders/app_loading.dart'; import '../../../../controllers/providers/api/service_requests_provider.dart'; import '../../../../new_views/app_style/app_color.dart'; @@ -432,74 +433,108 @@ class ServiceRequestBottomSheet { ), ); } -static Future getQRCodeBottomSheet({required BuildContext context}) async{ - showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); - ServiceRequestDetailProvider requestDetailProvider = Provider.of(context,listen:false); - String? base64String = await requestDetailProvider.getQrCode(workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId ?? 0); - Navigator.pop(context); - if (base64String != null) { - // You have the base64 string, now you can display it - Uint8List bytes = base64Decode(base64String); + static Future getQRCodeBottomSheet({required BuildContext context}) async { + // Show the loading dialog while fetching QR code + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); + ServiceRequestDetailProvider requestDetailProvider = Provider.of(context, listen: false); + String? base64String = await requestDetailProvider.getQrCode(workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId ?? 0); + Navigator.pop(context); - return buildBottomSheetParent( - context: context, - childWidget: Consumer( - builder: (context, requestDetailProvider, child) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox().indicatorWidget().center, - 8.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.qrCode.bottomSheetHeadingTextStyle(context), - ), - 8.height, - Align( - alignment: AlignmentDirectional.centerStart, - child: context.translation.provideQrCodeToEngineer.bodyText2(context), - ), - 12.height, - Center( - child: Image.memory( - bytes, // Displaying the QR code from base64 - fit: BoxFit.contain, // Ensure the image fits well in the dialog - errorBuilder: (context, error, stackTrace) { - return const Icon(Icons.error, color: Colors.red); - }, - ), - ), - - 16.height, - ], - ); - }, - ), - ); - - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - backgroundColor: Colors.white, - title:context.translation.scanQr.heading6(context).center, - content: Image.memory( - bytes, // Displaying the QR code from base64 - fit: BoxFit.contain, // Ensure the image fits well in the dialog - errorBuilder: (context, error, stackTrace) { - return const Icon(Icons.error, color: Colors.red); - }, - ), + if (base64String != null) { + Uint8List bytes = base64Decode(base64String); + bool isLoading = false; - ); - }, - ); - } else { - print('Failed to get the QR code'); - } + return buildBottomSheetParent( + context: context, + childWidget: StatefulBuilder( + builder: (context, setState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox().indicatorWidget().center, + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.qrCode.bottomSheetHeadingTextStyle(context), + ), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.provideQrCodeToEngineer.bodyText(context), + ), + 12.height, + SizedBox( + height: 296.toScreenHeight, + child: Center( + child: isLoading + ? const ALoading() // Show loader while fetching the new QR code + : Image.memory( + bytes, // Displaying the QR code from base64 + fit: BoxFit.contain, // Ensure the image fits well in the dialog + errorBuilder: (context, error, stackTrace) { + return const Icon(Icons.error, color: Colors.red); + }, + ), + ), + ), + 12.height, + Center( + child: InkWell( + onTap: () async { + // Set loading state and call API to get the new QR code + setState(() { + isLoading = true; + }); + // Fetch the new QR code + String? newBase64String = await requestDetailProvider.getQrCode( + workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId ?? 0, + ); + // Decode the new QR code and update the state + if (newBase64String != null) { + setState(() { + bytes = base64Decode(newBase64String); + isLoading = false; + }); + } else { + setState(() { + isLoading = false; // Stop loader if fetching fails + }); + } + }, + child: Text( + context.translation.refreshQrCode, + style: TextStyle( + color: AppColor.primary10, + fontWeight: FontWeight.w500, + fontSize: 12.toScreenWidth, + decorationColor: AppColor.primary10, + decoration: TextDecoration.underline, + ), + ), + ), + ), + 16.height, + AppFilledButton( + label: context.translation.close, + // maxWidth: true, + textColor: AppColor.black20, + buttonColor: AppColor.white30, + onPressed: () async { + Navigator.pop(context); + }, + ), + 16.height, + ], + ); + }, + ), + ); + } else { + print('Failed to get the QR code'); + } } @@ -1095,4 +1130,175 @@ static Future getQRCodeBottomSheet({required BuildContext context}) async{ // ).bottomSheetContainer(context); // })); } + static Future nurseVerifyArrivalBottomSheet({required BuildContext context}) { + bool acknowledge = false; + Uint8List? newSignature; + String? nurseSignature; + return buildBottomSheetParent( + context: context, + childWidget: Consumer(builder: (context, ServiceRequestDetailProvider requestDetailProvider, child) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox().indicatorWidget(), + 8.height, + Align( + alignment: AlignmentDirectional.centerStart, + child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context), + ), + 10.height, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.min, + children: [ + AppFilledButton( + label: context.translation.notArrived, + maxWidth: true, + buttonColor: Colors.white54, + textColor: AppColor.red30, + showBorder: true, + onPressed: () async { + Navigator.pop(context); + nurseRejectBackBottomSheet(context: context); + }, + ).expanded, + const SizedBox( + width: 20, + ), + AppFilledButton( + label: context.translation.arrived, + maxWidth: true, + loading: requestDetailProvider.isLoading, + buttonColor: AppColor.green70, + onPressed: () async { + if (newSignature != null) { + requestDetailProvider.nurseActionHelperModel = NurseActionHelperModel( + workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId!, + signatureNurse: nurseSignature, + ); + await requestDetailProvider.nurseConfirm(); + if (requestDetailProvider.currentWorkOrder!.data!.requestId != null) { + requestDetailProvider.getWorkOrderById(id: requestDetailProvider.currentWorkOrder!.data!.requestId!); + } + Navigator.pop(context); + } else { + //show some toast... + } + }, + ).expanded, + ], + ) + ], + ); + })); + + // + // return showModalBottomSheet( + // context: context, + // useSafeArea: true, + // isScrollControlled: true, + // backgroundColor: Colors.transparent, + // builder: (context) => Consumer(builder: (context, serviceRequestProvider, child) { + // return Form( + // key: _formKey, + // child: SingleChildScrollView( + // child: StatefulBuilder(builder: (context, setState) { + // return Column( + // crossAxisAlignment: CrossAxisAlignment.center, + // children: [ + // const SizedBox().indicatorWidget(), + // 8.height, + // Align( + // alignment: AlignmentDirectional.centerStart, + // child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context), + // ), + // 10.height, + // Row( + // children: [ + // InkWell( + // child: acknowledge + // ? const Icon( + // Icons.check_box, + // color: AppColor.primary10, + // ) + // : const Icon( + // Icons.check_box_outline_blank, + // color: AppColor.neutral120, + // ), + // onTap: () { + // setState(() { + // acknowledge = !acknowledge; + // }); + // }, + // ), + // 6.width, + // Flexible(child: context.translation.nurseAcknowledge.bodyText(context).custom(color: context.isDark ? AppColor.primary50 : AppColor.neutral120)), + // ], + // ), + // 17.height, + // ESignature( + // title: '', + // oldSignature: '', + // newSignature: newSignature, + // backgroundColor: AppColor.neutral100, + // showShadow: false, + // onSaved: (signature) { + // if (signature == null || signature.isEmpty) return; + // newSignature = signature; + // nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + // }, + // ), + // 36.height, + // Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + // mainAxisSize: MainAxisSize.min, + // children: [ + // AppFilledButton( + // label: context.translation.reject, + // maxWidth: true, + // buttonColor: Colors.white54, + // textColor: AppColor.red30, + // showBorder: true, + // onPressed: () async { + // _formKey.currentState?.save(); + // if (newSignature != null && acknowledge) { + // //TODO replace provider with new provider and also check workorder id is not correct. + // Provider.of(context, listen: false).nurseReject( + // model: NurseActionModel( + // workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), + // signatureNurse: nurseSignature, + // )); + // Navigator.pop(context); + // } + // }, + // ).expanded, + // const SizedBox( + // width: 20, + // ), + // AppFilledButton( + // label: context.translation.confirm, + // maxWidth: true, + // buttonColor: AppColor.green70, + // onPressed: () async { + // _formKey.currentState?.save(); + // if (newSignature != null && acknowledge) { + // //TODO replace provider with new provider and also check workorder id is not correct. + // Provider.of(context, listen: false).nurseConfirm( + // model: NurseActionModel( + // workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!), + // signatureNurse: nurseSignature, + // )); + // Navigator.pop(context); + // } + // }, + // ).expanded, + // ], + // ) + // ], + // ); + // }), + // ), + // ).bottomSheetContainer(context); + // })); + } }