From ab6b14376342e9e0e4dbac32d7e260d9ceb6630c Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Thu, 25 Dec 2025 12:41:02 +0300 Subject: [PATCH] improvements --- lib/extensions/context_extension.dart | 4 +- .../pages/asset_delivery_page.dart | 102 ++++++------ .../pages/attachment_view.dart | 9 +- .../pages/change_status_bottomsheet.dart | 33 ++-- .../cost_center_form_view.dart | 88 +++++----- .../delivery_inspection_form_view.dart | 37 ++--- .../end_user_cost_center_list_view.dart | 36 ++-- .../technical_inspection_lines_list_view.dart | 155 +++++++++--------- 8 files changed, 229 insertions(+), 235 deletions(-) diff --git a/lib/extensions/context_extension.dart b/lib/extensions/context_extension.dart index f85af74c..96e79211 100644 --- a/lib/extensions/context_extension.dart +++ b/lib/extensions/context_extension.dart @@ -29,11 +29,9 @@ extension BuildContextExtension on BuildContext { return isTablet; } - - void showConfirmDialog(String message, {String? title, VoidCallback? onTap, String? okTitle}) => showDialog( context: this, - builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title,okTitle: okTitle), + builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title, okTitle: okTitle), ); Future showBottomSheet(Widget childWidget, {bool? isDismissible, String? title}) => showModalBottomSheet( diff --git a/lib/modules/asset_delivery_module/pages/asset_delivery_page.dart b/lib/modules/asset_delivery_module/pages/asset_delivery_page.dart index aad1d276..b3a3174b 100644 --- a/lib/modules/asset_delivery_module/pages/asset_delivery_page.dart +++ b/lib/modules/asset_delivery_module/pages/asset_delivery_page.dart @@ -74,60 +74,58 @@ class _AssetDeliveryPageState extends State { if (dataModel == null) { return const NoDataFound().center; } - return ListView( - padding: const EdgeInsets.all(12), - children: [ - requestDetailCard(context), - const Divider().defaultStyle(context), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Asset Delivery Table", - style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10), - ), - Row( - children: [ - Container( - height: 24, - width: 24, - decoration: const BoxDecoration( - shape: BoxShape.circle, - color: AppColor.primary10, // or AppColor.blueStatus(context) - ), - alignment: Alignment.center, - child: const Icon( - Icons.add, - color: Colors.white, - size: 16, + return SingleChildScrollView( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + requestDetailCard(context), + const Divider().defaultStyle(context), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Asset Delivery Table", + style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10), + ), + Row( + children: [ + Container( + height: 24, + width: 24, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: AppColor.primary10, // or AppColor.blueStatus(context) + ), + alignment: Alignment.center, + child: const Icon( + Icons.add, + color: Colors.white, + size: 16, + ), ), - ), - 4.width, - Text( - "Add more", - style: AppTextStyles.bodyText.copyWith( - color: context.isDark ? AppColor.neutral30 : AppColor.neutral50, - decoration: TextDecoration.underline, + 4.width, + Text( + "Add more", + style: AppTextStyles.bodyText.copyWith( + color: context.isDark ? AppColor.neutral30 : AppColor.neutral50, + decoration: TextDecoration.underline, + ), ), - ), - ], - ).onPress(() async { - await assetDeliveryProvider?.addNewDelivery(requestId: widget.requestId).then((status) async { - if (status) { - await assetDeliveryProvider?.getAssetDeliveryTableListById(requestId: widget.requestId); - } - }); - }), - ], - ), - 8.height, - assetDeliveryTableList(context: context, assetDeliveryProvider: provider), - ], - ).toShadowContainer( - context, - borderRadius: 20, - padding: 0, - margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), + ], + ).onPress(() async { + await assetDeliveryProvider?.addNewDelivery(requestId: widget.requestId).then((status) async { + if (status) { + await assetDeliveryProvider?.getAssetDeliveryTableListById(requestId: widget.requestId); + } + }); + }), + ], + ), + 8.height, + assetDeliveryTableList(context: context, assetDeliveryProvider: provider), + ], + ).toShadowContainer(context, borderRadius: 20), ); }, ), diff --git a/lib/modules/asset_delivery_module/pages/attachment_view.dart b/lib/modules/asset_delivery_module/pages/attachment_view.dart index 0c22772e..a8834fcc 100644 --- a/lib/modules/asset_delivery_module/pages/attachment_view.dart +++ b/lib/modules/asset_delivery_module/pages/attachment_view.dart @@ -78,6 +78,7 @@ class _AssetDeliveryAttachmentViewState extends State attachement = []; for (var item in _attachments) { String fileName = - CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; + CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; attachement.add(GenericAttachmentModel(id: item.id ?? 0, name: fileName)); } showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); - Map payLoad ={ + Map payLoad = { 'assetDeliveryExternalDeliveryId': widget.tableItemId, - 'attachments':attachement, + 'attachments': attachement, }; - await assetDeliveryProvider.saveAttachment(payload:payLoad).then((status) async { + await assetDeliveryProvider.saveAttachment(payload: payLoad).then((status) async { Navigator.pop(context); if (status) { ///Need to verify need to stay on this page and refresh or go back.. diff --git a/lib/modules/asset_delivery_module/pages/change_status_bottomsheet.dart b/lib/modules/asset_delivery_module/pages/change_status_bottomsheet.dart index 696207bf..1eb16c9c 100644 --- a/lib/modules/asset_delivery_module/pages/change_status_bottomsheet.dart +++ b/lib/modules/asset_delivery_module/pages/change_status_bottomsheet.dart @@ -1,5 +1,3 @@ - - import 'package:flutter/material.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/string_extensions.dart'; @@ -21,7 +19,7 @@ class AssetDeliveryBottomSheet { ); } - static Future changeStatusBottomSheet({required BuildContext context,required VoidCallback cancelStatusTap,required VoidCallback statusChangeTap}) { + static Future changeStatusBottomSheet({required BuildContext context, required VoidCallback cancelStatusTap, required VoidCallback statusChangeTap}) { return buildBottomSheetParent( context: context, childWidget: Column( @@ -31,14 +29,17 @@ class AssetDeliveryBottomSheet { 8.height, Align( alignment: AlignmentDirectional.centerStart, - child: Text('Change Status'.addTranslation,style: TextStyle( - fontSize: 21.toScreenWidth, - fontWeight: FontWeight.w500, - fontStyle: FontStyle.normal, - decoration: TextDecoration.none, - ),), + child: Text( + 'Change Status'.addTranslation, + style: TextStyle( + fontSize: 21.toScreenWidth, + fontWeight: FontWeight.w500, + fontStyle: FontStyle.normal, + decoration: TextDecoration.none, + ), + ), ), - 10.height, + 16.height, Row( children: [ AppFilledButton( @@ -50,14 +51,16 @@ class AssetDeliveryBottomSheet { showBorder: true, onPressed: () async { cancelStatusTap(); - }, ).expanded, 12.width, - AppFilledButton(buttonColor: AppColor.green70, label: 'Change Status'.addTranslation, maxWidth: true, onPressed: () { - statusChangeTap(); - - }).expanded, + AppFilledButton( + buttonColor: AppColor.green70, + label: 'Change Status'.addTranslation, + maxWidth: true, + onPressed: () { + statusChangeTap(); + }).expanded, ], ), ], diff --git a/lib/modules/asset_delivery_module/pages/delivery_inspection/cost_center_form_view.dart b/lib/modules/asset_delivery_module/pages/delivery_inspection/cost_center_form_view.dart index 4dec60db..3cc0497b 100644 --- a/lib/modules/asset_delivery_module/pages/delivery_inspection/cost_center_form_view.dart +++ b/lib/modules/asset_delivery_module/pages/delivery_inspection/cost_center_form_view.dart @@ -1,4 +1,3 @@ - import 'dart:developer'; import 'package:flutter/material.dart'; @@ -103,32 +102,30 @@ class _CostCenterFormViewState extends State { backgroundColor: Theme.of(context).scaffoldBackgroundColor, appBar: DefaultAppBar( title: 'Cost Center for Item'.addTranslation, - onBackPress: () { - Navigator.pop(context); - }, + // onBackPress: () { + // Navigator.pop(context); + // }, ), body: Consumer(builder: (context, provider, child) { - return Column( - children: [ - itemDetails(context: context, itemNo: widget.itemNo, itemDescription: widget.itemDescription), - provider.isLoading - ? const CircularProgressIndicator(color: AppColor.primary10).center - : ListView.builder( + return provider.isLoading + ? const CircularProgressIndicator(color: AppColor.primary10).center + : Column( + children: [ + itemDetails(context: context, itemNo: widget.itemNo, itemDescription: widget.itemDescription), + ListView.builder( itemCount: _list.length + 1, shrinkWrap: true, - padding: EdgeInsets.all(widget.cardPadding ?? 16), + padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16, top: 8), itemBuilder: (context, index) { if (index == _list.length) { - return Visibility( - child: AppFilledButton( - label: "Add Cost Center".addTranslation, - maxWidth: true, - textColor: AppColor.textColor(context), - buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, - icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), - showIcon: true, - onPressed: _addNewEntry, - ), + return AppFilledButton( + label: "Add Cost Center".addTranslation, + maxWidth: true, + textColor: AppColor.textColor(context), + buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, + icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), + showIcon: true, + onPressed: _addNewEntry, ); } return CostCenterItemCard( @@ -142,28 +139,27 @@ class _CostCenterFormViewState extends State { ); }, ).expanded, - 8.height, - FooterActionButton.footerContainer( - context: context, - child: AppFilledButton( - buttonColor: AppColor.primary10, - label: 'Save'.addTranslation, - maxWidth: true, - onPressed: () async { - showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); - await assetDeliveryProvider.saveCostCenterToLineDeliveryInspection(tableItemId: widget.tableItemId, lineId: widget.lineId, list: _list).then((status) async { - Navigator.pop(context); - if (status) { - Navigator.pop(context); - assetDeliveryProvider.getDeliveryLinesListById( - itemId: widget.tableItemId, - ); - } - }); - }), - ), - ], - ); + FooterActionButton.footerContainer( + context: context, + child: AppFilledButton( + buttonColor: AppColor.primary10, + label: 'Save'.addTranslation, + maxWidth: true, + onPressed: () async { + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); + await assetDeliveryProvider.saveCostCenterToLineDeliveryInspection(tableItemId: widget.tableItemId, lineId: widget.lineId, list: _list).then((status) async { + Navigator.pop(context); + if (status) { + Navigator.pop(context); + assetDeliveryProvider.getDeliveryLinesListById( + itemId: widget.tableItemId, + ); + } + }); + }), + ), + ], + ); }), ); } @@ -172,6 +168,7 @@ class _CostCenterFormViewState extends State { Widget itemDetails({required BuildContext context, String? itemNo, String? itemDescription}) { return Column( crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ Text( 'Item No'.addTranslation, @@ -197,7 +194,8 @@ Widget itemDetails({required BuildContext context, String? itemNo, String? itemD context, borderRadius: 20, padding: 12, - margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + showShadow: false, + margin: const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8), ); } @@ -293,6 +291,6 @@ class CostCenterItemCard extends StatelessWidget { ], ) ], - ).toShadowContainer(context, paddingObject: const EdgeInsets.symmetric(horizontal: 16, vertical: 12)).paddingOnly(bottom: 12); + ).toShadowContainer(context, paddingObject: const EdgeInsets.symmetric(horizontal: 12, vertical: 12)).paddingOnly(bottom: 12); } } diff --git a/lib/modules/asset_delivery_module/pages/delivery_inspection/delivery_inspection_form_view.dart b/lib/modules/asset_delivery_module/pages/delivery_inspection/delivery_inspection_form_view.dart index 40a4f61c..3ef8c0a0 100644 --- a/lib/modules/asset_delivery_module/pages/delivery_inspection/delivery_inspection_form_view.dart +++ b/lib/modules/asset_delivery_module/pages/delivery_inspection/delivery_inspection_form_view.dart @@ -124,29 +124,28 @@ class _DeliveryInspectionFormViewState extends State ], ).toShadowContainer(context, borderRadius: 20, padding: 12)) .expanded, - if (!viewOnly) ...[ - FooterActionButton.footerContainer( - context: context, - child: AppFilledButton(buttonColor: AppColor.primary10, label: 'Attachments'.addTranslation, maxWidth: true, onPressed: _attachmentTap), - ), - 8.height, - ], FooterActionButton.footerContainer( context: context, child: !viewOnly - ? Row( + ? Column( children: [ - AppFilledButton( - label: 'Cancel'.addTranslation, - maxWidth: true, - buttonColor: AppColor.background(context), - // textColor: context.isDark ? AppColor.neutral30 : Colors.white, - textColor: AppColor.red30, - showBorder: true, - onPressed: _cancelTap, - ).expanded, - 12.width, - AppFilledButton(buttonColor: AppColor.green70, label: 'Change Status'.addTranslation, maxWidth: true, onPressed: _changeStatusTap).expanded, + AppFilledButton(buttonColor: AppColor.primary10, label: 'Attachments'.addTranslation, maxWidth: true, onPressed: _attachmentTap), + 16.height, + Row( + children: [ + AppFilledButton( + label: 'Cancel'.addTranslation, + maxWidth: true, + buttonColor: AppColor.background(context), + // textColor: context.isDark ? AppColor.neutral30 : Colors.white, + textColor: AppColor.red30, + showBorder: true, + onPressed: _cancelTap, + ).expanded, + 12.width, + AppFilledButton(buttonColor: AppColor.green70, label: 'Change Status'.addTranslation, maxWidth: true, onPressed: _changeStatusTap).expanded, + ], + ), ], ) : AppFilledButton(buttonColor: AppColor.primary10, label: 'Next'.addTranslation, maxWidth: true, onPressed: _nextTap), diff --git a/lib/modules/asset_delivery_module/pages/end_user_acceptance/end_user_cost_center_list_view.dart b/lib/modules/asset_delivery_module/pages/end_user_acceptance/end_user_cost_center_list_view.dart index 3711f237..5accb0ae 100644 --- a/lib/modules/asset_delivery_module/pages/end_user_acceptance/end_user_cost_center_list_view.dart +++ b/lib/modules/asset_delivery_module/pages/end_user_acceptance/end_user_cost_center_list_view.dart @@ -83,28 +83,28 @@ class _EndUserCostCenterLIstViewState extends State { children: [ //Refactor this SingleChildScrollView(padding: const EdgeInsets.all(16), child: linesList(context).toShadowContainer(context, borderRadius: 20, padding: 12)).expanded, - if (!viewOnly) ...[ - FooterActionButton.footerContainer( - context: context, - child: AppFilledButton(buttonColor: AppColor.primary10, label: 'Attachments'.addTranslation, maxWidth: true, onPressed: _attachmentTap), - ), - 8.height, - ], + !viewOnly ? FooterActionButton.footerContainer( context: context, - child: Row( + child: Column( children: [ - AppFilledButton( - label: 'Cancel'.addTranslation, - maxWidth: true, - buttonColor: AppColor.background(context), - textColor: AppColor.red30, - showBorder: true, - onPressed: _cancelTap, - ).expanded, - 12.width, - AppFilledButton(buttonColor: AppColor.green70, label: 'Change Status'.addTranslation, maxWidth: true, onPressed: _changeStatusTap).expanded, + AppFilledButton(buttonColor: AppColor.primary10, label: 'Attachments'.addTranslation, maxWidth: true, onPressed: _attachmentTap), + 16.height, + Row( + children: [ + AppFilledButton( + label: 'Cancel'.addTranslation, + maxWidth: true, + buttonColor: AppColor.background(context), + textColor: AppColor.red30, + showBorder: true, + onPressed: _cancelTap, + ).expanded, + 12.width, + AppFilledButton(buttonColor: AppColor.green70, label: 'Change Status'.addTranslation, maxWidth: true, onPressed: _changeStatusTap).expanded, + ], + ), ], )) : const SizedBox(), diff --git a/lib/modules/asset_delivery_module/pages/technical_inpection/technical_inspection_lines_list_view.dart b/lib/modules/asset_delivery_module/pages/technical_inpection/technical_inspection_lines_list_view.dart index 61e52c87..11105480 100644 --- a/lib/modules/asset_delivery_module/pages/technical_inpection/technical_inspection_lines_list_view.dart +++ b/lib/modules/asset_delivery_module/pages/technical_inpection/technical_inspection_lines_list_view.dart @@ -84,89 +84,86 @@ class _TechnicalInspectionLinesListViewState extends State 8.height, + itemBuilder: (context, index) { + if (index == 0) { + return Text( + "Lines", + style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10), + ); + } + + final DeliveryLineModel model = technicalInspectionLinesList[index - 1]; + return AssetDeliveryLineCard( + deliveryLineModel: model, + isViewOnly: viewOnly, + isTechnical: true, + editPress: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => UpdateTechnicalInspectionLinesView( + requestModel: widget.requestModel, + deliveryTableModel: widget.deliveryTableModel, + deliveryLineModel: model, + ), + ), + ); + }, + ); + }, + ).toShadowContainer(context, borderRadius: 20, padding: 12), + ], + ), + ).expanded, + FooterActionButton.footerContainer( + context: context, + child: !viewOnly + ? Column( + children: [ + AppFilledButton(buttonColor: AppColor.primary10, label: 'Attachments'.addTranslation, maxWidth: true, onPressed: _attachmentTap), + 16.height, + Row( + children: [ + AppFilledButton( + label: 'Cancel'.addTranslation, + maxWidth: true, + buttonColor: AppColor.background(context), + // textColor: context.isDark ? AppColor.neutral30 : Colors.white, + textColor: AppColor.red30, + showBorder: true, + onPressed: _cancelTap, + ).expanded, + 12.width, + AppFilledButton(buttonColor: AppColor.green70, label: 'Change Status'.addTranslation, maxWidth: true, onPressed: _changeStatusTap).expanded, + ], + ), + ], + ) + : AppFilledButton(buttonColor: AppColor.primary10, label: 'Next'.addTranslation, maxWidth: true, onPressed: _nextTap), + ), + ], + ), ), ); } - Widget linesList(BuildContext context) { - if (isLoading) { - return SizedBox.expand( - child: const CircularProgressIndicator(color: AppColor.primary10).center, - ); - } - - if (technicalInspectionLinesList.isEmpty) { - return const NoDataFound().center; - } - - return ListView.separated( - padding: const EdgeInsets.all(16), - itemCount: technicalInspectionLinesList.length + 1, // +1 for the header - separatorBuilder: (_, __) => 8.height, - itemBuilder: (context, index) { - if (index == 0) { - return Text( - "Lines", - style: AppTextStyles.heading6.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10), - ); - } - - final DeliveryLineModel model = technicalInspectionLinesList[index - 1]; - return AssetDeliveryLineCard( - deliveryLineModel: model, - isViewOnly: viewOnly, - isTechnical: true, - editPress: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => UpdateTechnicalInspectionLinesView( - requestModel: widget.requestModel, - deliveryTableModel: widget.deliveryTableModel, - deliveryLineModel: model, - ), - ), - ); - }, - ); - }, - ).toShadowContainer(context, borderRadius: 20, padding: 12); - } - //May be need to show data. Widget inspectionDetails() { return Column(