From 951dd22eccebe002358a90b352468772c1615ae8 Mon Sep 17 00:00:00 2001 From: Manish Date: Wed, 26 Nov 2025 15:20:20 +0530 Subject: [PATCH] bug fixed for 1776, 1775, 1736, 1626 --- .../attendance_screen_controller.dart | 2 +- .../payment_request_detail_controller.dart | 16 ++----- .../attendance/attendence_action_button.dart | 10 ++-- lib/view/Attendence/attendance_screen.dart | 47 ++++++++++--------- .../payment_request_detail_screen.dart | 25 +++++----- 5 files changed, 46 insertions(+), 54 deletions(-) diff --git a/lib/controller/attendance/attendance_screen_controller.dart b/lib/controller/attendance/attendance_screen_controller.dart index 5aebd4d..91b6c8f 100644 --- a/lib/controller/attendance/attendance_screen_controller.dart +++ b/lib/controller/attendance/attendance_screen_controller.dart @@ -376,7 +376,7 @@ class AttendanceController extends GetxController { logSafe( "Project data fetched for project ID: $projectId, tab: $selectedTab"); - update(); + update(); } // ------------------ UI Interaction ------------------ diff --git a/lib/controller/finance/payment_request_detail_controller.dart b/lib/controller/finance/payment_request_detail_controller.dart index d790eb4..c0252a6 100644 --- a/lib/controller/finance/payment_request_detail_controller.dart +++ b/lib/controller/finance/payment_request_detail_controller.dart @@ -281,6 +281,7 @@ class PaymentRequestDetailController extends GetxController { String? tdsPercentage, }) async { isLoading.value = true; + try { final success = await ApiService.updateExpensePaymentRequestStatusApi( paymentRequestId: _requestId, @@ -295,25 +296,14 @@ class PaymentRequestDetailController extends GetxController { ); if (success) { - showAppSnackbar( - title: 'Success', - message: 'Payment submitted successfully', - type: SnackbarType.success); + // Controller refreshes the data but does not show snackbars. await fetchPaymentRequestDetail(); paymentRequestController.fetchPaymentRequests(); - } else { - showAppSnackbar( - title: 'Error', - message: 'Failed to update status. Please try again.', - type: SnackbarType.error); } return success; } catch (e) { - showAppSnackbar( - title: 'Error', - message: 'Something went wrong: $e', - type: SnackbarType.error); + // Controller returns false on error; UI will show the snackbar. return false; } finally { isLoading.value = false; diff --git a/lib/model/attendance/attendence_action_button.dart b/lib/model/attendance/attendence_action_button.dart index fefc312..c65e81b 100644 --- a/lib/model/attendance/attendence_action_button.dart +++ b/lib/model/attendance/attendence_action_button.dart @@ -23,6 +23,7 @@ class AttendanceActionButton extends StatefulWidget { } class _AttendanceActionButtonState extends State { + final attendanceController = Get.find(); late final String uniqueLogKey; @override @@ -189,12 +190,9 @@ class _AttendanceActionButtonState extends State { controller.uploadingStates[uniqueLogKey]?.value = false; - if (success) { - await controller.fetchTodaysAttendance(selectedProjectId); - await controller.fetchAttendanceLogs(selectedProjectId); - await controller.fetchRegularizationLogs(selectedProjectId); - await controller.fetchProjectData(selectedProjectId); - controller.update(); + if (selectedProjectId.isNotEmpty) { + await attendanceController.fetchProjectData(selectedProjectId); + attendanceController.update(['attendance_dashboard_controller']); } } diff --git a/lib/view/Attendence/attendance_screen.dart b/lib/view/Attendence/attendance_screen.dart index b782fdb..d617654 100644 --- a/lib/view/Attendence/attendance_screen.dart +++ b/lib/view/Attendence/attendance_screen.dart @@ -33,13 +33,11 @@ class _AttendanceScreenState extends State with UIMixin { void initState() { super.initState(); - WidgetsBinding.instance.addPostFrameCallback((_) { - // 🔁 Listen for project changes - ever(projectController.selectedProjectId, (projectId) async { - if (projectId.isNotEmpty) await _loadData(projectId); - }); + ever(projectController.selectedProjectId, (projectId) async { + if (projectId.isNotEmpty) await _loadData(projectId); + }); - // 🚀 Load initial data only once the screen is shown + WidgetsBinding.instance.addPostFrameCallback((_) { final projectId = projectController.selectedProjectId.value; if (projectId.isNotEmpty) _loadData(projectId); }); @@ -49,7 +47,7 @@ class _AttendanceScreenState extends State with UIMixin { try { attendanceController.selectedTab = 'todaysAttendance'; await attendanceController.loadAttendanceData(projectId); - attendanceController.update(['attendance_dashboard_controller']); + // attendanceController.update(['attendance_dashboard_controller']); } catch (e) { debugPrint("Error loading data: $e"); } @@ -375,26 +373,29 @@ class _AttendanceScreenState extends State with UIMixin { return MyRefreshIndicator( onRefresh: _refreshData, - child: SingleChildScrollView( - physics: const AlwaysScrollableScrollPhysics(), - padding: MySpacing.zero, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - MySpacing.height(flexSpacing), - _buildFilterSearchRow(), - MyFlex( + child: Builder( + builder: (context) { + return SingleChildScrollView( + physics: const AlwaysScrollableScrollPhysics(), + padding: MySpacing.zero, + child: Column( children: [ - MyFlexItem( - sizes: 'lg-12 md-12 sm-12', - child: noProjectSelected - ? _buildNoProjectWidget() - : _buildSelectedTabContent(), + MySpacing.height(flexSpacing), + _buildFilterSearchRow(), + MyFlex( + children: [ + MyFlexItem( + sizes: 'lg-12 md-12 sm-12', + child: noProjectSelected + ? _buildNoProjectWidget() + : _buildSelectedTabContent(), + ), + ], ), ], ), - ], - ), + ); + }, ), ); }, diff --git a/lib/view/finance/payment_request_detail_screen.dart b/lib/view/finance/payment_request_detail_screen.dart index a00aefd..84fc219 100644 --- a/lib/view/finance/payment_request_detail_screen.dart +++ b/lib/view/finance/payment_request_detail_screen.dart @@ -191,11 +191,9 @@ class _PaymentRequestDetailScreenState extends State return const SizedBox.shrink(); } - if (!_checkedPermission) { + if (!_checkedPermission && request != null && employeeInfo != null) { _checkedPermission = true; - WidgetsBinding.instance.addPostFrameCallback((_) { - _checkPermissionToSubmit(request); - }); + _checkPermissionToSubmit(request); } const reimbursementStatusId = '61578360-3a49-4c34-8604-7b35a3787b95'; @@ -269,15 +267,20 @@ class _PaymentRequestDetailScreenState extends State comment: comment.trim(), ); + if (!success) { + showAppSnackbar( + title: 'Error', + message: 'Failed to update status', + type: SnackbarType.error, + ); + return; + } + showAppSnackbar( - title: success ? 'Success' : 'Error', - message: success - ? 'Status updated successfully' - : 'Failed to update status', - type: success ? SnackbarType.success : SnackbarType.error, + title: 'Success', + message: 'Status updated successfully', + type: SnackbarType.success, ); - - if (success) await controller.fetchPaymentRequestDetail(); } }, child: MyText.bodySmall(