From f6d41327d1eb44e241a31b799eb2b52d80ac4748 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Thu, 10 Jul 2025 18:12:44 +0530 Subject: [PATCH] FIX_TAB_HIDE/SHOW --- lib/claimshistory.dart | 4 +- lib/hrDashboard.dart | 27 +++--- lib/hrPolicyDetails.dart | 178 ++++++++++++++++++++++++--------------- 3 files changed, 129 insertions(+), 80 deletions(-) diff --git a/lib/claimshistory.dart b/lib/claimshistory.dart index 9393d31..044c510 100644 --- a/lib/claimshistory.dart +++ b/lib/claimshistory.dart @@ -150,7 +150,7 @@ class _ClaimHistoryPopupState extends State { border: Border.all(color: Color(0xFFBCBCBC)), borderRadius: BorderRadius.circular(6), ), - child: Icon( + child: const Icon( Icons.close, size: 25, color: Color(0xFFBCBCBC), @@ -166,7 +166,7 @@ class _ClaimHistoryPopupState extends State { decoration: BoxDecoration( color: Color(0xFFFFFFFF), // White background borderRadius: BorderRadius.circular(12), - boxShadow: [ + boxShadow: const [ BoxShadow( color: Color(0xFFEBEBEB), // Shadow color blurRadius: 14, // How soft the shadow is diff --git a/lib/hrDashboard.dart b/lib/hrDashboard.dart index 5e43921..9d9b073 100755 --- a/lib/hrDashboard.dart +++ b/lib/hrDashboard.dart @@ -169,14 +169,14 @@ class _hrDashboardState extends State print('allowed_modules'); String? modulesString = prefs.getString('empAllowed_modules'); - String? enrollmodulesString = - prefs.getString('enrollmentAllowed_modules'); - if (modulesString != null || enrollmodulesString != null) { - empAllowed_modules = jsonDecode(modulesString!); - enrollmentAllowed_modules = jsonDecode(enrollmodulesString!); + // String? enrollmodulesString = + // prefs.getString('enrollmentAllowed_modules'); + if (modulesString != null) { + empAllowed_modules = jsonDecode(modulesString); + // enrollmentAllowed_modules = jsonDecode(enrollmodulesString!); print("empAllowed_modules - $empAllowed_modules"); // [2, 3, 4] - print( - "enrollmentAllowed_modules - $enrollmentAllowed_modules"); // [2, 3, 4] + // print( + // "enrollmentAllowed_modules - $enrollmentAllowed_modules"); // [2, 3, 4] if (empAllowed_modules.contains(2)) { print("visibleTabs.length2"); @@ -215,7 +215,7 @@ class _hrDashboardState extends State if (empAllowed_modules.contains(4)) { tabData.add({ 'icon': Icons.receipt_long, - 'label': 'Claims', + 'label': 'Claims', // Label Name Integrated with code (dont change) }); // tabViews.add(ClaimsPolicies( // empClientId: empClientId, @@ -246,9 +246,15 @@ class _hrDashboardState extends State print('111'); if (widget.selectedIndex == 3) { print("Process1"); - _tabController.index = 3; + print("ProcessTAb - $tabData"); + + final claimsIndex = tabData.indexWhere((tab) => tab['label'] == 'Claims'); + print('Claims tab index: $claimsIndex'); + _tabController.index = claimsIndex; + // _tabController.index = 3; setState(() { - selectedIndex = 3; + selectedIndex = claimsIndex; + // selectedIndex = 3; isHrcode = 1; empCodeFromHrPolcy = widget.empCodeFromHrPolicy; }); @@ -747,6 +753,7 @@ class CustomTab extends StatelessWidget { @override Widget build(BuildContext context) { + print("isSelected - $isSelected"); return Tab( child: Container( // margin: const EdgeInsets.symmetric(horizontal: 6), diff --git a/lib/hrPolicyDetails.dart b/lib/hrPolicyDetails.dart index 7f756d2..32f6079 100755 --- a/lib/hrPolicyDetails.dart +++ b/lib/hrPolicyDetails.dart @@ -61,6 +61,7 @@ class _HrPolicyDetailsState extends State with TickerProviderStateMixin { Uint8List? fileBytes; String empCodeFromHrPolcy = ''; + bool hasAnyEcardLink = false; late String _token; List> getEmpDependenceByClintId = []; List> getCDPolicies = []; @@ -79,6 +80,9 @@ class _HrPolicyDetailsState extends State dynamic clientPolicyId; dynamic clientId; dynamic empRefId; + String? modulesString; + final storeModuleId = 4; + bool hasModule = false; int inceptionType = 0; TextEditingController searchController = TextEditingController(); late ApiService apiService; @@ -99,6 +103,8 @@ class _HrPolicyDetailsState extends State apiService = ApiService(context); // Initialize ApiService here getCDPoliciesDetails(); print("_PreEnrollmentState 1"); + + print('allowed_modules'); } Future getCDPoliciesDetails() async { @@ -109,6 +115,24 @@ class _HrPolicyDetailsState extends State try { print('10'); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + modulesString = prefs.getString('empAllowed_modules'); + // modulesString = "[2,3]"; + + print("empmodulesString - $modulesString"); + + if (modulesString != null && modulesString!.trim().isNotEmpty) { + final List? moduleList = modulesString + ?.replaceAll('[', '') + .replaceAll(']', '') + .split(',') + .map((e) => int.tryParse(e.trim()) ?? -1) // convert to int safely + .where((id) => id != -1) // filter out invalid + .toList(); + + hasModule = moduleList!.contains(storeModuleId); + } + final response = widget.TokenType == "post" ? await apiService.getEmployeeAndDependenceToApi(widget.ClientId, widget.ClientPoliyId, widget.clientBranchId, widget.Token) @@ -536,6 +560,18 @@ class _HrPolicyDetailsState extends State } Widget _buildCDDataTable(BuildContext context) { + if (_paginatedData.isNotEmpty) { + hasAnyEcardLink = _paginatedData.any( + (item) => item['ecard_download_link'] != null, + ); + + if (widget.TokenType == "post" && hasModule) { + print("paginatTtt - $_paginatedData"); + + print("📥 Any e-card link present: $hasAnyEcardLink"); + } + } + if (filteredData.isEmpty) { return SizedBox( // height: 50, @@ -643,17 +679,18 @@ class _HrPolicyDetailsState extends State ), ), ), - Expanded( - flex: 3, - child: Text( - 'Action', - textAlign: TextAlign.center, - style: GoogleFonts.poppins( - color: Colors.black, - fontWeight: FontWeight.w600, + if (widget.TokenType != "pre" && (hasAnyEcardLink || hasModule)) + Expanded( + flex: 3, + child: Text( + 'Action', + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + color: Colors.black, + fontWeight: FontWeight.w600, + ), ), ), - ), ], ), ), @@ -796,72 +833,77 @@ class _HrPolicyDetailsState extends State ), ), ), - Expanded( - flex: 3, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - if (item['ecard_download_link'] != null) - GestureDetector( - onTap: () { - _launchURL(item['ecard_download_link']); - }, - child: Container( - height: 35, - width: 35, - decoration: BoxDecoration( - color: Color(0xFFE6F5F6), - borderRadius: BorderRadius.circular(8), - ), - child: Padding( - padding: EdgeInsets.all( - 6), // You can adjust this value - child: Image.asset( - 'assets/credit_card.png', - fit: BoxFit.contain, + if (widget.TokenType != "pre" && + (hasAnyEcardLink || hasModule)) + Expanded( + flex: 3, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (item['ecard_download_link'] != null) + GestureDetector( + onTap: () { + _launchURL(item['ecard_download_link']); + }, + child: Container( + height: 35, + width: 35, + decoration: BoxDecoration( + color: Color(0xFFE6F5F6), + borderRadius: BorderRadius.circular(8), ), - ), - ), - ), - SizedBox( - width: 10, - ), - GestureDetector( - onTap: () { - setState(() { - print("policytabdata - ${item['emp_code']!}"); - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => hrDashboard( - selectedIndex: 3, - empCodeFromHrPolicy: item['emp_code']!, - isHrcode: 1, + child: Padding( + padding: EdgeInsets.all( + 6), // You can adjust this value + child: Image.asset( + 'assets/credit_card.png', + fit: BoxFit.contain, ), ), - ); - }); - }, - child: Container( - height: 35, - width: 35, - decoration: BoxDecoration( - color: Color(0xFFE6F5F6), - borderRadius: BorderRadius.circular(8), - ), - child: Padding( - padding: EdgeInsets.all( - 6), // You can adjust this value - child: Image.asset( - 'assets/claim.png', - fit: BoxFit.contain, ), ), + SizedBox( + width: 10, ), - ), - ], + if (widget.TokenType == "post" && hasModule) + GestureDetector( + onTap: () { + setState(() { + print( + "policytabdata - ${item['emp_code']!}"); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => hrDashboard( + selectedIndex: 3, + empCodeFromHrPolicy: + item['emp_code']!, + isHrcode: 1, + ), + ), + ); + }); + }, + child: Container( + height: 35, + width: 35, + decoration: BoxDecoration( + color: Color(0xFFE6F5F6), + borderRadius: BorderRadius.circular(8), + ), + child: Padding( + padding: EdgeInsets.all( + 6), // You can adjust this value + child: Image.asset( + 'assets/claim.png', + fit: BoxFit.contain, + ), + ), + ), + ), + ], + ), ), - ), ], ), );