// import 'dart:convert';
// import 'dart:io';
//
// import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart';
// import 'package:provider/provider.dart';
// import 'package:test_sa/controllers/providers/api/service_requests_provider.dart';
// import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_assistants_employee_provider.dart';
// import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_types_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/models/device/asset.dart';
// import 'package:test_sa/models/lookup.dart';
// import 'package:test_sa/models/new_models/assigned_employee.dart';
// import 'package:test_sa/models/new_models/assistant_employee.dart';
// import 'package:test_sa/models/service_request/search_work_order.dart';
// import 'package:test_sa/models/service_request/service_report.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/default_app_bar.dart';
// import 'package:test_sa/providers/service_request_providers/equipment_status_provider.dart';
// import 'package:test_sa/providers/service_request_providers/loan_availability_provider.dart';
// import 'package:test_sa/providers/work_order/vendor_provider.dart';
// import 'package:test_sa/views/pages/user/requests/add_supplier_engineer_bottom_sheet.dart';
// import 'package:test_sa/views/widgets/e_signature/e_signature.dart';
// import 'package:test_sa/views/widgets/equipment/pick_asset.dart';
// import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
// import 'package:test_sa/views/widgets/loaders/app_loading.dart';
//
// import '../../../attachment.dart';
// import '../../../controllers/api_routes/http_status_manger.dart';
// import '../../../controllers/providers/api/parts_provider.dart';
// import '../../../controllers/providers/api/status_drop_down/report/service_report_fault_description_provider.dart';
// import '../../../controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart';
// import '../../../controllers/providers/api/user_provider.dart';
// import '../../../models/service_request/spare_parts.dart';
// import '../../../models/service_request/supp_engineer_work_orders.dart';
// import '../../../models/service_request/supplier_details.dart';
// import '../../../models/service_request/wo_call_request.dart';
// import '../../../new_views/common_widgets/app_lazy_loading.dart';
// import '../../../new_views/common_widgets/app_text_form_field.dart';
// import '../../../new_views/common_widgets/single_item_drop_down_menu.dart';
// import '../../../providers/loading_list_notifier.dart';
// import '../../../providers/work_order/reason_provider.dart';
// import '../../widgets/date_and_time/date_picker.dart';
// import '../../widgets/loaders/loading_manager.dart';
// import '../../widgets/status/report/service_report_assistant_employee_menu.dart';
// import '../../widgets/status/report/service_report_fault_description.dart';
// import '../../widgets/status/report/service_report_last_call.dart';
// import '../../widgets/status/report/service_report_repair_location.dart';
// import '../../widgets/timer/app_timer.dart';
// import '../user/requests/work_order/part_no_button.dart';
//
// class CreateSubWorkOrderPage extends StatefulWidget {
//   static const id = "/CreateSubWorkOrder";
//   final SearchWorkOrder? workOrder;
//// //todo @delete
//   const CreateSubWorkOrderPage({this.workOrder, Key? key}) : super(key: key);
//
//   @override
//   State<CreateSubWorkOrderPage> createState() => _CreateSubWorkOrderPageState();
// }
//
// class _CreateSubWorkOrderPageState extends State<CreateSubWorkOrderPage> {
//   final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
//   late SearchWorkOrder _subWorkOrders;
//   late ServiceReport _serviceReport;
//   late PartsProvider _partsProvider;
//   final List<File> _files = [];
//   List<SparePart> _spareParts = [];
//   bool _isLoading = false;
//   bool _showVendorFields = false;
//   SuppEngineerWorkOrders? engineer;
//   SupplierDetails? initialSupplier;
//   final TextEditingController _workPreformedController = TextEditingController();
//   final TextEditingController _partQtyController = TextEditingController();
//
//   @override
//   void initState() {
//     _subWorkOrders = SearchWorkOrder(
//       assignedEmployee: widget.workOrder?.callRequest?.assignedEmployee,
//       callRequest: CallRequest(id: widget.workOrder?.callRequest?.id),
//       currentSituation: null,
//       supplier: null,
//       parentWOId: widget.workOrder?.id,
//     );
//     _serviceReport = ServiceReport(id: widget.workOrder?.id, assetType: widget.workOrder?.assetType, equipmentStatus: widget.workOrder?.equipmentStatus);
//     _isLoading = true;
//     super.initState();
//     if (context.mounted) {
//       Provider.of<ServiceReportAssistantsEmployeeProvider>(context, listen: false).reset();
//       Provider.of<ReasonProvider>(context, listen: false).reset();
//       Provider.of<ReasonProvider>(context, listen: false).serviceRequestId = widget.workOrder?.callRequest!.id.toString();
//     }
//   }
//
//   late ServiceStatusProvider assetTypesProvider;
//   CallRequest? _callRequestForWorkOrder;
//
//   Future getAssetType() async {
//     Provider.of<ServiceReportLastCallsProvider>(context, listen: false).reset();
//     final serviceRequestProvider = Provider.of<ServiceRequestsProvider>(context);
//     Provider.of<ServiceRequestFaultDescriptionProvider>(context, listen: false).reset();
//     assetTypesProvider = Provider.of<ServiceStatusProvider>(context, listen: false);
//     _callRequestForWorkOrder = await serviceRequestProvider.getCallRequestForWorkOrder(callId: widget.workOrder!.callRequest!.id!.toString());
//     if (_subWorkOrders.parentWOId != null) {
//       ServiceReport? subWoDetails = await serviceRequestProvider.getSubWorkOrderDetails(parentId: _subWorkOrders.parentWOId.toString());
//       if (subWoDetails != null) {
//         _subWorkOrders.copyDetails(subWoDetails);
//         _serviceReport.equipmentStatus = subWoDetails.equipmentStatus;
//         _serviceReport.reason = subWoDetails.reason;
//         initialSupplier = subWoDetails.supplier;
//         _serviceReport.faultDescription = subWoDetails.faultDescription;
//         _subWorkOrders.visitDate = subWoDetails.visitDate;
//         _subWorkOrders.sparePartsWorkOrders = subWoDetails.sparePartsWorkOrders;
//       }
//     }
//     await assetTypesProvider.getTypes();
//     _subWorkOrders.assetType = assetTypesProvider.statuses?.firstWhere(
//       (element) => element.value == _callRequestForWorkOrder?.assetType,
//       orElse:  null,
//     );
//     if (checkVendorFieldsVisibility(_subWorkOrders.calllastSituation)) {
//       if (_subWorkOrders.suppEngineerWorkOrders?.isNotEmpty ?? false) {
//         engineer = _subWorkOrders.suppEngineerWorkOrders?.last;
//         engineer?.id = engineer?.supplierContactId;
//       }
//       _subWorkOrders.supplier ??= SupplierDetails(id: _subWorkOrders.supplier?.id);
//     }
//     _spareParts = await _partsProvider.getPartsList(assetId: widget.workOrder?.callRequest?.asset?.id);
//     setState(() {
//       _isLoading = false;
//     });
//   }
//
//   Asset? loanAvailabilityAsset;
//
//   @override
//   void dispose() {
//     _workPreformedController.dispose();
//     _partQtyController.dispose();
//     super.dispose();
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     final user = Provider.of<UserProvider>(context).user!;
//     final isCurrentUserIsAssistantEmp = (user.userID != widget.workOrder?.assignedEmployee?.id);
//     if (isCurrentUserIsAssistantEmp) {
//       // _subWorkOrders.assistantEmployees = [widget.workOrder.assistantEmployees?.first?.copyWith(id: 0)];
//       _subWorkOrders.assistantEmployees = [AssistantEmployees(id: 0, user: AssignedEmployee(id: user.userID, name: user.username))];
//     } else {}
//     if (_callRequestForWorkOrder == null) {
//       _partsProvider = Provider.of<PartsProvider>(context);
//       getAssetType();
//     }
//
//     bool disablePart = _subWorkOrders.calllastSituation?.value == 12;
//
//     return Scaffold(
//       appBar: DefaultAppBar(title: context.translation.createSubWorkOrder),
//       body: SafeArea(
//         child: _isLoading
//             ? const ALoading()
//             : Column(
//                 children: [
//                   SingleChildScrollView(
//                     child: Form(
//                       key: _formKey,
//                       child: Column(
//                         crossAxisAlignment: CrossAxisAlignment.stretch,
//                         children: [
//                           Card(
//                             child: Column(
//                               crossAxisAlignment: CrossAxisAlignment.stretch,
//                               children: [
//                                 (widget.workOrder?.callRequest?.asset?.site?.custName ?? "").heading5(context),
//                                 8.height,
//                                 "${context.translation.assetNo}: ${widget.workOrder?.callRequest?.asset?.assetNumber ?? ""}".bodyText(context),
//                                 "${context.translation.callId}: ${widget.workOrder?.callRequest?.id}".bodyText(context),
//                               ],
//                             ).paddingAll(16),
//                           ),
//                           // WorkOrderDetails(item: widget.workOrder, assetType: _subWorkOrders?.assetType),
//                           8.height,
//                           ADatePicker(
//                             label: context.translation.returnToService,
//                             date: DateTime.tryParse(_subWorkOrders.visitDate ?? ""),
//                             formatDateWithTime: true,
//                             onDatePicker: (selectedDate) {
//                               showTimePicker(
//                                 context: context,
//                                 initialTime: TimeOfDay.now(),
//                               ).then((selectedTime) {
//                                 if (selectedTime != null) {
//                                   DateTime selectedDateTime = DateTime(
//                                     selectedDate.year,
//                                     selectedDate.month,
//                                     selectedDate.day,
//                                     selectedTime.hour,
//                                     selectedTime.minute,
//                                   );
//                                   if (_subWorkOrders.visitDate != null && selectedDateTime.isBefore(DateTime.parse(_subWorkOrders.visitDate!))) {
//                                     "Visit Date time must be greater then previous date".showToast;
//                                     return;
//                                   }
//
//                                   setState(() {
//                                     _subWorkOrders.visitDate = selectedDateTime.toIso8601String();
//                                   });
//                                 }
//                               });
//                             },
//                           ),
//                           8.height,
//                           AppTimer(
//                             label: context.translation.workingHours,
//                             timer: _subWorkOrders.timer,
//                             enabled: _subWorkOrders.timer?.endAt == null,
//                             onChange: (timer) async {
//                               _subWorkOrders.timer = timer;
//                               if (timer.startAt != null && timer.endAt != null) {
//                                 if (timer.durationInSecond != 0) {
//                                   _subWorkOrders.workingHours = num.tryParse((((timer.durationInSecond ?? 0) / 60) / 60).toStringAsFixed(2) ?? "0");
//                                 } else {
//                                   timer.durationInSecond = (timer.endAt!.difference(timer.startAt!)).inSeconds;
//                                   String workingHours = (((timer.durationInSecond ?? 0) / 60) / 60).toStringAsFixed(2);
//                                   _subWorkOrders.workingHours = num.tryParse(workingHours ?? "0");
//                                 }
//                               }
//                               return true;
//                             },
//                           ),
//                           8.height,
//                           LoadingManager(
//                             isLoading: assetTypesProvider.isLoading,
//                             isFailedLoading: assetTypesProvider.statuses == null,
//                             stateCode: assetTypesProvider.stateCode,
//                             onRefresh: () async {
//                               assetTypesProvider.reset();
//                               await assetTypesProvider.getTypes();
//                               _subWorkOrders.assetType = assetTypesProvider.statuses?.firstWhere(
//                                 (element) => element.value == _serviceReport.callRequest?.assetType,
//                                 orElse:  null,
//                               );
//                             },
//                             child: AppTextFormField(
//                               labelText: context.translation.assetType,
//                               initialValue: _subWorkOrders.assetType?.name,
//                               textAlign: TextAlign.center,
//                               enable: false,
//                               style: Theme.of(context).textTheme.titleMedium,
//                             ),
//                           ),
//                           8.height,
//                           SingleItemDropDownMenu<Lookup, ReasonProvider>(
//                             context: context,
//                             title: context.translation.reason,
//                             initialValue: _subWorkOrders.reason,
//                             onSelect: (value) {
//                               if (value != null) {
//                                 _subWorkOrders.reason = value;
//                               }
//                             },
//                           ),
//                           8.height,
//                           SingleItemDropDownMenu<Lookup, EquipmentStatusProvider>(
//                             context: context,
//                             title: context.translation.equipmentStatus,
//                             initialValue: _subWorkOrders.equipmentStatus,
//                             onSelect: (value) {
//                               if (value != null) {
//                                 _subWorkOrders.equipmentStatus = value;
//                               }
//                             },
//                           ),
//                           8.height,
//                           ServiceReportLastCallsMenu(
//                             report: _serviceReport,
//                             title: context.translation.callLastSituation,
//                             parentId: widget.workOrder?.id?.toString(),
//                             onSelect: (status) {
//                               _serviceReport.calllastSituation = status;
//                               if (checkVendorFieldsVisibility(status)) {
//                                 _subWorkOrders.supplier ??= SupplierDetails(id: _subWorkOrders.supplier?.id);
//                                 engineer = null;
//                               } else {
//                                 _subWorkOrders.supplier = initialSupplier;
//                               }
//                               if (status?.value == 12 || _subWorkOrders.calllastSituation?.value == 12) {
//                                 _subWorkOrders.calllastSituation = status;
//                                 _subWorkOrders.mrNumber = null;
//                               } else {
//                                 _subWorkOrders.calllastSituation = status;
//                               }
//                               setState(() {});
//                             },
//                           ),
//                           if (_subWorkOrders.calllastSituation?.value == 12) const SizedBox(height: 8),
//                           if (_subWorkOrders.calllastSituation?.value == 12)
//                             AppTextFormField(
//                               labelText: context.translation.mrNumber,
//                               initialValue: _subWorkOrders.mrNumber,
//                               onSaved: (value) {
//                                 _subWorkOrders.mrNumber = value;
//                               },
//                             ),
//                           if (_showVendorFields) const SizedBox(height: 8),
//                           if (_showVendorFields)
//                             SingleItemDropDownMenu<SupplierDetails, VendorProvider>(
//                               context: context,
//                               title: context.translation.supplier,
//                               initialValue: _subWorkOrders.supplier ?? initialSupplier,
//                               showAsBottomSheet: true,
//                               onSelect: (supplier) {
//                                 if (supplier != null) {
//                                   _subWorkOrders.supplier = supplier;
//                                   //   log(_subWorkOrders.supplier?.suppPersons?.map((e) => e.personName)?.toString());
//                                   setState(() {});
//                                 }
//                               },
//                             ),
//                           if (_showVendorFields) const SizedBox(height: 8),
//                           if (_showVendorFields)
//                             Row(
//                               children: [
//                                 SingleItemDropDownMenu<SuppPersons, NullableLoadingProvider>(
//                                   context: context,
//                                   title: context.translation.supplierEngineer,
//                                   enabled: _subWorkOrders.supplier?.suppPersons?.isNotEmpty ?? false,
//                                   staticData: _subWorkOrders.supplier?.suppPersons,
//                                   showAsBottomSheet: true,
//                                   initialValue: engineer == null ? null : SuppPersons.fromJson(engineer!.toJson()),
//                                   onSelect: (suppPerson) {
//                                     if (suppPerson != null) {
//                                       engineer = SuppEngineerWorkOrders.fromJson(suppPerson.toJson());
//                                       // engineer = SuppEngineerWorkOrders(
//                                       //   id: suppPerson?.supplierId,
//                                       //   supplierContactId: suppPerson?.id,
//                                       //   personName: suppPerson?.personName,
//                                       //   contact: suppPerson?.contact,
//                                       //   externalEngCode: suppPerson?.externalEngCode,
//                                       //   email: suppPerson?.email,
//                                       // );
//                                       setState(() {});
//                                     }
//                                   },
//                                 ).expanded,
//                                 8.width,
//                                 Container(
//                                   height: 60.toScreenHeight,
//                                   width: 60.toScreenWidth,
//                                   decoration: BoxDecoration(
//                                     color: _subWorkOrders.supplier?.suppliername == null ? AppColor.neutral40 : AppColor.background(context),
//                                     borderRadius: BorderRadius.circular(10),
//                                     boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
//                                   ),
//                                   child: Icon(
//                                     Icons.add,
//                                     color: context.isDark ? null : AppColor.neutral60,
//                                   ),
//                                 ).onPress(_subWorkOrders.supplier?.suppliername == null
//                                     ? null
//                                     : () async {
//                                         SuppEngineerWorkOrders suppEngineer = (await showModalBottomSheet(
//                                           context: context,
//                                           useSafeArea: true,
//                                           isScrollControlled: true,
//                                           backgroundColor: Colors.transparent,
//                                           builder: (context) => AddSupplierEngineerBottomSheet(_subWorkOrders.supplier!.id!.toInt()),
//                                         )) as SuppEngineerWorkOrders;
//                                         _subWorkOrders.supplier?.suppPersons ??= [];
//                                         _subWorkOrders.supplier?.suppPersons?.add(SuppPersons.fromJson(suppEngineer.toJson()));
//                                         engineer = suppEngineer;
//                                         setState(() {});
//                                                                             }),
//                               ],
//                             ),
//                           8.height,
//                           ServiceReportFaultDescription(
//                             requestId: widget.workOrder?.callRequest?.id?.toString(),
//                             initialValue: _subWorkOrders.faultDescription,
//                             onSelect: (status) {
//                               _subWorkOrders.faultDescription = status;
//                               _workPreformedController.text = _subWorkOrders.faultDescription?.workPerformed ?? "";
//                             },
//                           ),
//                           8.height,
//                           AppTextFormField(
//                             labelText: context.translation.solution,
//                             initialValue: _subWorkOrders.faultDescription?.workPerformed,
//                             textAlign: TextAlign.center,
//                             enable: false,
//                             controller: _workPreformedController,
//                           ),
//                           8.height,
//                           SingleItemDropDownMenu<Lookup, LoanAvailabilityProvider>(
//                             context: context,
//                             title: context.translation.loanAvailability,
//                             initialValue: _subWorkOrders.loanAvailablity,
//                             onSelect: (status) {
//                               if (status != null) {
//                                 setState(() {
//                                   _subWorkOrders.loanAvailablity = status;
//                                   if (_subWorkOrders.loanAvailablity?.value != 1) {
//                                     loanAvailabilityAsset = null;
//                                     _subWorkOrders.assetLoan = null;
//                                   }
//                                 });
//                               }
//                             },
//                           ),
//                           if (_subWorkOrders.loanAvailablity?.value == 1) 8.height,
//                           if (_subWorkOrders.loanAvailablity?.value == 1)
//
//                             PickAsset(
//                               device: loanAvailabilityAsset, // ?? _serviceReport.device,
//                               onPickAsset: (asset) {
//                                 _subWorkOrders.assetLoan = AssetInfo.fromJson(asset.toJson());
//                                 setState(() {
//                                   loanAvailabilityAsset = asset;
//                                 });
//                                                             },
//                             ),
//                           8.height,
//                           ServiceReportAssistantEmployeeMenu(
//                             title: context.translation.assignAssistant,
//                             assetId: widget.workOrder!.callRequest!.asset!.id!.toInt(),
//
//                             initialValue: (_subWorkOrders.assistantEmployees?.isNotEmpty ?? false) ? _subWorkOrders.assistantEmployees?.first : null,
//                             // initialValue: !isCurrentAssigned
//                             //     ? (widget.workOrder.assistantEmployees?.first)
//                             //     : (_subWorkOrders.assistantEmployees?.isNotEmpty ?? false)
//                             //         ? _subWorkOrders.assistantEmployees?.first
//                             //         : null,
//                             enable: !isCurrentUserIsAssistantEmp,
//                             onSelect: (employee) {
//                               if (employee == null) {
//                                 _subWorkOrders.assistantEmployees = [];
//                               } else {
//                                 _subWorkOrders.assistantEmployees = [employee.copyWith(id: 0)];
//                               }
//                             },
//                           ),
//                           8.height,
//                           ServiceReportRepairLocation(
//                             label: context.translation.repairLocation,
//                             initialValue: _subWorkOrders.repairLocation,
//                             onSelect: (status) {
//                               _subWorkOrders.repairLocation = status;
//                             },
//                           ),
//                           8.height,
//                           PartNoButton(
//                             controller: _partQtyController,
//                             spareParts: _spareParts,
//                             disablePartEdit: disablePart,
//                             initialList: _subWorkOrders.sparePartsWorkOrders,
//                             onChange: (parts) {
//                               _subWorkOrders.sparePartsWorkOrders = parts;
//                             },
//                           ),
//                           8.height,
//                           MultiFilesPicker(label: context.translation.attachImage, files: _files),
//                           8.height,
//                           AppTextFormField(
//                             labelText: context.translation.travelingExpense,
//                             initialValue: _subWorkOrders.travelingExpenses?.toString(),
//                             textInputType: TextInputType.number,
//                             onSaved: (value) {
//                               _subWorkOrders.travelingExpenses = double.tryParse(value) ?? 0.0;
//                             },
//                           ),
//                           8.height,
//                           AppTextFormField(
//                             labelText: context.translation.travelingHours,
//                             initialValue: _subWorkOrders.travelingHours?.toString(),
//                             textInputType: TextInputType.number,
//                             onSaved: (value) {
//                               _subWorkOrders.travelingHours = double.tryParse(value) ?? 0.0;
//                             },
//                           ),
//                           8.height,
//                           AppTextFormField(
//                             initialValue: _subWorkOrders.comment,
//                             labelText: context.translation.technicalComment,
//                             alignLabelWithHint: true,
//                             textInputType: TextInputType.multiline,
//                             onSaved: (value) {
//                               _subWorkOrders.comment = value;
//                             },
//                           ),
//                           8.height,
//                           ESignature(
//                             title: context.translation.engSign,
//                             oldSignature: _subWorkOrders.engSignature,
//                             newSignature: _subWorkOrders.localEngSignature,
//                             // onChange: (signature) {
//                             //   // if (signature == null || signature.isEmpty) {
//                             //   //   setState(() {});
//                             //   //   return;
//                             //   // }
//                             //   if (signature == null || signature.isEmpty) return;
//                             //   _subWorkOrders.localEngSignature = signature;
//                             //   _subWorkOrders.engSignature = signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}" : null;
//                             //   print("_serviceReport.engSignature:${_serviceReport.engSignature}");
//                             // },
//                             onSaved: (signature) {
//                               if (signature == null || signature.isEmpty) {
//                                 setState(() {});
//                                 return;
//                               }
//                               if (signature.isEmpty) return;
//                               _subWorkOrders.localEngSignature = signature;
//                               _subWorkOrders.engSignature = signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}" : null;
//                             },
//                           ),
//                           8.height,
//                           ESignature(
//                             title: context.translation.nurseSignature,
//                             oldSignature: _subWorkOrders.nurseSignature,
//                             newSignature: _subWorkOrders.localNurseSignature,
//                             onSaved: (signature) {
//                               // if (signature == null || signature.isEmpty) {
//                               //   setState(() {});
//                               //   return;
//                               // }
//                               if (signature == null || signature.isEmpty) return;
//                               _subWorkOrders.localNurseSignature = signature;
//                               _subWorkOrders.nurseSignature = signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}" : null;
//                             },
//                           ),
//                           16.height,
//                         ],
//                       ),
//                     ),
//                   ).paddingAll(16).expanded,
//                   AppFilledButton(
//                     label: context.translation.submitRequest,
//                     onPressed: () async {
//                       setState(() {});
//                       _subWorkOrders.suppEngineerWorkOrders = [];
//                       if (engineer != null) {
//                         _subWorkOrders.suppEngineerWorkOrders!.add(engineer!);
//                       }
//                       //  return;
//                       if (await validate()) {
//                         _subWorkOrders.attachmentsWorkOrder ??= [];
//                         for (var file in _files) {
//                           _subWorkOrders.attachmentsWorkOrder!.add(Attachment(id: 0, name: "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}"));
//                         }
//                         if (_formKey.currentState?.validate() ?? false) {}
//                         _formKey.currentState?.save();
//                         final serviceRequestsProvider = Provider.of<ServiceRequestsProvider>(context, listen: false);
//                         for (var element in (_subWorkOrders.suppEngineerWorkOrders ?? [])) {
//                           if (element != null && element.id != 0) {
//                             element.supplierContactId = element.id;
//                             element.id = 0;
//                           }
//                         }
//
//                         showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
//                         final status = await serviceRequestsProvider.createSubWorkOrder(workOrder: _subWorkOrders, makeSuppPersonsEmpty: true);
//                         Navigator.of(context).pop();
//                         if (status >= 200 && status < 300) {
//                           Fluttertoast.showToast(msg: context.translation.successfulRequestMessage);
//                           Navigator.of(context).pop();
//                         } else {
//                           String errorMessage = HttpStatusManger.getStatusMessage(status: serviceRequestsProvider.stateCode, subtitle: context.translation);
//                           ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(errorMessage)));
//                         }
//                       }
//                     },
//                   ).paddingAll(16),
//                 ],
//               ),
//       ),
//     );
//   }
//
//   bool checkVendorFieldsVisibility(Lookup? callsLastSituation) {
//     bool result = (initialSupplier?.suppliername?.isNotEmpty ?? false) ||
//         (callsLastSituation?.name?.toLowerCase().contains("under repair-vendor") ?? false) ||
//         (callsLastSituation?.name?.toLowerCase().contains("waiting for vendor") ?? false);
//     setState(() {
//       _showVendorFields = result;
//     });
//     return result;
//   }
//
//   Future<bool> validate() async {
//     if (_subWorkOrders.reason == null) {
//       Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.reason}");
//       return false;
//     } else if (_subWorkOrders.equipmentStatus == null) {
//       Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.equipmentStatus}");
//       return false;
//     } else if (_subWorkOrders.calllastSituation == null) {
//       Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.callLastSituation}");
//       return false;
//     } else if (_showVendorFields && _subWorkOrders.suppEngineerWorkOrders == null) {
//       Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.supplierEngineer}");
//       return false;
//     } else if (_showVendorFields && (_subWorkOrders.supplier?.suppliername?.isEmpty ?? true)) {
//       Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.supplier}");
//       return false;
//     } else if (_subWorkOrders.calllastSituation!.value == 12 && (_subWorkOrders.sparePartsWorkOrders?.isEmpty ?? true)) {
//       Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.partNo}");
//       return false;
//     } else if (_subWorkOrders.timer?.startAt == null) {
//       await Fluttertoast.showToast(msg: "Working Hours Required");
//       return false;
//     } else if (_subWorkOrders.timer?.endAt == null) {
//       await Fluttertoast.showToast(msg: "Please Stop The Timer");
//       return false;
//     }
//     return true;
//   }
// }
