From 448a85522a85a211d43734684b95cff862d52f8d Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 <50428976+WaseemAbbasi22@users.noreply.github.com> Date: Thu, 27 Aug 2026 12:10:52 +0300 Subject: [PATCH] bug fixes --- lib/main.dart | 4 + lib/models/generic_attachment_model.dart | 22 +++- .../helper_function.dart | 1 + .../pages/attachment_view.dart | 116 +++++++++--------- .../models/asset_inventory_model.dart | 2 +- .../pages/asset_detail_card_view.dart | 1 + .../pages/asset_inventory_form_view.dart | 7 +- .../demo_module/demo_request_item_view.dart | 2 +- .../update_equipment_internal_audit_page.dart | 1 + .../system_internal_audit_detail_page.dart | 11 +- .../traf_module/traf_request_detail_page.dart | 16 +-- .../create_request_type_bottom_sheet.dart | 1 + lib/views/widgets/images/files_list.dart | 1 + .../widgets/images/multi_image_picker.dart | 17 +-- 14 files changed, 116 insertions(+), 86 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d65c1255..615b98ba 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -68,6 +68,7 @@ import 'package:test_sa/modules/applicationDemo/providers/application_demo_reque import 'package:test_sa/modules/applicationDemo/screens/application_demo_request_form_screen.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'; import 'package:test_sa/new_views/app_style/app_themes.dart'; import 'package:test_sa/new_views/pages/help_center_page.dart'; import 'package:test_sa/new_views/pages/land_page/land_page.dart'; @@ -145,6 +146,7 @@ import 'modules/tm_module/device_transfer/device_filter_screen.dart'; import 'modules/tm_module/device_transfer/device_search_screen.dart'; import 'modules/tm_module/tasks/create_task_view.dart'; import 'modules/tm_module/gas_refill/gas_refill_request_form.dart'; +import 'modules/traf_module/traf_request_provider.dart'; import 'providers/lookups/classification_lookup_provider.dart'; import 'providers/lookups/customer_lookup_provider.dart'; import 'providers/lookups/department_lookup_provider.dart'; @@ -387,6 +389,7 @@ class MyApp extends StatelessWidget { // UTILITY PROVIDERS (1) ChangeNotifierProvider(create: (_) => OracleCodeProvider(), lazy: true), + ChangeNotifierProvider(create: (_) => TrafRequestProvider(), lazy: true), ], child: GestureDetector( onTap: () { @@ -425,6 +428,7 @@ class MyApp extends StatelessWidget { DeviceSearchScreen.id: (_) => const DeviceSearchScreen(), DeviceFilterScreen.id: (_) => const DeviceFilterScreen(), CreateIncidentRequestPage.id: (_) => CreateIncidentRequestPage(), + CreateTRAFRequestPage.id: (_) => CreateTRAFRequestPage(), SettingsPage.id: (_) => const SettingsPage(), ProfilePage.id: (_) => const ProfilePage(), ReportBugPage.id: (_) => const ReportBugPage(), diff --git a/lib/models/generic_attachment_model.dart b/lib/models/generic_attachment_model.dart index 41749f68..68f262b3 100644 --- a/lib/models/generic_attachment_model.dart +++ b/lib/models/generic_attachment_model.dart @@ -163,10 +163,19 @@ class GenericAttachmentModel { documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; originalName = json['originalName']; } + GenericAttachmentModel.fromAssetInventoryJson(Map json) { + id = json['id']; + name = json['attachmentName']; + attachmentURL = json['attachmentURL']; + documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; + originalName = json['originalName']; + } GenericAttachmentModel.fromTrafJson(Map json) { id = json['id']; + moduleReferenceId= json['trafId']; name = json['attachmentName']; + attachmentDescription = json['attachmentDescription']; moduleReferenceId = json['trafId']; documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; } @@ -287,10 +296,19 @@ class GenericAttachmentModel { data['originalName'] = originalName; return data; } + Map toAssetDeliveryJson() { + final Map data = {}; + data['id'] = id; + data['name'] = name; + data['attachmentTypeId'] = documentType?.id; + data['originalName'] = originalName; + data['createdBy'] = createdBy; + return data; + } Map toInventoryJson() { final Map data = {}; data['id'] = id; - data['attachmentName'] = name; + data['Name'] = name; data['attachmentURL'] = attachmentURL; data['attachmentTypeId'] = documentType?.id; data['originalName'] = originalName; @@ -302,7 +320,7 @@ class GenericAttachmentModel { data['id'] = id; data['trafId'] = moduleReferenceId; data['attachmentName'] = name; - data['documentTypeId'] = documentType?.id; + data['attachmentTypeId'] = documentType?.id; return data; } diff --git a/lib/modules/asset_delivery_module/helper_function.dart b/lib/modules/asset_delivery_module/helper_function.dart index 747c34c6..0fc2e7ea 100644 --- a/lib/modules/asset_delivery_module/helper_function.dart +++ b/lib/modules/asset_delivery_module/helper_function.dart @@ -34,6 +34,7 @@ class HelperFunction { builder: (context) => AssetDeliveryAttachmentView( tableItemId: deliveryTableItemId, attachmentType: result!.value, + documentType: Lookup(id: result.id, value: result.value, name: result.name), viewOnly: viewOnly, attachmentList: list, ))); diff --git a/lib/modules/asset_delivery_module/pages/attachment_view.dart b/lib/modules/asset_delivery_module/pages/attachment_view.dart index 6d699a62..c42a97e8 100644 --- a/lib/modules/asset_delivery_module/pages/attachment_view.dart +++ b/lib/modules/asset_delivery_module/pages/attachment_view.dart @@ -11,6 +11,7 @@ import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/enums/request_attachment_type_enum.dart'; import 'package:test_sa/models/generic_attachment_model.dart'; +import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/modules/asset_delivery_module/provider/asset_delivery_provider.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'; @@ -26,6 +27,7 @@ import 'package:test_sa/views/widgets/loaders/no_data_found.dart'; class AssetDeliveryAttachmentView extends StatefulWidget { final int? tableItemId; final int? attachmentType; + final Lookup? documentType; bool viewOnly = false; final List attachmentList; @@ -34,6 +36,7 @@ class AssetDeliveryAttachmentView extends StatefulWidget { required this.attachmentList, this.viewOnly = false, this.attachmentType, + this.documentType, this.tableItemId, }); @@ -76,73 +79,74 @@ class _AssetDeliveryAttachmentViewState extends State URLs.getFileUrl(e.name ?? '') ?? '',).toList() ?? []).toShadowContainer( - context, - borderRadius: 20, - padding: 12, - margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), - ), - ], - ), - ], - ), - ), - if (widget.attachmentType == 5 && !widget.viewOnly) - FooterActionButton.footerContainer( - context: context, - child: AppFilledButton( - buttonColor: AppColor.primary10, - label: 'Save'.addTranslation, - maxWidth: true, - onPressed: _onSavePressed, - ), - ), + widget.attachmentType == 5 && !widget.viewOnly + ? AttachmentPicker( + label: context.translation.attachments, + showTypeDropdown: false, + attachment: _attachments, + moduleId: RequestAttachmentTypeEnum.assetDelivery.id, + buttonColor: AppColor.primary10, + documentType: widget.documentType, + onlyImages: false, + showAsListView: true, + buttonIcon: 'quotation_icon'.toSvgAsset(color: AppColor.primary10), + onChange: (attachment) {}, + ).toShadowContainer( + context, + borderRadius: 20, + padding: 12, + margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + ) + : FilesList( + showAsListView: true, + types: _attachments.map((doc) { + final attachmentType = doc.documentType?.name ?? ''; + return attachmentType.isNotEmpty ? attachmentType : 'Asset Guide'; + }).toList(), + images: _attachments + .map( + (e) => URLs.getFileUrl(e.name ?? '') ?? '', + ) + .toList() ?? + []) + .toShadowContainer( + context, + borderRadius: 20, + padding: 12, + margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + ), ], ), + ), + if (widget.attachmentType == 5 && !widget.viewOnly) + FooterActionButton.footerContainer( + context: context, + child: AppFilledButton( + buttonColor: AppColor.primary10, + label: 'Save'.addTranslation, + maxWidth: true, + onPressed: _onSavePressed, + ), + ), + ], + ), ); } Future _onSavePressed() async { - final List attachmentPayload = _attachments.map((item) { + final List> attachmentPayload = _attachments.map((item) { final String name = CMRequestUtils.isLocalUrl(item.name ?? '') ? '${item.name?.split("/").last}|${base64Encode(File(item.name!).readAsBytesSync())}' : item.name ?? ''; - return GenericAttachmentModel( id: item.id ?? 0, name: name, - documentType: item.documentType, - - ); + documentType: widget.documentType, + ).toAssetDeliveryJson(); }).toList(); showDialog( diff --git a/lib/modules/asset_inventory_module/models/asset_inventory_model.dart b/lib/modules/asset_inventory_module/models/asset_inventory_model.dart index fd913df8..c63f477f 100644 --- a/lib/modules/asset_inventory_module/models/asset_inventory_model.dart +++ b/lib/modules/asset_inventory_module/models/asset_inventory_model.dart @@ -200,7 +200,7 @@ class AssetInventoryModel { if (json['assetInventoryDetailAssetAttachments'] != null) { assetInventoryDetailAssetAttachments = []; json['assetInventoryDetailAssetAttachments'].forEach((v) { - assetInventoryDetailAssetAttachments.add(GenericAttachmentModel.fromAssetJson(v)); + assetInventoryDetailAssetAttachments.add(GenericAttachmentModel.fromAssetInventoryJson(v)); }); } diff --git a/lib/modules/asset_inventory_module/pages/asset_detail_card_view.dart b/lib/modules/asset_inventory_module/pages/asset_detail_card_view.dart index 60a5c710..d90ec511 100644 --- a/lib/modules/asset_inventory_module/pages/asset_detail_card_view.dart +++ b/lib/modules/asset_inventory_module/pages/asset_detail_card_view.dart @@ -11,6 +11,7 @@ import 'package:test_sa/modules/asset_inventory_module/models/asset_inventory_mo import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/views/widgets/loaders/image_loader.dart'; +///TODO We are not showing attachment here we need to check this with backend team and flow . class AssetDetailCardView extends StatelessWidget { AssetInventoryModel assetInventoryModel; VoidCallback onDeletePress; diff --git a/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart b/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart index 48f5fcb0..09277488 100644 --- a/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart +++ b/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart @@ -296,12 +296,7 @@ class _AssetInventoryFormViewState extends State { classificationWidget(label: _scannedAssetModel?.status), ], 12.height, - InfoHeader16Widget('Attachments'.addTranslation), - // Text( - // 'Attachments'.addTranslation, - // style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.white936), - // ), - 8.height, + AttachmentPicker( moduleId: RequestAttachmentTypeEnum.assetInventory.id, label: context.translation.attachFiles, diff --git a/lib/modules/demo_module/demo_request_item_view.dart b/lib/modules/demo_module/demo_request_item_view.dart index 6abc6d58..5338dcac 100644 --- a/lib/modules/demo_module/demo_request_item_view.dart +++ b/lib/modules/demo_module/demo_request_item_view.dart @@ -54,7 +54,7 @@ class DemoRequestItemView extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ StatusLabel( - label: requestDetails!.status!, + label: requestDetails?.status??'', textColor: AppColor.demoRequestStatusTextColor(context, requestDetails?.statusValue ?? 0), backgroundColor: AppColor.demoRequestStatus(context, requestDetails?.statusValue ?? 0), ), diff --git a/lib/modules/internal_audit_module/pages/equipment_internal_audit/update_equipment_internal_audit_page.dart b/lib/modules/internal_audit_module/pages/equipment_internal_audit/update_equipment_internal_audit_page.dart index 5e986081..cf60b860 100644 --- a/lib/modules/internal_audit_module/pages/equipment_internal_audit/update_equipment_internal_audit_page.dart +++ b/lib/modules/internal_audit_module/pages/equipment_internal_audit/update_equipment_internal_audit_page.dart @@ -26,6 +26,7 @@ import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart'; import 'package:test_sa/new_views/common_widgets/default_app_bar.dart'; import 'package:test_sa/new_views/common_widgets/working_time_tile.dart'; import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; +import 'package:test_sa/views/widgets/item_views/info_header_widget.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import 'package:test_sa/views/widgets/timer/app_timer.dart'; import 'package:test_sa/views/widgets/total_working_time_detail_bottomsheet.dart'; diff --git a/lib/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_detail_page.dart b/lib/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_detail_page.dart index dda1f510..1f264369 100644 --- a/lib/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_detail_page.dart +++ b/lib/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_detail_page.dart @@ -86,19 +86,19 @@ class _SystemInternalAuditDetailPageState extends State { if (_attachments.isNotEmpty) ...[ 4.height, InfoHeader16Widget("Attachments".addTranslation), + 4.height, FilesList( - showAsListView: true, - types: _attachments - .whereType() - .where((e) => e.documentType != null && e.documentType!.name!.isNotEmpty) - .map((toElement) => toElement.documentType!.name!) - .toList(), - images: _attachments.map((e) => URLs.getFileUrl(e.path ?? '') ?? '').toList() ?? []), + showAsListView: true, + types: data.attachments + ?.whereType() + .where((e) => e.documentType != null && e.documentType!.name!.isNotEmpty) + .map((toElement) => toElement.documentType!.name!) + .toList() ?? + [], + images: _attachments.map((e) => URLs.getFileUrl(e.path ?? '') ?? '').toList()), ], ], ).toShadowContainer(context); diff --git a/lib/new_views/pages/land_page/create_request_type_bottom_sheet.dart b/lib/new_views/pages/land_page/create_request_type_bottom_sheet.dart index 04eaf070..dcad5347 100644 --- a/lib/new_views/pages/land_page/create_request_type_bottom_sheet.dart +++ b/lib/new_views/pages/land_page/create_request_type_bottom_sheet.dart @@ -106,6 +106,7 @@ class _CreateRequestTypeBottomSheetState extends State with SingleTickerPr vsync: this, ); _animationController.forward(); + // if (widget.documentType != null) { + // documentLookup = widget.documentType; + // } WidgetsBinding.instance.addPostFrameCallback((_) { Provider.of(context, listen: false).reset(); - log('i am going to reset the value'); }); } @@ -136,6 +138,7 @@ class _AttachmentPickerState extends State with SingleTickerPr file: image, showAsListView: widget.showAsListView, enabled: widget.enabled, + // documentType: widget.documentType != null ? widget.documentType?.name : widget.attachment[index].documentType?.name, documentType: widget.attachment[index].documentType?.name, onRemoveTap: (image) { if (!widget.enabled) { @@ -186,7 +189,7 @@ class _AttachmentPickerState extends State with SingleTickerPr ); if (result != null) { for (var path in result.paths) { - widget.attachment.add(GenericAttachmentModel(id: 0, name: File(path!).path, documentType: documentLookup)); + widget.attachment.add(GenericAttachmentModel(id: 0, name: File(path!).path, documentType: widget.documentType ?? documentLookup)); } if (widget.onChange != null) { widget.onChange!(widget.attachment); @@ -229,8 +232,7 @@ class _AttachmentPickerState extends State with SingleTickerPr return StatefulBuilder( builder: (BuildContext context, StateSetter setModalState) { Widget listCard({required String icon, required String label, required VoidCallback onTap}) { - - bool isEnabled = !widget.showTypeDropdown?true:documentLookup != null; + bool isEnabled = !widget.showTypeDropdown ? true : documentLookup != null; return Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( @@ -305,7 +307,7 @@ class _AttachmentPickerState extends State with SingleTickerPr 8.height, InfoHeader16Widget(widget.pickerTitle), 8.height, - if(widget.showTypeDropdown)...[ + if (widget.showTypeDropdown) ...[ SingleItemDropDownMenu( context: context, height: 56.toScreenHeight, @@ -325,7 +327,6 @@ class _AttachmentPickerState extends State with SingleTickerPr const InfoTextLabelWidget(label: 'Please Select Document Type before picking file', color: AppColor.red30), ], ], - GridView.builder( padding: const EdgeInsets.only(top: 16, bottom: 0), shrinkWrap: true, @@ -381,7 +382,7 @@ class _AttachmentPickerState extends State with SingleTickerPr pickedFiles.forEach((pickedFile) { File fileImage = File(pickedFile.path); - widget.attachment.add(GenericAttachmentModel(id: 0, name: fileImage.path, documentType: documentLookup)); + widget.attachment.add(GenericAttachmentModel(id: 0, name: fileImage.path, documentType: widget.documentType ?? documentLookup)); }); if (widget.onChange != null) { widget.onChange!(widget.attachment); @@ -408,7 +409,7 @@ class _AttachmentPickerState extends State with SingleTickerPr } } - widget.attachment.add(GenericAttachmentModel(id: 0, name: fileImage.path, documentType: documentLookup)); + widget.attachment.add(GenericAttachmentModel(id: 0, name: fileImage.path, documentType: widget.documentType ?? documentLookup)); if (widget.onChange != null) { widget.onChange!(widget.attachment); }