From d765bf0b83dc64a3824ae349812f59b8909dab91 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Mon, 15 Dec 2025 15:10:41 +0300 Subject: [PATCH] medical gas cont. --- lib/main.dart | 3 + .../create_medical_gas_request_page.dart | 447 ++++++++++++++++++ 2 files changed, 450 insertions(+) create mode 100644 lib/modules/medical_gas_inspection/create_medical_gas_request_page.dart diff --git a/lib/main.dart b/lib/main.dart index d4544472..ada9fea0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -41,6 +41,7 @@ import 'package:test_sa/modules/loan_module/pages/create_loan_request_page.dart' import 'package:test_sa/modules/loan_module/provider/loan_period_provider.dart'; import 'package:test_sa/modules/loan_module/provider/loan_provider.dart'; import 'package:test_sa/modules/loan_module/provider/medical_department_provider.dart'; +import 'package:test_sa/modules/medical_gas_inspection/create_medical_gas_request_page.dart'; import 'package:test_sa/modules/tm_module/gas_refill/create_gas_refill_request.dart'; import 'package:test_sa/modules/tm_module/gas_refill/update_gas_refill_request.dart'; import 'package:test_sa/modules/traf_module/create_traf_request_page.dart'; @@ -385,6 +386,8 @@ class MyApp extends StatelessWidget { CreateLoanRequestPage.id: (_) => CreateLoanRequestPage(), // SwipeSuccessView.routeName: (_) => const SwipeSuccessView(), // SwipeHistoryView.routeName: (_) => const SwipeHistoryView(), + + CreateMedicalGasRequestPage.id: (_) => CreateMedicalGasRequestPage(), }, ), ), diff --git a/lib/modules/medical_gas_inspection/create_medical_gas_request_page.dart b/lib/modules/medical_gas_inspection/create_medical_gas_request_page.dart new file mode 100644 index 00000000..d1b5b1c9 --- /dev/null +++ b/lib/modules/medical_gas_inspection/create_medical_gas_request_page.dart @@ -0,0 +1,447 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:test_sa/controllers/providers/api/device_transfer_provider.dart'; +import 'package:test_sa/controllers/validator/validator.dart'; +import 'package:test_sa/dashboard_latest/dashboard_provider.dart'; +import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/string_extensions.dart'; +import 'package:test_sa/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/helper/utils.dart'; +import 'package:test_sa/models/device/asset.dart'; +import 'package:test_sa/models/enums/user_types.dart'; +import 'package:test_sa/models/generic_attachment_model.dart'; +import 'package:test_sa/models/lookup.dart'; +import 'package:test_sa/models/new_models/site.dart'; +import 'package:test_sa/models/new_models/task_request/task_type_model.dart'; +import 'package:test_sa/models/new_models/work_order_detail_model.dart'; +import 'package:test_sa/modules/cm_module/cm_request_utils.dart'; +import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart'; +import 'package:test_sa/modules/loan_module/models/loan_form_model.dart'; +import 'package:test_sa/modules/loan_module/models/medical_department_model.dart'; +import 'package:test_sa/modules/loan_module/provider/loan_period_provider.dart'; +import 'package:test_sa/modules/loan_module/provider/loan_provider.dart'; +import 'package:test_sa/modules/loan_module/provider/loan_provider.dart'; +import 'package:test_sa/modules/loan_module/provider/medical_department_provider.dart'; +import 'package:test_sa/new_views/app_style/app_color.dart'; +import 'package:test_sa/new_views/common_widgets/app_filled_button.dart'; +import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart'; +import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart'; +import 'package:test_sa/providers/department_provider.dart'; +import 'package:test_sa/providers/gas_request_providers/site_provider.dart'; +import 'package:test_sa/providers/loading_list_notifier.dart'; +import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; +import '../../../../../../new_views/common_widgets/default_app_bar.dart'; + +class CreateMedicalGasRequestPage extends StatefulWidget { + static const String id = "/create-medical-gas"; + + CreateMedicalGasRequestPage({Key? key}) : super(key: key); + + @override + _CreateMedicalGasRequestPageState createState() => _CreateMedicalGasRequestPageState(); +} + +class _CreateMedicalGasRequestPageState extends State with TickerProviderStateMixin { + final List attachments = []; + final GlobalKey _formKey = GlobalKey(); + final GlobalKey _scaffoldKey = GlobalKey(); + TaskType? selectedType; + final LoanFormModel _loanFormModel = LoanFormModel(); + + TextEditingController commentController = TextEditingController(); + + // bool get isBackUpRequest => widget.workOrderId != null; + + // List loanTypes = []; + + @override + void initState() { + super.initState(); + // Provider.of(context, listen: false).reset(); + // Provider.of(context, listen: false).reset(); + // loanTypes = [Lookup(id: 0, name: "Standard", value: 1), Lookup(id: 1, name: "Backup", value: 2)]; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + key: _scaffoldKey, + appBar: DefaultAppBar(title: 'Medical Gas Inspection'.addTranslation), + body: Form( + key: _formKey, + child: Column( + children: [ + SingleChildScrollView( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + SingleItemDropDownMenu( + context: context, + title: "Loan Type", + enabled: false, + staticData: [], + initialValue: null, + showShadow: false, + backgroundColor: AppColor.fieldBgColor(context), + showAsBottomSheet: true, + onSelect: (value) {}, + ), + // 16.height, + + // ...contactInfoSection(), + // 16.height, + ...itemDetailsSection(), + 16.height, + ...doctorInfoSection(), + 16.height, + ...vendorDetailsSection(), + 16.height, + AttachmentPicker( + label: context.translation.attachments, + attachment: attachments, + buttonColor: AppColor.black10, + onlyImages: false, + showAsListView: true, + buttonIcon: 'image-plus'.toSvgAsset(color: context.isDark ? AppColor.primary10 : AppColor.neutral120), + onChange: (attachments) { + attachments = attachments; + setState(() {}); + }, + ), + ], + ).toShadowContainer(context, borderRadius: 20), + ).expanded, + FooterActionButton.footerContainer( + context: context, + child: AppFilledButton( + buttonColor: AppColor.primary10, + label: context.translation.submitRequest, + onPressed: _submit, + // buttonColor: AppColor.primary10, + ), + ), + ], + ), + ), + ); + } + + List doctorInfoSection() { + return [ + context.translation.contactInfo.bodyText(context).custom(color: AppColor.black10), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Doctor Name", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.text, + onChange: (value) { + _loanFormModel.docName = value; + }, + ), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Doctor Number", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.phone, + onChange: (value) { + _loanFormModel.docNumber = value; + }, + ), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Doctor Email", + validator: (value) { + if ((value ?? "").isEmpty) { + return "Mandatory"; + } else { + return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage; + } + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.emailAddress, + onChange: (value) { + _loanFormModel.docEmail = value; + }, + ), + ]; + } + + List itemDetailsSection() { + return [ + 'Item Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.site, + initialValue: _loanFormModel.site, + showShadow: false, + validator: (value) { + if (value == null) return "Please select a site"; + return null; + }, + backgroundColor: AppColor.fieldBgColor(context), + showAsBottomSheet: true, + onSelect: (value) { + _loanFormModel.site = value; + setState(() {}); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.department, + showShadow: false, + validator: (value) { + if (value == null) return "Please select a department"; + return null; + }, + showAsBottomSheet: true, + initialValue: _loanFormModel.department, + requestById: context.userProvider.user?.clientId, + backgroundColor: AppColor.fieldBgColor(context), + onSelect: (value) { + _loanFormModel.department = value; + setState(() {}); + }, + ), + 8.height, + AppTextFormField( + labelText: "Item Description", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.text, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.itemDescription = value; + }, + ), + 8.height, + Row( + children: [ + "help-circle".toSvgAsset(height: 16, width: 16), + 8.width, + Text( + "Specify the purpose of the loan (e.g., equipment needed for a scheduled procedure or patient case)", + style: AppTextStyles.tinyFont2.copyWith(fontWeight: FontWeight.w400, color: context.isDark ? Colors.white : const Color(0xff3B3D4A)), + ).expanded, + ], + ), + 8.height, + AppTextFormField( + labelText: "Request Description", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.text, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.requestDescription = value; + }, + ), + 8.height, + AppTextFormField( + labelText: "Model", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.text, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.model = value; + }, + ), + 8.height, + AppTextFormField( + labelText: "Manufacturer", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.text, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.manufacturer = value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + height: 56.toScreenHeight, + title: 'Loan Period'.addTranslation, + showShadow: false, + validator: (value) { + if (value == null) return "Please select loan period"; + return null; + }, + backgroundColor: AppColor.fieldBgColor(context), + showAsBottomSheet: true, + initialValue: _loanFormModel.loanProvided, + onSelect: (status) { + if (status != null) { + _loanFormModel.loanProvided = status; + setState(() {}); + } + }, + ), + 8.height, + ]; + } + + List vendorDetailsSection() { + return [ + 'Vendor Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Vendor Name", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.name, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.vendorName = value; + }, + ), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Vendor Representative Name", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.name, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.vendorRepresentativeName = value; + }, + ), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Vendor Number", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.phone, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.vendorNumber = value; + }, + ), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Vendor Email", + validator: (value) { + if ((value ?? "").isEmpty) { + return "Mandatory"; + } else { + return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage; + } + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.emailAddress, + textInputAction: TextInputAction.next, + onChange: (value) { + _loanFormModel.vendorEmail = value; + }, + ), + ]; + } + + Future _submit() async { + return; + FocusScope.of(context).unfocus(); + if (_formKey.currentState!.validate()) { + _formKey.currentState!.save(); + + _loanFormModel.loanAttachment = []; + for (var item in attachments) { + String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; + _loanFormModel.loanAttachment?.add(LoanAttachments(id: 0, attachmentName: fileName, loanId: 0)); + } + Utils.showLoading(context); + LoanProvider loanProvider = Provider.of(context, listen: false); + Map body = _loanFormModel.toJson(); + body["id"] = 0; + body["LoanTypeId"] = 0; + body["requestorUserID"] = context.userProvider.user!.userID; + + bool isSuccess = await loanProvider.addLoanRequest(body); + Utils.hideLoading(context); + if (isSuccess) { + Navigator.pop(context); + } + } + } +}