post_enrollment_app/lib/pages/postEnrollment/profile.dart

789 lines
33 KiB
Dart
Executable File

import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:jwt_decode/jwt_decode.dart';
import 'package:nhance_app_pwa/customAppBar/customAppBar.dart';
import 'package:nhance_app_pwa/pages/postEnrollment/service/api_service.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../customAppBar/customFooter.dart';
import '../../customAppBar/responsive.dart';
import '../../customAppBar/tabs.dart';
import '../../customAppBar/toastHelper.dart';
import 'package:http/http.dart' as http;
import '../../models/platform_helper_mobile.dart'
if (dart.library.html) '../../models/platform_helper_other.dart';
import '../session/authenticationService.dart';
class profile extends StatefulWidget {
const profile({Key? key}) : super(key: key);
@override
State<profile> createState() => _profileState();
}
class _profileState extends State<profile> {
bool isLoading = false;
late ApiService apiService;
final AuthService _authService = AuthService();
int _currentIndex = 0;
bool isActive = true;
dynamic _token;
dynamic empCodeString;
dynamic empPrimaryId;
dynamic client_id;
dynamic policyList;
dynamic policyDataIsEmpty = 1;
dynamic policyHeading;
dynamic policyName;
dynamic EmployeePolicy;
List<Map<String, String>> employeeDetails = [];
dynamic argumentsData;
dynamic selfRelationship;
dynamic selfName;
dynamic selfMobile;
dynamic selfDesignation;
dynamic selfDob;
dynamic selfDoj;
dynamic selfGender;
dynamic selfEmailCorporate;
dynamic selfEmailPersonal;
dynamic selfEmpCode;
dynamic selfFamilyFloaterKey;
dynamic selfEmpStatus;
dynamic client_branch_id;
void _onTabChanged(int index) {
setState(() {
_currentIndex = index;
});
}
@override
void initState() {
super.initState();
apiService = ApiService(context); // Initialize ApiService here
_loadToken();
}
@override
void dispose() {
super.dispose();
}
Future<String> _getAppVersion() async {
try {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
print('App version: ${packageInfo.version}');
return packageInfo.version;
} catch (e) {
print('Error getting app version: $e');
return 'Unknown'; // Optional fallback
}
}
Future<void> _loadToken() async {
print('_loadToken');
final SharedPreferences prefs = await SharedPreferences.getInstance();
final String? token = prefs.getString('_postToken');
if (token != null && token.isNotEmpty) {
setState(() {
_token = token;
});
// Decode the JWT token received from the API response
Map<String, dynamic>? decodedToken = Jwt.parseJwt(token);
print(decodedToken);
client_branch_id = decodedToken['client_branch_id'];
empCodeString = prefs.getString('empCode');
print(empCodeString); // Check if emp_code is correct
empPrimaryId = prefs.getString('empPrimaryId');
client_id = prefs.getString('client_id');
print(client_id);
getSelfEmployeeProfile();
} else {
// Token is empty or null, handle accordingly (e.g., navigate to login screen)
// For now, let's navigate to the login screen
ToastHelper.showErrorToast(context, 'Session Out');
Navigator.pushReplacementNamed(context, 'login');
}
}
String convertDate(String dateString) {
DateTime date = DateTime.parse(dateString);
DateFormat formatter = DateFormat('dd MMM yyyy');
return formatter.format(date);
}
Future<void> getSelfEmployeeProfile() async {
print(getSelfEmployeeProfile);
if (client_id == null || empCodeString == null) {
return;
}
setState(() {
isLoading = true;
});
print('check 1');
final response = await apiService.getSelfEmployeeProfileDetails(
client_id!, empCodeString!, client_branch_id!);
print('check 1');
if (response['status'] == 'success') {
if (response.containsKey('data')) {
setState(() {
dynamic selfDetails = response['data'];
print(selfDetails);
selfRelationship = selfDetails['relationship'];
selfName = selfDetails['name'];
selfMobile = selfDetails['mobile'];
selfDesignation = selfDetails['designation'];
selfDob = convertDate(selfDetails['dob']);
selfDoj = convertDate(selfDetails['doj']);
selfGender = selfDetails['gender'];
selfEmailCorporate = selfDetails['email_corporate'];
selfEmailPersonal = selfDetails['email_personal'];
selfEmpCode = selfDetails['emp_code'];
selfFamilyFloaterKey = selfDetails['family_floater_key'];
// print(clientDetails);
selfEmpStatus = selfDetails['emp_status'];
isLoading = false;
});
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('selfEmpStatus', selfEmpStatus);
} else {
// Handle other status messages if needed
// ToastHelper.showErrorToast(
// context, 'API request failed with status: ${data['status']}');
print('API request failed with status: ${response['status']}');
}
} else {
print('API request failed with status: ${response['status']}');
}
}
Future<void> logout(BuildContext context) async {
// if (isMobilePlatform()) {
final SharedPreferences prefs = await SharedPreferences.getInstance();
// Get the value of the mobile_number key
String? mobileNumber = prefs.getString('empMobileNo');
String? mailID = prefs.getString('empEmailid');
final isMpinSkipped = prefs.getString('is_mpin_skipped');
// bool? biometricStatus = prefs.getBool('biometricStatus') ?? false;
// int? skipStatus = prefs.getInt('skipStatus') ?? 1;
// Clear all keys
await prefs.clear();
print('Local Storage Clear');
// html.window.localStorage.clear();
// Re-set the mobile_number key
if (isMobilePlatform()) {
if (mobileNumber != null) {
await prefs.setString('empMobileNo', mobileNumber);
// await prefs.setBool('biometricStatus', biometricStatus!);
// await prefs.setInt('skipStatus', skipStatus!);
}
if (mailID != null) {
await prefs.setString('empEmailid', mailID);
// await prefs.setBool('biometricStatus', biometricStatus!);
// await prefs.setInt('skipStatus', skipStatus!);
}
await prefs.setString('is_mpin_skipped', isMpinSkipped!);
print('isMpinSkipped $isMpinSkipped');
if (isMpinSkipped != null && isMpinSkipped == '0') {
Navigator.pushReplacementNamed(context, 'pinPage');
} else {
Navigator.pushReplacementNamed(context, 'login');
}
} else {
ToastHelper.showSuccessToast(context, 'logout');
// Navigate to login page
Navigator.pushNamed(context, 'login');
}
// } else {
// final prefs = await SharedPreferences.getInstance();
// await prefs.clear();
// Navigator.pushNamed(context, 'login');
// }
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: CustomAppBar(),
body: Stack(children: [
SingleChildScrollView(
child: Container(
padding: Responsive.isDesktop(context)
? EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width *
0.2, // 30% of screen width as horizontal padding
vertical: MediaQuery.of(context).size.height *
0.03, // 5% of screen height as vertical padding
)
: EdgeInsets.all(10),
color: Colors.white,
child: Column(children: [
if (selfName != null)
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: InkWell(
onTap: () {
Navigator.pushNamed(context, 'home');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
Icons
.chevron_left, // Replace with your desired icon
color: Color(0xFF000000),
size: 30,
),
],
),
),
),
Expanded(
flex: 11,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Adjust space between icon and text
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
selfName ?? '',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Color(0xFF000000),
),
),
],
),
],
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.topLeft,
padding: EdgeInsets.only(top: 10, left: 10),
child: Text(''))),
Expanded(
flex: Responsive.isDesktop(context) ? 12 : 11,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Adjust space between icon and text
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RichText(
text: TextSpan(
children: [
TextSpan(
text: 'Emp: Id - ',
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight
.w600, // Bold style for "Emp: Id -"
color: Color(0xFF000000),
),
),
TextSpan(
text: selfEmpCode ?? '',
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight
.w400, // Normal style for the ID number
color: Color(0xFF747474),
),
),
],
),
),
],
),
],
),
)
],
),
// Add more rows as needed
],
),
),
SizedBox(height: 15),
if (selfName != null)
Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10), // Set the border radius here
),
child: Column(children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
),
padding: Responsive.isDesktop(context)
? EdgeInsets.all(30)
: EdgeInsets.all(15),
child: Column(children: [
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color(0xFFBDBDBD),
width: 1.0, // Adjust the width as needed
),
),
),
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 15, bottom: 15, left: 15, right: 15)
: EdgeInsets.only(top: 10, bottom: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerLeft,
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
right: 10)
: EdgeInsets.only(
top: 7,
bottom: 7,
left: 7,
right: 7),
child: Text(
'Gender',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 14,
color: Color(0xFF777777),
fontWeight: FontWeight.w500,
),
),
),
),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Text(
selfGender == 'M' ? 'Male' : 'Female',
textAlign: TextAlign.end,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 16,
color: Color(0xFF2D5A82),
fontWeight: FontWeight.w400,
),
),
),
),
],
)),
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color(0xFFBDBDBD),
width: 1.0, // Adjust the width as needed
),
),
),
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 15, bottom: 15, left: 15, right: 15)
: EdgeInsets.only(top: 10, bottom: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerLeft,
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
right: 10)
: EdgeInsets.only(
top: 7,
bottom: 7,
left: 7,
right: 7),
child: Text(
'Date of birth',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 14,
color: Color(0xFF777777),
fontWeight: FontWeight.w500,
),
),
),
),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Text(
selfDob ?? '',
textAlign: TextAlign.end,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 16,
color: Color(0xFF2D5A82),
fontWeight: FontWeight.w400,
),
),
),
),
],
)),
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color(0xFFBDBDBD),
width: 1.0, // Adjust the width as needed
),
),
),
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 15, bottom: 15, left: 15, right: 15)
: EdgeInsets.only(top: 10, bottom: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerLeft,
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
right: 10)
: EdgeInsets.only(
top: 7,
bottom: 7,
left: 7,
right: 7),
child: Text(
'Phone No',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 14,
color: Color(0xFF777777),
fontWeight: FontWeight.w500,
),
),
),
),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Text(
selfMobile ?? '',
textAlign: TextAlign.end,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 16,
color: Color(0xFF2D5A82),
fontWeight: FontWeight.w400,
),
),
),
),
],
)),
Container(
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 15, bottom: 15, left: 15, right: 15)
: EdgeInsets.only(top: 10, bottom: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerLeft,
padding: Responsive.isDesktop(context)
? EdgeInsets.only(
top: 10,
bottom: 10,
left: 10,
right: 10)
: EdgeInsets.only(
top: 7,
bottom: 7,
left: 7,
right: 7),
child: Text(
'Email id',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 14,
color: Color(0xFF777777),
fontWeight: FontWeight.w500,
),
),
),
),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Text(
selfEmailCorporate ?? '',
textAlign: TextAlign.end,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context)
? 16
: 16,
color: Color(0xFF2D5A82),
fontWeight: FontWeight.w400,
),
),
),
),
],
)),
]),
)
])),
SizedBox(height: 12),
if(Responsive.isMobile(context))
Container(
child: Row(
children: [
Expanded(
flex: 12,
child: Container(
width: 150,
// height: Responsive.isDesktop(context) ? 150 : 100,
alignment: Alignment.center,
child: ElevatedButton(
onPressed: () {
Navigator.pushReplacementNamed(
context, 'changePin');
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Adjust space between icon and text
Text(
'Change Pin',
style: GoogleFonts.poppins(
color: Color(0xFFE26728)),
),
],
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
side: BorderSide(color: Color(0xFFE26728)),
),
),
),
)),
],
),
),
SizedBox(height: 10),
Container(
child: Row(
children: [
Expanded(
flex: 12,
child: Container(
width: 150,
// height: Responsive.isDesktop(context) ? 150 : 100,
alignment: Alignment.center,
child: ElevatedButton(
onPressed: () {
logout(context);
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.logout,
color: Color(0xFFE26728),
),
SizedBox(
width:
8), // Adjust space between icon and text
Text(
'Logout',
style: GoogleFonts.poppins(
color: Color(0xFFE26728)),
),
],
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
side: BorderSide(color: Color(0xFFE26728)),
),
),
),
)),
],
),
),
SizedBox(height: Responsive.isDesktop(context) ? 40 : 10),
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: FutureBuilder<String>(
future: _getAppVersion(), // Function to get the app version
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Text(
'Loading version...',
style: GoogleFonts.poppins(
fontSize: 12, color: Colors.grey),
textAlign: TextAlign.center,
);
} else if (snapshot.hasError) {
return Text(
'Error fetching version',
style: GoogleFonts.poppins(
fontSize: 12, color: Colors.red),
textAlign: TextAlign.center,
);
} else {
return Text(
'Version ${snapshot.data}',
style: GoogleFonts.poppins(
fontSize: 12, color: Colors.grey),
textAlign: TextAlign.center,
);
}
},
),
),
]),
)),
if (isLoading)
Container(
color: Color(0x98FFFCE5), // Semi-transparent background
child: Center(
child: // Your GIF loader widget
Image.asset(
height: 60,
width: 60,
'assets/nhance-loader.gif'), // Adjust path to your GIF loader
),
),
if (Responsive.isDesktop(context))
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity, // Make the footer full width
child: CustomFooter(),
),
),
]),
// floatingActionButton: Responsive.isDesktop(context)
// ? null
// : FloatingActionButton(
// onPressed: () {
// Navigator.pushNamed(context, 'chatbot');
// },
// child: Icon(Icons.chat),
// ),
floatingActionButtonLocation: Responsive.isDesktop(context)
? null
: FloatingActionButtonLocation.miniEndFloat,
bottomNavigationBar: Responsive.isDesktop(context)
? null
: CustomBottomNavigationBar(
onTabChanged: (index) {
if (index == 0) {
Navigator.pushNamed(context, 'home');
} else if (index == 1) {
Navigator.pushNamed(context, 'claims');
} else if (index == 2) {
Navigator.pushNamed(context, 'profile');
} else if (index == 3) {
Navigator.pushNamed(context, 'help');
} else if (index == 4) {
Navigator.pushNamed(context, 'wellness');
}
},
icons: [
Icons.home_outlined,
Icons.sticky_note_2_outlined,
Icons.person_outline_outlined,
Icons.headset_mic_outlined,
Icons.health_and_safety_outlined,
],
labels: [
"Home",
"Claim",
"Profile",
"Help",
"Wellness",
],
initialIndex: 2, // Initial index of the bottom navigation bar
),
);
}
}