From 5088f4f275ea41b376f22260d7d4cdf72145fab0 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Tue, 8 Jul 2025 15:31:01 +0530 Subject: [PATCH] FIX_EMPCODE_RESET_CLAIMS --- lib/hrDashboard.dart | 204 ++++++++++++++++++--------------------- lib/hrPolicyDetails.dart | 9 +- 2 files changed, 98 insertions(+), 115 deletions(-) diff --git a/lib/hrDashboard.dart b/lib/hrDashboard.dart index 07f628b..0dc6515 100755 --- a/lib/hrDashboard.dart +++ b/lib/hrDashboard.dart @@ -42,6 +42,9 @@ class _hrDashboardState extends State late TabController _tabController; bool isLoading = false; int isHrcode = 0; + + String? enrollToken = ''; + String? _postToken = ''; late String _token; dynamic getPolicyNo; // bool _isLoading = false; @@ -101,11 +104,11 @@ class _hrDashboardState extends State Future _loadToken() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); - final _postToken = prefs.getString('_postToken'); - final enrollToken = prefs.getString('enrollToken'); + _postToken = prefs.getString('_postToken'); + enrollToken = prefs.getString('enrollToken'); - if (enrollToken != null && enrollToken.isNotEmpty) { - Map? decodedToken = Jwt.parseJwt(enrollToken); + if (enrollToken != null && enrollToken!.isNotEmpty) { + Map? decodedToken = Jwt.parseJwt(enrollToken!); enrollmentClient_id = decodedToken['client_id'].toString(); enrollmentEmpClientBranchId = prefs.getString('enrollmentEmpClientBranchId'); @@ -129,39 +132,14 @@ class _hrDashboardState extends State }); print("getCardArrays.length = ${getCardArrays.length}"); - tabViews.add( - PreEnrollment( - enrollmentClientId: enrollmentClient_id, - enrollmentClientBranchId: enrollmentEmpClientBranchId, - enrollmentHrId: enrollmentHrId, - enrollToken: enrollToken, - ), - // SizedBox( - // height: 400, - // child: Card( - // elevation: 5, - // color: Colors.white, - // child: SizedBox( - // height: 100, - // child: GridView.builder( - // itemCount: getCardArrays.length, - // gridDelegate: - // const SliverGridDelegateWithFixedCrossAxisCount( - // crossAxisCount: 4, - // crossAxisSpacing: 16, - // mainAxisSpacing: 0, - // childAspectRatio: 2, - // ), - // itemBuilder: (context, index) { - // print("tabIndc- $index"); - // print("getCardArraystabIndc- $getCardArrays[index]"); - // return buildPolicyCard(getCardArrays[index]); - // }, - // ), - // ), - // ), - // ), - ); + // tabViews.add( + // PreEnrollment( + // enrollmentClientId: enrollmentClient_id, + // enrollmentClientBranchId: enrollmentEmpClientBranchId, + // enrollmentHrId: enrollmentHrId, + // enrollToken: enrollToken, + // ), + // ); } } @@ -176,8 +154,8 @@ class _hrDashboardState extends State enrollmentHrId, enrollToken); } - if (_postToken != null && _postToken.isNotEmpty) { - Map? postdecodedToken = Jwt.parseJwt(_postToken); + if (_postToken != null && _postToken!.isNotEmpty) { + Map? postdecodedToken = Jwt.parseJwt(_postToken!); empClientId = postdecodedToken['client_id'].toString(); empClientBranchId = prefs.getString('empClientBranchId'); @@ -208,14 +186,14 @@ class _hrDashboardState extends State 'icon': Icons.verified_user, 'label': 'Active Policies', }); - tabViews.add( - ActivePolicies( - empClientId: empClientId, - empClientBranchId: empClientBranchId, - empHrId: empHrId, - postToken: _postToken, - ), - ); + // tabViews.add( + // ActivePolicies( + // empClientId: empClientId, + // empClientBranchId: empClientBranchId, + // empHrId: empHrId, + // postToken: _postToken, + // ), + // ); } if (empAllowed_modules.contains(3)) { print("visibleTabs.length3"); @@ -226,12 +204,12 @@ class _hrDashboardState extends State 'label': 'CD', }); - tabViews.add(CdPolicies( - empClientId: empClientId, - empClientBranchId: empClientBranchId, - empHrId: empHrId, - postToken: _postToken, - )); + // tabViews.add(CdPolicies( + // empClientId: empClientId, + // empClientBranchId: empClientBranchId, + // empHrId: empHrId, + // postToken: _postToken, + // )); } print('333'); if (empAllowed_modules.contains(4)) { @@ -239,16 +217,15 @@ class _hrDashboardState extends State 'icon': Icons.receipt_long, 'label': 'Claims', }); - tabViews.add(ClaimsPolicies( - empClientId: empClientId, - empClientBranchId: empClientBranchId, - empHrId: empHrId, - postToken: _postToken, - isHrcode: widget.isHrcode == 1 ? 1 : 0, - empCodeHrPolicy: empCodeFromHrPolcy - // empCodeHrPolicy: widget.empCodeFromHrPolicy - - )); + // tabViews.add(ClaimsPolicies( + // empClientId: empClientId, + // empClientBranchId: empClientBranchId, + // empHrId: empHrId, + // postToken: _postToken, + // isHrcode: widget.isHrcode == 1 ? 1 : 0, + // empCodeHrPolicy: empCodeFromHrPolcy + // // empCodeHrPolicy: widget.empCodeFromHrPolicy + // )); } } // getCashDepositDetails( @@ -281,16 +258,20 @@ class _hrDashboardState extends State print('222'); _tabController.addListener(() { + int newIndex = _tabController.index; + setState(() { - selectedIndex = _tabController.index; - if (widget.selectedIndex == 3) { - isHrcode = 1; - } else { - isHrcode = 0; + selectedIndex = newIndex; + if (newIndex != 3 && empCodeFromHrPolcy.isNotEmpty) { + empCodeFromHrPolcy = ''; // ✅ clear only once } - empCodeFromHrPolcy = ''; + + // selectedIndex = _tabController.index; + // empCodeFromHrPolcy = ''; + print("Process2"); print("tabIndexConti- $selectedIndex - ${_tabController.index}"); + // print("tabIndexCode11- $isHrcode "); }); }); @@ -300,6 +281,47 @@ class _hrDashboardState extends State isLoading = false; } + List getTabViews() { + return tabData.map((tab) { + final label = tab['label']; + + switch (label) { + case 'Claims': + return ClaimsPolicies( + empClientId: empClientId, + empClientBranchId: empClientBranchId, + empHrId: empHrId, + postToken: _postToken!, + isHrcode: widget.isHrcode == 1 ? 1 : 0, + empCodeHrPolicy: empCodeFromHrPolcy, + ); + case 'CD': + return CdPolicies( + empClientId: empClientId, + empClientBranchId: empClientBranchId, + empHrId: empHrId, + postToken: _postToken!, + ); + case 'Active Policies': + return ActivePolicies( + empClientId: empClientId, + empClientBranchId: empClientBranchId, + empHrId: empHrId, + postToken: _postToken!, + ); + case 'Pre Enrollment': + return PreEnrollment( + enrollmentClientId: enrollmentClient_id, + enrollmentClientBranchId: enrollmentEmpClientBranchId, + enrollmentHrId: enrollmentHrId, + enrollToken: enrollToken!, + ); + default: + return Center(child: Text('Unknown tab')); + } + }).toList(); + } + Future getClientLogoAndDetails(clintBranchId, clintID, token) async { var url = Uri.parse(Environment.apiUrl + 'getClientDetails?client_id=$clintID&client_branch_id=$clintBranchId'); @@ -568,19 +590,6 @@ class _hrDashboardState extends State controller: _tabController, isScrollable: true, labelPadding: EdgeInsets.zero, - // labelPadding: const EdgeInsets.symmetric( - // horizontal: 0, vertical: 0), - // indicator: BoxDecoration( - // color: const Color(0xFF00999E), // Selected tab background - // borderRadius: BorderRadius.circular(12), - // boxShadow: [ - // BoxShadow( - // color: Colors.black.withOpacity(0.2), - // blurRadius: 4, - // offset: const Offset(0, 2), - // ) - // ], - // ), dividerColor: Colors.transparent, indicatorColor: Colors.transparent, indicatorPadding: EdgeInsets.zero, @@ -595,25 +604,6 @@ class _hrDashboardState extends State isSelected: selectedIndex == index, ); }), - - // tabs: [ - // CustomTab( - // icon: Icons.grid_view, - // label: 'Pre Enrollment', - // isSelected: selectedIndex == 0), - // CustomTab( - // icon: Icons.verified_user, - // label: 'Active Policies', - // isSelected: selectedIndex == 1), - // CustomTab( - // icon: Icons.desktop_windows, - // label: 'CD', - // isSelected: selectedIndex == 2), - // CustomTab( - // icon: Icons.receipt_long, - // label: 'Claims', - // isSelected: selectedIndex == 3), - // ], ), ], ), @@ -625,19 +615,11 @@ class _hrDashboardState extends State padding: const EdgeInsets.symmetric(horizontal: 5), child: TabBarView( controller: _tabController, - children: tabViews, + children: getTabViews(), + // children: tabViews, ), ), ), - - // SizedBox( - // height: MediaQuery.of(context).size.height * 0.55, - // // height: 500, // Adjust height based on your layout - // child: TabBarView( - // controller: _tabController, - // children: tabViews, - // ), - // ), ], ), ), diff --git a/lib/hrPolicyDetails.dart b/lib/hrPolicyDetails.dart index a276c23..47851a8 100755 --- a/lib/hrPolicyDetails.dart +++ b/lib/hrPolicyDetails.dart @@ -60,6 +60,7 @@ class hrPolicyDetails extends StatefulWidget { class _HrPolicyDetailsState extends State with TickerProviderStateMixin { Uint8List? fileBytes; + String empCodeFromHrPolcy = ''; late String _token; List> getEmpDependenceByClintId = []; List> getCDPolicies = []; @@ -831,10 +832,10 @@ class _HrPolicyDetailsState extends State context, MaterialPageRoute( builder: (context) => hrDashboard( - selectedIndex: 3, - empCodeFromHrPolicy: - item['emp_code']!, - isHrcode: 1), + selectedIndex: 3, + empCodeFromHrPolicy: item['emp_code']!, + isHrcode: 1, + ), ), ); });