From 44e94898b7155fcfe79fd6d9833a42ddf098351c Mon Sep 17 00:00:00 2001 From: Venba Date: Thu, 4 Jul 2024 15:02:22 +0530 Subject: [PATCH] CHANGE_ --- .env | 2 +- .env.development | 2 +- .env.production | 2 +- .env.test | 2 +- android/app/src/main/AndroidManifest.xml | 1 + build_web_dev.sh | 31 +- build_web_production.sh | 39 +- build_web_test.sh | 39 +- lib/customAppBar/customAppBar.dart | 20 +- lib/customAppBar/enrollmentAppBar.dart | 101 + lib/main.dart | 32 +- lib/models/environment.dart | 41 +- lib/pages/claimtracklist.dart | 512 -- lib/pages/enrollment/addons.dart | 4577 +++++++++++++++++ lib/pages/enrollment/empDetails.dart | 2297 +++++++++ lib/pages/enrollment/empReview.dart | 2518 +++++++++ lib/pages/enrollment/oldPolicy.dart | 388 ++ lib/pages/enrollment/service/api_service.dart | 502 ++ lib/pages/help.dart | 460 -- lib/pages/postEnrollment/chatbot.dart | 235 + .../{ => postEnrollment}/claimprocess.dart | 24 +- lib/pages/{ => postEnrollment}/claims.dart | 369 +- lib/pages/postEnrollment/claimtracklist.dart | 631 +++ lib/pages/postEnrollment/data.dart | 192 + .../generalexclusionsdeductibles.dart | 26 +- lib/pages/postEnrollment/help.dart | 1070 ++++ lib/pages/{ => postEnrollment}/home.dart | 141 +- .../{ => postEnrollment}/planclaimsform.dart | 276 +- lib/pages/{ => postEnrollment}/policies.dart | 60 +- .../{ => postEnrollment}/privacypolicy.dart | 11 +- lib/pages/{ => postEnrollment}/profile.dart | 74 +- .../postEnrollment}/service/api_service.dart | 40 +- .../{ => postEnrollment}/termsofuse.dart | 11 +- lib/pages/verify.dart | 28 +- macos/Flutter/GeneratedPluginRegistrant.swift | 4 + pubspec.yaml | 4 + test/widget_test.dart | 2 +- web/index.html | 3 +- 38 files changed, 13182 insertions(+), 1585 deletions(-) create mode 100644 lib/customAppBar/enrollmentAppBar.dart delete mode 100644 lib/pages/claimtracklist.dart create mode 100644 lib/pages/enrollment/addons.dart create mode 100644 lib/pages/enrollment/empDetails.dart create mode 100644 lib/pages/enrollment/empReview.dart create mode 100644 lib/pages/enrollment/oldPolicy.dart create mode 100644 lib/pages/enrollment/service/api_service.dart delete mode 100644 lib/pages/help.dart create mode 100644 lib/pages/postEnrollment/chatbot.dart rename lib/pages/{ => postEnrollment}/claimprocess.dart (98%) rename lib/pages/{ => postEnrollment}/claims.dart (82%) create mode 100644 lib/pages/postEnrollment/claimtracklist.dart create mode 100755 lib/pages/postEnrollment/data.dart rename lib/pages/{ => postEnrollment}/generalexclusionsdeductibles.dart (98%) create mode 100644 lib/pages/postEnrollment/help.dart rename lib/pages/{ => postEnrollment}/home.dart (90%) rename lib/pages/{ => postEnrollment}/planclaimsform.dart (59%) rename lib/pages/{ => postEnrollment}/policies.dart (97%) rename lib/pages/{ => postEnrollment}/privacypolicy.dart (99%) rename lib/pages/{ => postEnrollment}/profile.dart (94%) rename lib/{ => pages/postEnrollment}/service/api_service.dart (78%) rename lib/pages/{ => postEnrollment}/termsofuse.dart (99%) diff --git a/.env b/.env index 359dfdf..267d625 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ API_URL=https://venbait.in/nhance/dev/employeeRest/ -TICKET_API_URL=https://venbait.in/nhance/helpdesk/dev/api/ +TICKET_API_URL=https://venbait.in/nhance/helpdesk/dev/api BASE_HREF=/nhance/employee/dev/ ENV=development \ No newline at end of file diff --git a/.env.development b/.env.development index 359dfdf..267d625 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ API_URL=https://venbait.in/nhance/dev/employeeRest/ -TICKET_API_URL=https://venbait.in/nhance/helpdesk/dev/api/ +TICKET_API_URL=https://venbait.in/nhance/helpdesk/dev/api BASE_HREF=/nhance/employee/dev/ ENV=development \ No newline at end of file diff --git a/.env.production b/.env.production index a96bf9f..f0ed597 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ API_URL=https://venbait.in/nhance/uat/employeeRest/ -TICKET_API_URL=https://venbait.in/nhance/helpdesk/uat/api/ +TICKET_API_URL=https://venbait.in/nhance/helpdesk/uat/api BASE_HREF=/nhance/employee/uat/ ENV=production \ No newline at end of file diff --git a/.env.test b/.env.test index 6bf47a1..96bf094 100644 --- a/.env.test +++ b/.env.test @@ -1,4 +1,4 @@ API_URL=https://venbait.in/nhance/test/employeeRest/ -TICKET_API_URL=https://venbait.in/nhance/helpdesk/test/api/ +TICKET_API_URL=https://venbait.in/nhance/helpdesk/test/api BASE_HREF=/nhance/employee/test/ ENV=test \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 399f32a..3008e9c 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ diff --git a/build_web_dev.sh b/build_web_dev.sh index f7d52b3..ad8a027 100755 --- a/build_web_dev.sh +++ b/build_web_dev.sh @@ -11,24 +11,29 @@ fi # Copy the .env.development file to .env cp $ENV_FILE_PATH .env +echo "Copied $ENV_FILE_PATH to .env" -# Check if the BASE_HREF variable exists in the .env file -if ! grep -q BASE_HREF .env; then - echo "BASE_HREF not found in .env file" +# Source the .env file to load the environment variables +source .env + +# Check if the required variables are set +if [ -z "$BASE_HREF" ] || [ -z "$API_URL" ] || [ -z "$TICKET_API_URL" ]; then + echo "Environment variables not set correctly in .env" exit 1 fi -# Extract the BASE_HREF value -BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2) - -# Check if the BASE_HREF value is empty -if [ -z "$BASE_HREF" ]; then - echo "BASE_HREF value is empty" - exit 1 -fi +# Print the loaded variables for verification +echo "Loaded BASE_HREF: $BASE_HREF" +echo "Loaded API_URL: $API_URL" +echo "Loaded TICKET_API_URL: $TICKET_API_URL" # Build the web app for development with base href flutter build web --release --base-href "$BASE_HREF" -# Optionally, remove the .env file after the build -# rm .env +# Check if the build was successful +if [ $? -ne 0 ]; then + echo "Flutter dev build failed" + exit 1 +fi + +echo "Flutter dev build succeeded" diff --git a/build_web_production.sh b/build_web_production.sh index 7463034..2d06463 100755 --- a/build_web_production.sh +++ b/build_web_production.sh @@ -1,34 +1,39 @@ #!/bin/bash -# Define the path to the .env file for production +# Define the path to the .env.production file ENV_FILE_PATH=".env.production" -# Check if the .env file exists +# Check if the .env.production file exists if [ ! -f $ENV_FILE_PATH ]; then echo "$ENV_FILE_PATH does not exist" exit 1 fi -# Copy the .env file for production to .env +# Copy the .env.production file to .env cp $ENV_FILE_PATH .env +echo "Copied $ENV_FILE_PATH to .env" -# Check if the BASE_HREF variable exists in the .env file -if ! grep -q BASE_HREF .env; then - echo "BASE_HREF not found in .env file" +# Source the .env file to load the environment variables +source .env + +# Check if the required variables are set +if [ -z "$BASE_HREF" ] || [ -z "$API_URL" ] || [ -z "$TICKET_API_URL" ]; then + echo "Environment variables not set correctly in .env" exit 1 fi -# Extract the BASE_HREF value -BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2) +# Print the loaded variables for verification +echo "Loaded BASE_HREF: $BASE_HREF" +echo "Loaded API_URL: $API_URL" +echo "Loaded TICKET_API_URL: $TICKET_API_URL" -# Check if the BASE_HREF value is empty -if [ -z "$BASE_HREF" ]; then - echo "BASE_HREF value is empty" - exit 1 -fi - -# Build the web app for production environment with base href +# Build the web app for production with base href flutter build web --release --base-href "$BASE_HREF" -# Optionally, remove the .env file after the build -# rm .env +# Check if the build was successful +if [ $? -ne 0 ]; then + echo "Flutter prod build failed" + exit 1 +fi + +echo "Flutter prod build succeeded" diff --git a/build_web_test.sh b/build_web_test.sh index cee690d..b764d8c 100755 --- a/build_web_test.sh +++ b/build_web_test.sh @@ -1,34 +1,39 @@ #!/bin/bash -# Define the path to the .env file for testing +# Define the path to the .env.test file ENV_FILE_PATH=".env.test" -# Check if the .env file exists +# Check if the .env.test file exists if [ ! -f $ENV_FILE_PATH ]; then echo "$ENV_FILE_PATH does not exist" exit 1 fi -# Copy the .env file for testing to .env +# Copy the .env.test file to .env cp $ENV_FILE_PATH .env +echo "Copied $ENV_FILE_PATH to .env" -# Check if the BASE_HREF variable exists in the .env file -if ! grep -q BASE_HREF .env; then - echo "BASE_HREF not found in .env file" +# Source the .env file to load the environment variables +source .env + +# Check if the required variables are set +if [ -z "$BASE_HREF" ] || [ -z "$API_URL" ] || [ -z "$TICKET_API_URL" ]; then + echo "Environment variables not set correctly in .env" exit 1 fi -# Extract the BASE_HREF value -BASE_HREF=$(grep BASE_HREF .env | cut -d '=' -f2) +# Print the loaded variables for verification +echo "Loaded BASE_HREF: $BASE_HREF" +echo "Loaded API_URL: $API_URL" +echo "Loaded TICKET_API_URL: $TICKET_API_URL" -# Check if the BASE_HREF value is empty -if [ -z "$BASE_HREF" ]; then - echo "BASE_HREF value is empty" - exit 1 -fi - -# Build the web app for test environment with base href +# Build the web app for the test environment with base href flutter build web --release --base-href "$BASE_HREF" -# Optionally, remove the .env file after the build -# rm .env +# Check if the build was successful +if [ $? -ne 0 ]; then + echo "Flutter test build failed" + exit 1 +fi + +echo "Flutter test build succeeded" diff --git a/lib/customAppBar/customAppBar.dart b/lib/customAppBar/customAppBar.dart index f9b7246..bb80d9c 100644 --- a/lib/customAppBar/customAppBar.dart +++ b/lib/customAppBar/customAppBar.dart @@ -9,36 +9,28 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { Future logout(BuildContext context) async { final prefs = await SharedPreferences.getInstance(); - final String? hrtoken = prefs.getString('hrtoken'); final String? token = prefs.getString('token'); if (token != null && token.isNotEmpty) { - if (hrtoken != null && hrtoken.isNotEmpty) { - prefs.remove('token'); - Navigator.pushNamed(context, 'hrDashboard'); - } else { - await prefs.clear(); - Navigator.pushNamed(context, 'phone'); - } - } else if (hrtoken != null && hrtoken.isNotEmpty) { await prefs.clear(); - Navigator.pushNamed(context, 'hrLogin'); + Navigator.pushNamed(context, 'phone'); } } @override Widget build(BuildContext context) { final sw = MediaQuery.of(context).size.width; - + final isPoliciesPage = Uri.base.fragment == 'policies'; return ClipRRect( - borderRadius: Responsive.isDesktop(context) + borderRadius: Responsive.isDesktop(context) || isPoliciesPage ? BorderRadius.zero : BorderRadius.only( bottomLeft: Radius.circular(32.0), bottomRight: Radius.circular(32.0), ), child: AppBar( - backgroundColor: Color(0xFFFFFBDE), // Set background color for AppBar + backgroundColor: const Color(0xFFFFFBDE), + elevation: 0, // Set background color for AppBar toolbarHeight: kToolbarHeight, titleSpacing: 0.0, automaticallyImplyLeading: false, @@ -76,7 +68,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { flex: Responsive.isDesktop(context) ? 9 : 3, child: AdaptiveNavBar( screenWidth: sw, - backgroundColor: Color(0xFFFFFBDE), + backgroundColor: const Color(0xFFFFFBDE), leading: Container(), // Set an empty container as we have the logo separately title: Text(''), diff --git a/lib/customAppBar/enrollmentAppBar.dart b/lib/customAppBar/enrollmentAppBar.dart new file mode 100644 index 0000000..78b663f --- /dev/null +++ b/lib/customAppBar/enrollmentAppBar.dart @@ -0,0 +1,101 @@ +import 'package:flutter/material.dart'; +import 'package:adaptive_navbar/adaptive_navbar.dart'; +import 'package:nhance_app_pwa/customAppBar/responsive.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { + @override + _CustomAppBarState createState() => _CustomAppBarState(); + + @override + Size get preferredSize => Size.fromHeight(kToolbarHeight); +} + +class _CustomAppBarState extends State { + bool showBackToHR = true; + bool hideInactiveStatus = true; + + @override + void initState() { + super.initState(); + } + + Future logout(BuildContext context) async { + final prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + + if (token != null && token.isNotEmpty) { + await prefs.clear(); + Navigator.pushNamed(context, 'login'); + } + } + + @override + Widget build(BuildContext context) { + final sw = MediaQuery.of(context).size.width; + + return Scaffold( + backgroundColor: Color(0xFFFFFCE5), // Set background color for AppBar + appBar: PreferredSize( + preferredSize: widget.preferredSize, + child: SafeArea( + child: Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.symmetric(horizontal: 16.0) + : EdgeInsets.symmetric(horizontal: 0), + child: Row( + children: [ + // Logo Column + Expanded( + flex: Responsive.isDesktop(context) ? 3 : 9, + child: Row( + mainAxisAlignment: Responsive.isDesktop(context) + ? MainAxisAlignment.spaceEvenly + : MainAxisAlignment.start, + children: [ + Container( + margin: EdgeInsets.only(top: 10, bottom: 10), + width: 230, + height: 230, + child: Image.asset( + 'assets/nhance_client_logo.png', + fit: BoxFit.contain, + ), + ), + ], + ), + ), + // AdaptiveNavBar Column + Expanded( + flex: Responsive.isDesktop(context) ? 9 : 3, + child: AdaptiveNavBar( + screenWidth: sw, + backgroundColor: Color(0xFFFFFCE5), + leading: + Container(), // Set an empty container as we have the logo separately + title: Text(''), + navBarItems: [ + if (Responsive.isDesktop(context)) + NavBarItem( + text: "Inactive Policy", + onTap: () { + Navigator.pushNamed(context, 'oldPolicy'); + }, + ), + NavBarItem( + text: "Logout", + onTap: () async { + logout(context); + }, + ), + ], + ), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index a9376ae..248c268 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,17 +1,23 @@ import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; -import 'package:nhance_app_pwa/pages/claimprocess.dart'; -import 'package:nhance_app_pwa/pages/claims.dart'; -import 'package:nhance_app_pwa/pages/claimtracklist.dart'; -import 'package:nhance_app_pwa/pages/generalexclusionsdeductibles.dart'; -import 'package:nhance_app_pwa/pages/help.dart'; -import 'package:nhance_app_pwa/pages/home.dart'; +import 'package:nhance_app_pwa/pages/enrollment/addons.dart'; +import 'package:nhance_app_pwa/pages/enrollment/empDetails.dart'; +import 'package:nhance_app_pwa/pages/enrollment/empReview.dart'; + import 'package:nhance_app_pwa/pages/login.dart'; -import 'package:nhance_app_pwa/pages/planclaimsform.dart'; -import 'package:nhance_app_pwa/pages/policies.dart'; -import 'package:nhance_app_pwa/pages/privacypolicy.dart'; -import 'package:nhance_app_pwa/pages/profile.dart'; -import 'package:nhance_app_pwa/pages/termsofuse.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/chatbot.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/claimprocess.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/claims.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/claimtracklist.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/generalexclusionsdeductibles.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/help.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/home.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/planclaimsform.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/policies.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/privacypolicy.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/profile.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/termsofuse.dart'; + import 'package:nhance_app_pwa/pages/verify.dart'; import 'models/environment.dart'; @@ -35,8 +41,12 @@ Future main() async { 'claimtracklist': (context) => claimtracklist(), 'privacypolicy': (context) => privacypolicy(), 'termsofuse': (context) => termsofuse(), + 'chatbot': (context) => chatbot(), 'generalExclusionsDeductibles': (context) => generalExclusionsDeductibles(), + 'empDetails': (context) => empDetails(), + 'addOnsDetails': (context) => addOnsDetails(), + 'empReviewDetails': (context) => empReviewDetails(), }, )); } diff --git a/lib/models/environment.dart b/lib/models/environment.dart index 0d144de..b4479ad 100644 --- a/lib/models/environment.dart +++ b/lib/models/environment.dart @@ -1,12 +1,14 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; +import '../pages/postEnrollment/home.dart'; + class Environment { static String get fileName { const bool isProduction = bool.fromEnvironment('dart.vm.product', defaultValue: false); - const bool isTest = - bool.fromEnvironment('dart.vm.environment', defaultValue: false); + const bool isTest = bool.fromEnvironment('ENV', defaultValue: false); if (isProduction) { return '.env.production'; @@ -37,3 +39,38 @@ class Environment { return 'uncp8FvG310bEyYdV9MmStlo7KDRZ65fLWTeXCI2JzwPrNHjBqQhUiAgxsaO'; } } + +Future main() async { + await dotenv.load(fileName: Environment.fileName); + runApp(MyApp()); +} + +// class Environment { +// static String get fileName { +// if (kReleaseMode) { +// return '.env.production'; +// } else { +// return '.env.development'; +// } +// } +// +// static String get apiUrl { +// return dotenv.env['API_URL'] ?? 'API_URL not found!'; +// } +// +// static String get baseHref { +// return dotenv.env['BASE_HREF'] ?? 'BASE_HREF not found!'; +// } +// +// static String get env { +// return dotenv.env['ENV'] ?? 'ENV not found!'; +// } +// +// static String get apiUrlTicket { +// return dotenv.env['TICKET_API_URL'] ?? 'API_URL not found!'; +// } +// +// static String get ticketToken { +// return 'uncp8FvG310bEyYdV9MmStlo7KDRZ65fLWTeXCI2JzwPrNHjBqQhUiAgxsaO'; +// } +// } diff --git a/lib/pages/claimtracklist.dart b/lib/pages/claimtracklist.dart deleted file mode 100644 index 5513108..0000000 --- a/lib/pages/claimtracklist.dart +++ /dev/null @@ -1,512 +0,0 @@ -import 'dart:convert'; -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:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; -import 'package:http/http.dart' as http; - -import '../service/api_service.dart'; - -class claimtracklist extends StatefulWidget { - const claimtracklist({Key? key}) : super(key: key); - - @override - State createState() => _claimtracklistformState(); -} - -class _claimtracklistformState extends State { - late ApiService apiService; - dynamic _token; - dynamic empCodeString; - dynamic empPrimaryId; - dynamic client_id; - dynamic policyList; - dynamic policyDataIsEmpty = 1; - dynamic policyHeading; - dynamic policyName; - dynamic EmployeePolicy; - List> employeeDetails = []; - dynamic argumentsData; - dynamic decodedToken; - dynamic claimTrackMsgList; - dynamic empName; - dynamic ticketID; - late TextEditingController messageController; - - // Create a unique form key for each accordion section - final GlobalKey formKey = GlobalKey(); - - @override - void initState() { - super.initState(); - apiService = ApiService(context); // Initialize ApiService here - _loadToken(); - messageController = TextEditingController(); - } - - @override - void dispose() { - super.dispose(); - messageController.dispose(); - } - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - dynamic arguments = ModalRoute.of(context)!.settings.arguments; - if (arguments != null && arguments is Map) { - argumentsData = arguments; - print('argumentsData'); - print(argumentsData); - ticketID = argumentsData['id']; - claimTrackMsgList = argumentsData['message_list']; - print(claimTrackMsgList); - } - } - - Future _loadToken() async { - print('_loadToken'); - final SharedPreferences prefs = await SharedPreferences.getInstance(); - final String? token = prefs.getString('token'); - if (token != null && token.isNotEmpty) { - setState(() { - _token = token; - }); - // Decode the JWT token received from the API response - decodedToken = Jwt.parseJwt(token); - print(decodedToken); - empName = decodedToken['name']; - 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); - } 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'); - } - } - - void sendClaimsMessage(Map formData) async { - try { - formData = formData.map((key, value) => MapEntry(key, value.toString())); - - final response = await apiService.sendClaimsMessageToApi(formData); - - if (response['success'] == 1) { - messageController.clear(); - ToastHelper.showSuccessToast(context, 'Saved Successfully...'); - messageController.clear(); - Navigator.pushNamed(context, 'claims', arguments: 0); - print('Form data sent successfully.'); - } else { - print('Failed to submit form data: ${response['status']}'); - } - } catch (e) { - print('Error submitting form data: $e'); - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - 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: [ - Card( - elevation: 5, - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(15.0), // Set border radius here - ), - child: Container( - decoration: BoxDecoration( - color: Colors.white, // Set background color to white - borderRadius: BorderRadius.circular( - 15.0), // Set border radius for Container - ), - padding: Responsive.isDesktop(context) - ? EdgeInsets.only(top: 15, bottom: 15, left: 15, right: 15) - : EdgeInsets.only( - top: 10, - bottom: 10, - left: 10, - right: 10), // Add padding to the container - child: Row( - children: [ - Expanded( - flex: 12, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - padding: Responsive.isDesktop(context) - ? EdgeInsets.only( - top: 15, - bottom: 15, - left: 25, - right: 25) - : EdgeInsets.only( - top: 0, bottom: 0, left: 0, right: 0), - child: Column( - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.start, - children: [ - Expanded( - flex: 12, - child: InkWell( - onTap: () { - Navigator.pushNamed( - context, 'claims'); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - children: [ - if (!Responsive.isDesktop( - context)) - Icon( - Icons - .chevron_left, // Replace with your desired icon - color: Color(0xFF000000), - size: 30, - ), - SizedBox( - width: Responsive - .isDesktop( - context) - ? 0 - : 5), // Adjust space between icon and text - Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - Text( - 'Claims Track', - textAlign: - TextAlign.start, - style: - GoogleFonts.poppins( - fontSize: 16, - fontWeight: - FontWeight.w600, - color: - Color(0xFF000000), - ), - ), - ], - ), - ], - ), - ), - ), - ], - ), - // Add more rows as needed - ], - ), - ), - SizedBox(height: 15), - Container( - child: SingleChildScrollView( - child: Column(children: [ - ...claimTrackMsgList.map((message) { - bool isUserMessage = - message['staff_name'] == null; - String messageContent = - message['message']; - String messageDate = message['date']; - print('isUserMessage'); - print(isUserMessage); - dynamic messagername; - if (isUserMessage) { - messagername = empName; - } else { - messagername = message['staff_name']; - } - - return Padding( - padding: const EdgeInsets.symmetric( - vertical: 4.0), - child: Align( - alignment: isUserMessage - ? Alignment.centerLeft - : Alignment.centerRight, - child: Container( - constraints: - BoxConstraints(maxWidth: 300), - padding: EdgeInsets.all(10), - decoration: BoxDecoration( - color: isUserMessage - ? Colors.blue[100] - : Colors.green[100], - borderRadius: - BorderRadius.circular(10), - ), - child: Column( - crossAxisAlignment: isUserMessage - ? CrossAxisAlignment.start - : CrossAxisAlignment.end, - children: [ - Row( - mainAxisAlignment: isUserMessage - ? MainAxisAlignment.end - : MainAxisAlignment - .start, // Aligns children to the end (right) of the row - children: [ - Text( - messagername, - style: - GoogleFonts.poppins( - fontSize: Responsive - .isDesktop( - context) - ? 16 - : 14, - fontWeight: - FontWeight.w500, - color: - Color(0xFF000000), - ), - ), - SizedBox(width: 5), - Icon( - Icons - .person, // Replace with your desired icon - color: Color( - 0xFFE26728), // Customize the icon color - size: - 15, // Customize the icon size - ), - ], - ), - Text( - messageContent, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop( - context) - ? 14 - : 12, - fontWeight: FontWeight.w400, - color: Color(0xFF000000), - ), - ), - SizedBox(height: 5), - Text( - formatDate(messageDate), - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop( - context) - ? 12 - : 10, - fontWeight: FontWeight.w400, - color: Color(0xFF636363), - ), - ), - ], - ), - ), - ), - ); - }).toList(), - Padding( - padding: const EdgeInsets.symmetric( - vertical: 8.0), - child: Row( - children: [ - Expanded( - flex: - Responsive.isDesktop(context) - ? 10 - : 9, - child: TextFormField( - controller: messageController, - onChanged: (value) => null, - decoration: InputDecoration( - border: OutlineInputBorder(), - hintText: 'Message', - labelText: 'Message', - contentPadding: - EdgeInsets.symmetric( - vertical: 10, - horizontal: 15), - ), - validator: (value) { - if (value == null || - value.isEmpty) { - return 'Message is required'; - } - return null; - }, - ), - ), - Expanded( - flex: - Responsive.isDesktop(context) - ? 2 - : 3, - child: Container( - alignment: - Alignment.centerRight, - child: ElevatedButton( - onPressed: () { - // Check if any of the fields are empty - if (messageController - .text.isEmpty) { - ToastHelper.showWarningToast( - context, - 'All fields are required'); - } else { - // Create a map to hold the form data - Map - formData = { - 'ticket_id': ticketID, - 'replier': 'user', - 'message': - messageController - .text, - // Add more form fields as needed - }; - - // Call the function to send form data to API - sendClaimsMessage( - formData); - } - }, - child: Text( - 'Reply', - style: GoogleFonts.poppins( - color: Colors.white), - ), - style: - ElevatedButton.styleFrom( - backgroundColor: - Color(0xFFE26728), - shape: - RoundedRectangleBorder( - borderRadius: - BorderRadius.circular( - 5), - ), - ), - ), - ), - ), - ], - ) - // ElevatedButton( - // onPressed: () { - // - // }, - // child: Text('Reply'), - // ), - ), - ]), - )), - ], - ))), - ], - ), - ), - ), - SizedBox(height: Responsive.isDesktop(context) ? 40 : 10), - ]), - )), - 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: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), - floatingActionButtonLocation: Responsive.isDesktop(context) - ? null - : FloatingActionButtonLocation.centerDocked, - bottomNavigationBar: Responsive.isDesktop(context) - ? null - : CustomBottomNavigationBar( - onTabChanged: (index) { - // Add your navigation logic here - // For example: - 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'); - } - }, - icons: [ - Icons.home_outlined, - Icons.sticky_note_2_outlined, - Icons.person_outline_outlined, - Icons.headset_mic_outlined, - ], - labels: [ - "Home", - "Claim", - "Profile", - "Help", - ], // Initial index of the bottom navigation bar - ), - ); - } - - String formatDate(String timestamp) { - // Convert the timestamp string to milliseconds - int milliseconds = int.parse(timestamp) * 1000; - - // Create a DateTime object from milliseconds - DateTime date = DateTime.fromMillisecondsSinceEpoch(milliseconds); - - // Format the DateTime object - String formattedDate = DateFormat('d MMM, y').format(date); - - return formattedDate; - } -} diff --git a/lib/pages/enrollment/addons.dart b/lib/pages/enrollment/addons.dart new file mode 100644 index 0000000..3d51517 --- /dev/null +++ b/lib/pages/enrollment/addons.dart @@ -0,0 +1,4577 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:nhance_app_pwa/pages/enrollment/service/api_service.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import '../../customAppBar/enrollmentAppBar.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/toastHelper.dart'; +import 'package:jwt_decode/jwt_decode.dart'; +import 'package:http/http.dart' as http; +import 'package:flutter/widgets.dart'; +import 'package:flutter/services.dart'; +import 'dart:convert'; +import 'package:intl/intl.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class addOnsDetails extends StatefulWidget { + const addOnsDetails({Key? key}) : super(key: key); + + @override + State createState() => _addOnsDetailsState(); +} + +class _addOnsDetailsState extends State { + late ApiService apiService; + bool isChecked = false; + bool _addOnsDependentSwitcher = + false; // Declare the _isSwitched variable here + bool _topUpSiSwitcher = false; + bool _topUpParentSiSwitcher = false; + dynamic _token; + dynamic empCodeString; + dynamic empPrimaryId; + dynamic gpaEmpName; + dynamic client_id; + dynamic gpaPolicies; + dynamic gmcPolicies; + dynamic gpaPolicyName; + dynamic gpaGridMaster; + dynamic gpasumInsured; + dynamic gpaClintPolicyId; + dynamic gpaMappedFamilyFloaters; + dynamic gpaSelfName; + dynamic gpaSelfDob; + dynamic gpaSelfRelationship; + dynamic gpaSelfDetails; + dynamic gpaECardDownload; + dynamic gmcECardDownload; + dynamic gmcClintPolicyId; + dynamic gmcMappedFamilyFloaters; + dynamic gmcSelfName; + dynamic gmcSelfDob; + dynamic gmcSelfRelationship; + dynamic gmcSelfDetails; + dynamic gmcPolicyName; + dynamic gmcNotes; + dynamic gmcSumInsured; + dynamic gmcFloaterTextDescription; + dynamic gmcFloaterTextHeading; + dynamic gmcTypeName; + dynamic clientName; + dynamic clientLogo; + dynamic topUpECardDownload; + dynamic topUpMappedFamilyFloatersSi; + dynamic topUpMappedFamilyFloatersDependent; + dynamic topUpClientPolicyId; + dynamic topUpSlabRates; + dynamic topUpFamilyFloater; + dynamic topUpPolicyName; + dynamic topUpSiPremiumValue; + dynamic topUpSiValue; + dynamic topUpSiSelectedSI; + dynamic topUpSiPolicies = []; + dynamic topUpTypeName; + int topUpOpenForEnrollment = 0; + dynamic topUpSiParentPolicies = []; + dynamic topUpParentClientPolicyId; + dynamic topUpParentSlabRates; + dynamic topUpParentPolicyName; + dynamic topUpParentFamilyFloater; + dynamic topUpParentMappedFamilyFloatersSi; + dynamic topUpParentECardDownload; + dynamic topUpParentSiValue; + dynamic topUpParentSiSelectedSI; + dynamic topUpParentSiPremiumValue; + dynamic topUpParentSiPremiumGst; + dynamic topUpParentSiTotalAmt; + dynamic topUpParentTypeName; + int topUpParentOpenForEnrollment = 0; + dynamic addOnsDependentPolicies = []; + dynamic addOnsDependentMappedFamilyFloatersDependent; + dynamic addOnsDependentClientPolicyId; + dynamic addOnsDependentSlabRates; + dynamic addOnsSelectedDependent; + dynamic addOnsdependentValue; + dynamic addOnsDependentPolicyName; + dynamic addOnsDependentECardDownload; + int addOnsDependentOpenForEnrollment = 0; + dynamic siValue; + dynamic addOnDependentPremiumValue; + dynamic addOnsDependentFamilyFloater; + dynamic gmcAddOnSiPremiumValue; + dynamic addOnsDependentPremiumGst; + dynamic topUpSiPremiumGst; + dynamic addOnsDependentTotalAmt; + dynamic topUpSiTotalAmt; + late TextEditingController _relationShipController; + late TextEditingController _dobController; + late TextEditingController _memberNameController; + late DateTime? selectedDate; + List> relationshipOptions = []; + List> selectedRelationships = []; + List> formDataList = []; + late DateTime _selectedDate = DateTime.now(); // Define _selectedDate here + + dynamic iAgreeForAddOn = []; + + dynamic gmcDataIsEmpty = 1; + dynamic gpaDataIsEmpty = 1; + dynamic empRefId; + dynamic empClientBranchId; + + @override + void initState() { + super.initState(); + apiService = ApiService(context); // Initialize ApiService here + _dobController = TextEditingController(); + _memberNameController = TextEditingController(); + _relationShipController = TextEditingController(); + _loadToken(); + } + + @override + void dispose() { + _dobController.dispose(); + _memberNameController.dispose(); + _relationShipController.dispose(); + super.dispose(); + } + + String formatDate(String inputDate) { + // Parse the input date string + DateTime dateTime = DateFormat('dd-MM-yyyy').parse(inputDate); + + // Format the date to the desired format + String formattedDate = DateFormat('dd MMM yyyy').format(dateTime); + + return formattedDate; + } + + Future _loadToken() async { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + if (token != null && token.isNotEmpty) { + setState(() { + _token = token; + }); + // Decode the JWT token received from the API response + Map? decodedToken = Jwt.parseJwt(token); + print(decodedToken); + empClientBranchId = prefs.getString('empClientBranchId'); + empCodeString = prefs.getString('empCode'); + print(empCodeString); // Check if emp_code is correct + empPrimaryId = prefs.getString('empPrimaryId'); + gpaEmpName = prefs.getString('gpaEmpName'); + client_id = prefs.getString('client_id'); + print(client_id); + + // print(empPrimaryId); + // Call the API when the page enters + if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) { + clientLogo = prefs.getString('clientLogo'); + clientName = prefs.getString('clientName'); + } else { + getClientLogoAndDetails(); + } + getGmcSiTopUp(); + getGmcSiParentTopUp(); + getGmcDependentAddOns(); + fetchRelationshipList(); + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + } 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, 'phone'); + } + } + + Future getClientLogoAndDetails() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getClientLogoAndDetailsToApi( + client_id!, empCodeString!, empClientBranchId!); + print('check 1'); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + dynamic clientDetails = response['data']; + print(clientDetails); + clientName = clientDetails['client']['client_name']; + print(clientName); + clientLogo = clientDetails['client']['client_logo']; + print(clientLogo); + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGpaEmpPolicyDetails(empPrimaryId) async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGpaEmpPolicyDetailsToApi( + empPrimaryId, empCodeString!, client_id!, 'GPA', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + gpaPolicies = response['data']; + print(gpaPolicies); + // Assuming data is a List + print(gpaPolicies); + if (gpaPolicies.isNotEmpty) { + setState(() { + // You can use gpaPolicies as needed + print('GPA Policies found: $gpaPolicies'); + gpaPolicyName = gpaPolicies['Policy_Name'].toString(); + print(gpaPolicyName); + gpaClintPolicyId = gpaPolicies['ClientPolicyId'].toString(); + print(gpaClintPolicyId); + gpasumInsured = gpaPolicies['mapped_family_floaters']['data'] + ['basic_cover_si']; + print(gpasumInsured); + gpaMappedFamilyFloaters = + gpaPolicies['mapped_family_floaters']['data']; + print(gpaMappedFamilyFloaters); + gpaSelfName = gpaMappedFamilyFloaters['name'].toString() ?? ''; + // gpaSelfMobileNo = gpaMappedFamilyFloaters['mobile']; + gpaSelfDob = gpaMappedFamilyFloaters['dob'].toString() ?? ''; + gpaSelfRelationship = + gpaMappedFamilyFloaters['relationship'].toString() ?? ''; + gpaSelfDetails = gpaSelfName + + ' ~ ' + + gpaSelfRelationship + + ' ~ ' + + ' DOB : ' + + formatDate(gpaSelfDob); + + gpaECardDownload = gpaPolicies['eCardDownload']; + }); + } else { + setState(() { + gpaDataIsEmpty = 0; + }); + // ToastHelper.showWarningToast(context, 'Something went wrong'); + print('No data found in the response'); + } + } else { + // Handle other status messages if needed + // ToastHelper.showWarningToast(context, 'Something went wrong'); + print('API request failed with status: ${response['status']}'); + } + } else { + setState(() { + gpaDataIsEmpty = 0; + }); + // Handle other status codes + ToastHelper.showWarningToast(context, 'Something went wrong'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcEmpPolicyDetails(empPrimaryId) async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcEmpPolicyDetailsToApi( + empPrimaryId, empCodeString!, client_id!, 'GMC', empClientBranchId!); + if (response['status'] == 'success') { + // setState(() { + gmcPolicies = response['data']; + print('gmcPolicies'); + // }); + // Assuming data is a List + print(gmcPolicies); + } else { + setState(() { + gmcDataIsEmpty = 0; + }); + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcSiTopUp() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcSiTopUpToApi( + client_id!, empCodeString!, 'GMC-SI-TOPUP', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + setState(() { + topUpSiPolicies = response['data']; + print('topUpSiPolicies'); + print(topUpSiPolicies); + }); + if (topUpSiPolicies.isNotEmpty) { + // setState(() { + topUpClientPolicyId = + await topUpSiPolicies['gmc_si_topup']['client_policy_id']; + + topUpSlabRates = await topUpSiPolicies['gmc_si_topup']['SlabRates']; + print('topUpSlabRates'); + print(topUpSlabRates); + + topUpPolicyName = + await topUpSiPolicies['gmc_si_topup']['policy_name']; + + topUpFamilyFloater = await topUpSiPolicies['gmc_si_topup'] + ['policy_terms']['family_floater']; + print('topUpFamilyFloater'); + print(topUpFamilyFloater); + + topUpMappedFamilyFloatersSi = await topUpSiPolicies['gmc_si_topup'] + ['family_floaters_of_only_si_array']; + print('topUpMappedFamilyFloatersSi'); + print(topUpMappedFamilyFloatersSi); + + print('topUpECardDownload'); + topUpECardDownload = + topUpSiPolicies['gmc_si_topup']['eCardDownload']; + print(topUpECardDownload); + String intOpenForEnrollment = + topUpSiPolicies['gmc_si_topup']['OpenForEnrollment']; + topUpOpenForEnrollment = int.parse(intOpenForEnrollment); + print(topUpOpenForEnrollment); + + topUpTypeName = topUpSiPolicies['gmc_si_topup']['type']; + + topUpSiValue = await topUpSiPolicies['gmc_si_topup'] + ['family_floaters_of_only_si_value']; + topUpSiSelectedSI = + topUpSiValue != 0 ? topUpSiValue.toString() : null; + if (topUpSiSelectedSI != null) { + print('topUpSiSelectedSI'); + + _topUpSiSwitcher = true; + setState(() { + topUpSiPremiumValue = topUpSiPolicies['gmc_si_topup'] + ['family_floaters_of_only_si_premium_value']; + + topUpSiPremiumGst = topUpSiPolicies['gmc_si_topup'] + ['family_floaters_of_only_si_gst_value']; + + topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst; + }); + } + // }); + } else { + // ToastHelper.showErrorToast( + // context, 'No data found in the response'); + print('No data found in the response'); + } + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcSiParentTopUp() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcSiParentTopUpToApi(client_id!, + empCodeString!, 'GMC-SI-PARENT-TOPUP', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + setState(() { + topUpSiParentPolicies = response['data']; + print('topUpSiParentPolicies'); + print(topUpSiParentPolicies); + }); + if (topUpSiParentPolicies.isNotEmpty) { + // setState(() { + topUpParentClientPolicyId = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['client_policy_id']; + + topUpParentSlabRates = + await topUpSiParentPolicies['gmc_si_parent_topup']['SlabRates']; + print('topUpParentSlabRates'); + print(topUpParentSlabRates); + + topUpParentPolicyName = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['policy_name']; + + topUpParentFamilyFloater = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['policy_terms']['family_floater']; + print('topUpParentFamilyFloater'); + print(topUpParentFamilyFloater); + + topUpParentMappedFamilyFloatersSi = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['family_floaters_of_only_si_array']; + print('topUpParentMappedFamilyFloatersSi'); + print(topUpParentMappedFamilyFloatersSi); + + print('topUpECardDownload'); + topUpParentECardDownload = + topUpSiParentPolicies['gmc_si_parent_topup']['eCardDownload']; + print(topUpParentECardDownload); + String intOpenForEnrollment = + topUpSiParentPolicies['gmc_si_parent_topup'] + ['OpenForEnrollment']; + topUpParentOpenForEnrollment = int.parse(intOpenForEnrollment); + print(topUpParentOpenForEnrollment); + + topUpParentTypeName = + topUpSiParentPolicies['gmc_si_parent_topup']['type']; + + topUpParentSiValue = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['family_floaters_of_only_si_value']; + topUpParentSiSelectedSI = + topUpParentSiValue != 0 ? topUpParentSiValue.toString() : null; + if (topUpParentSiSelectedSI != null) { + print('topUpParentSiSelectedSI'); + + _topUpParentSiSwitcher = true; + setState(() { + topUpParentSiPremiumValue = + topUpSiParentPolicies['gmc_si_parent_topup'] + ['family_floaters_of_only_si_premium_value']; + + topUpParentSiPremiumGst = + topUpSiParentPolicies['gmc_si_parent_topup'] + ['family_floaters_of_only_si_gst_value']; + + topUpParentSiTotalAmt = + topUpParentSiPremiumValue + topUpParentSiPremiumGst; + }); + } + // }); + } else { + // ToastHelper.showErrorToast( + // context, 'No data found in the response'); + print('No data found in the response'); + } + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcDependentAddOns() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcDependentAddOnsToApi(client_id!, + empCodeString!, 'GMC-DEPENDENT-ADDON', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + setState(() { + addOnsDependentPolicies = response['data']; + print('addOnsDependentPolicies'); + print(addOnsDependentPolicies); + }); + if (addOnsDependentPolicies.isNotEmpty) { + // setState(() { + addOnsDependentClientPolicyId = + addOnsDependentPolicies['gmc_dependent_addon'] + ['client_policy_id']; + + addOnsDependentSlabRates = + await addOnsDependentPolicies['gmc_dependent_addon'] + ['SlabRates']; + print(addOnsDependentSlabRates); + + addOnsDependentPolicyName = + await addOnsDependentPolicies['gmc_dependent_addon'] + ['policy_name']; + + addOnsDependentFamilyFloater = + await addOnsDependentPolicies['gmc_dependent_addon'] + ['policy_terms']['family_floater']; + print('addOnsDependentFamilyFloater'); + print(addOnsDependentFamilyFloater); + + setState(() { + addOnsDependentMappedFamilyFloatersDependent = + addOnsDependentPolicies['gmc_dependent_addon'] + ['family_floaters_of_dependent_and_si_array']; + print('addOnsDependentMappedFamilyFloatersDependent'); + print(addOnsDependentMappedFamilyFloatersDependent); + }); + + addOnsdependentValue = + await addOnsDependentPolicies['gmc_dependent_addon'] + ['family_floaters_of_dependent_and_si_value']; + + addOnsSelectedDependent = await addOnsdependentValue != 0 + ? addOnsdependentValue.toString() + : null; + if (addOnsSelectedDependent != null) { + _addOnsDependentSwitcher = true; + setState(() { + addOnDependentPremiumValue = + addOnsDependentPolicies['gmc_dependent_addon'] + ['family_floaters_of_dependent_and_si_premium_value']; + + addOnsDependentPremiumGst = + addOnsDependentPolicies['gmc_dependent_addon'] + ['family_floaters_of_dependent_and_gst_value']; + + addOnsDependentTotalAmt = + addOnDependentPremiumValue + addOnsDependentPremiumGst; + }); + + addOnsDependentECardDownload = + addOnsDependentPolicies['gmc_dependent_addon'] + ['eCardDownload']; + print('addOnsDependentECardDownload'); + print(addOnsDependentECardDownload); + + String intOpenForEnrollment = + addOnsDependentPolicies['gmc_dependent_addon'] + ['OpenForEnrollment']; + addOnsDependentOpenForEnrollment = + int.parse(intOpenForEnrollment); + // if (addOnDependentPremiumValue != null) { + // calculationForDependentSumValue('Add'); + // } + } + + // }); + } else { + // ToastHelper.showErrorToast( + // context, 'No data found in the response'); + print('No data found in the response'); + } + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future fetchRelationshipList() async { + // Replace the URL with your API endpoint + try { + final response = await apiService.fetchRelationshipListToApi(); + if (response['status'] == 'success') { + for (var item in response['data']) { + String relationshipName = item['relationship_name']; + String dependent = item['dependent']; + + relationshipOptions.add({ + 'relationship_name': relationshipName, + 'dependent': dependent, + }); + } + // final List relationships = + // List.from(data.map((item) => item['relationship_name'])); + // setState(() { + // relationshipOptions = relationships; + // }); + } else { + // ToastHelper.showErrorToast( + // context, 'Failed to fetch relationship list'); + throw Exception('Failed to fetch relationship list'); + } + } catch (error) { + // ToastHelper.showErrorToast( + // context, 'Error fetching relationship list: $error'); + print('Error fetching relationship list: $error'); + // Handle error accordingly, e.g., show a snackbar with an error message + } + } + + Future _selectDate(BuildContext context, formType) async { + print(formType); + var ageValidation = formType['age_validation']; + int min = + int.parse(ageValidation['min']); // Parsing the string to an integer + int max = + int.parse(ageValidation['max']); // Parsing the string to an integer + print(min); + print(max); + late DateTime minDate; + late DateTime maxDate; + + final DateTime now = DateTime.now(); + + maxDate = DateTime(now.year - min, now.month, now.day); + print(maxDate); + minDate = DateTime(now.year - max, now.month, now.day); + print(minDate); + + // if (formType == 'child') { + // // For 'child' form type, allow 0-25 age + // minDate = DateTime(now.year - 25, now.month, now.day); + // maxDate = now; + // } else { + // // For other form types, allow 18-100 age + // minDate = DateTime(1900); + // maxDate = DateTime(now.year - 18, now.month, now.day); + // } + + // Ensure initialDate is within the range of minDate and maxDate + DateTime initialDate = + _selectedDate ?? maxDate; // Use maxDate if _selectedDate is null + initialDate = initialDate.isBefore(minDate) ? minDate : initialDate; + initialDate = initialDate.isAfter(maxDate) ? maxDate : initialDate; + + final DateTime? picked = await showDatePicker( + context: context, + initialDate: initialDate, + firstDate: minDate, + lastDate: maxDate, + selectableDayPredicate: (DateTime date) { + return date.isAfter(minDate.subtract(const Duration(days: 1))) && + date.isBefore(maxDate.add(const Duration(days: 1))); + }, + ); + + if (picked != null && picked != _selectedDate) { + setState(() { + _selectedDate = picked; + _dobController.text = DateFormat('dd-MM-yyyy').format(_selectedDate); + }); + } + } + + Future deleteItem(Map deletedItem) async { + print(deletedItem); + try { + var id = deletedItem['employee_id']; + final response = await apiService.deleteItemToApi(id); + + // Check if the request was successful (status code 200) + if (response['status'] == 'success') { + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + relationshipOptions.clear(); + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + fetchRelationshipList(); + getGmcSiTopUp(); + getGmcSiParentTopUp(); + getGmcDependentAddOns(); + ToastHelper.showSuccessToast(context, 'Item deleted successfully'); + print('Item deleted successfully'); + } else { + // Handle errors + ToastHelper.showErrorToast(context, 'Failed to delete item'); + } + } catch (error) { + // Handle network errors + print('Error deleting item: $error'); + } + } + + void saveAddOnsDetails(Map formData, + Map floatedData, action) async { + // Construct the array of objects + print(formData); + print(floatedData); + print(action); + formDataList.add({ + 'relationship': formData['relationship'], + 'name': formData['memberName'], + 'dob': formData['dateOfBirth'], + 'emp_code': empCodeString, + 'client_id': client_id, + 'client_policy_id': floatedData['client_policy_id'], + 'is_addon_value': 1, + 'basic_cover_si': addOnsSelectedDependent, + 'created_by': empPrimaryId, + 'client_branch_id': empClientBranchId, + // Add the 'id' field only if action is 'Edit' + if (action == 'Edit') 'id': floatedData['employee_id'], + }); + + // Convert the list of objects to JSON + // String formDataJson = jsonEncode(formDataList); + + final response = await apiService.saveAddOnsDetailsToApi(formDataList); + + // Check the response + if (response['status'] == 'success') { + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + relationshipOptions.clear(); + // Request successful, handle response + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + fetchRelationshipList(); + getGmcSiTopUp(); + getGmcSiParentTopUp(); + getGmcDependentAddOns(); + ToastHelper.showSuccessToast(context, 'Saved Successfully...'); + print('Form data sent successfully.'); + } else { + // Request failed, handle error + ToastHelper.showErrorToast(context, 'Failed'); + print('Failed to send form data. Error: ${response}'); + } + } + + void cancelPopUp() { + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + } + + void sendAddonsGmcDependentToAPI() async { + print(_addOnsDependentSwitcher); + print('continue'); + print(addOnsSelectedDependent); + if (_addOnsDependentSwitcher == true) { + if (addOnsSelectedDependent == null || addOnsSelectedDependent.isEmpty) { + return; // Return if addOnsSelectedDependent is null or empty + } else { + print('createOrUpdateEmployeePolicySiAmount'); + try { + dynamic getTrueObjects = addOnsDependentMappedFamilyFloatersDependent + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + List> getTrueDataObjects = getTrueObjects + .map>( + (element) => element['data'] as Map) + .toList(); + + print(getTrueDataObjects); + + List> selectedValues = []; + // try { + print('fff'); + if (getTrueDataObjects != null || getTrueDataObjects.isNotEmpty) { + for (var floater in getTrueDataObjects) { + String employee_id = floater['employee_id']; + String client_policy_id = floater['client_policy_id'].toString(); + + // Create a map containing the floater details and its selected values + Map floaterData = { + 'basic_cover_si': addOnsSelectedDependent, + 'client_policy_id': client_policy_id, + 'employee_id': employee_id, + 'client_id': client_id, + 'emp_code': empCodeString, + }; + + // Add the map to the list + selectedValues.add(floaterData); + } + print(selectedValues); + } + // Iterate through familyMembers list and send each member's data to the API + + final response = + await apiService.sendAddonsGmcDependentToAPI(selectedValues); + + if (response['status'] == 'success') { + // Member saved successfully + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + // Navigator.pushNamed(context, 'empReviewDetails'); + // ToastHelper.showSuccessToast(context, 'Saved successfully!'); + print('Saved successfully!'); + } else { + // Failed to save member + // ToastHelper.showErrorToast(context, "Operation Failed!"); + ToastHelper.showErrorToast(context, 'Failed to save'); + print('Operation Failed!'); + } + } catch (error) { + print('Error saving family members'); + // ToastHelper.showErrorToast(context, "Error saving family members"); + } + } + } else { + // Navigator.pushNamed(context, 'empReviewDetails'); + } + } + + void sendAddonsGmcSiToAPI() async { + print(_topUpSiSwitcher); + print('continue'); + print(topUpSiSelectedSI); + if (_topUpSiSwitcher == true) { + if (topUpSiSelectedSI == null || topUpSiSelectedSI.isEmpty) { + print('topUpSiSelectedSI'); + return; // Return if addOnsSelectedDependent is null or empty + } else { + print('createOrUpdateEmployeePolicySiAmount'); + try { + dynamic getTrueObjects = topUpMappedFamilyFloatersSi + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + List> getTrueDataObjects = getTrueObjects + .map>( + (element) => element['data'] as Map) + .toList(); + + print(getTrueDataObjects); + + List> selectedValues = []; + // try { + print('fff'); + if (getTrueDataObjects != null || getTrueDataObjects.isNotEmpty) { + for (var floater in getTrueDataObjects) { + String employee_id = floater['employee_id']; + String client_policy_id = floater['client_policy_id'].toString(); + + // Create a map containing the floater details and its selected values + Map floaterData = { + 'basic_cover_si': topUpSiSelectedSI, + 'client_policy_id': client_policy_id, + 'employee_id': employee_id, + 'client_id': client_id, + 'emp_code': empCodeString, + }; + + // Add the map to the list + selectedValues.add(floaterData); + } + print(selectedValues); + } + + final response = + await apiService.sendAddonsGmcSiToAPI(selectedValues); + + if (response['status'] == 'success') { + // Member saved successfully + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + // Navigator.pushNamed(context, 'empReviewDetails'); + // ToastHelper.showSuccessToast(context, 'Saved successfully!'); + print('Saved successfully!'); + } else { + // Failed to save member + // ToastHelper.showErrorToast(context, "Operation Failed!"); + // ToastHelper.showSuccessToast(context, 'Failed to Save...'); + print('Failed to Save...'); + } + } catch (error) { + print('Error saving family members'); + // ToastHelper.showErrorToast(context, "Error saving family members"); + } + } + } else { + // Navigator.pushNamed(context, 'empReviewDetails'); + } + } + + void sendAddonsGmcParentSiToAPI() async { + print(_topUpParentSiSwitcher); + print('continue'); + print(topUpParentSiSelectedSI); + if (_topUpParentSiSwitcher == true) { + if (topUpParentSiSelectedSI == null || topUpParentSiSelectedSI.isEmpty) { + print('topUpSiSelectedSI'); + return; // Return if addOnsSelectedDependent is null or empty + } else { + print('createOrUpdateEmployeePolicySiAmount'); + try { + dynamic getTrueObjects = topUpParentMappedFamilyFloatersSi + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + List> getTrueDataObjects = getTrueObjects + .map>( + (element) => element['data'] as Map) + .toList(); + + print(getTrueDataObjects); + + List> selectedValues = []; + // try { + print('fff'); + if (getTrueDataObjects != null || getTrueDataObjects.isNotEmpty) { + for (var floater in getTrueDataObjects) { + String employee_id = floater['employee_id']; + String client_policy_id = floater['client_policy_id'].toString(); + + // Create a map containing the floater details and its selected values + Map floaterData = { + 'basic_cover_si': topUpParentSiSelectedSI, + 'client_policy_id': client_policy_id, + 'employee_id': employee_id, + 'client_id': client_id, + 'emp_code': empCodeString, + }; + + // Add the map to the list + selectedValues.add(floaterData); + } + print(selectedValues); + } + + final response = + await apiService.sendAddonsGmcParentSiToAPI(selectedValues); + + if (response['status'] == 'success') { + // Member saved successfully + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + // Navigator.pushNamed(context, 'empReviewDetails'); + // ToastHelper.showSuccessToast(context, 'Saved successfully!'); + print('Saved successfully!'); + } else { + // Failed to save member + // ToastHelper.showErrorToast(context, "Operation Failed!"); + // ToastHelper.showSuccessToast(context, 'Failed to Save...'); + print('Failed to Save...'); + } + } catch (error) { + print('Error saving family members'); + // ToastHelper.showErrorToast(context, "Error saving family members"); + } + } + } else { + // Navigator.pushNamed(context, 'empReviewDetails'); + } + } + + Future removeAddonsGmcDependentToAPI() async { + try { + if (empCodeString == null || addOnsDependentClientPolicyId == null) { + return; + } + final response = await apiService.removeAddonsGmcDependentToAPI( + empCodeString!, addOnsDependentClientPolicyId!); + if (response['status'] == 'success') { + print(response['data']); + } else { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future removeAddonsGmcSiToAPI() async { + try { + if (empCodeString == null || topUpClientPolicyId == null) { + return; + } + final response = await apiService.removeAddonsGmcSiToAPI( + empCodeString!, topUpClientPolicyId!); + if (response['status'] == 'success') { + print(response['data']); + } else { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future removeAddonsGmcParentSiToAPI() async { + try { + if (empCodeString == null || topUpParentClientPolicyId == null) { + return; + } + final response = await apiService.removeAddonsGmcParentSiToAPI( + empCodeString!, topUpParentClientPolicyId!); + if (response['status'] == 'success') { + print(response['data']); + } else { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + void checkToCallRemoveEmpOrNot() { + if (_topUpSiSwitcher == false && + _addOnsDependentSwitcher == false && + _topUpParentSiSwitcher == false) { + removeAddonsGmcDependentToAPI(); + removeAddonsGmcSiToAPI(); + removeAddonsGmcParentSiToAPI(); + Navigator.pushNamed(context, 'empReviewDetails', + arguments: {'siData': [], 'siParentData': [], 'dependentData': []}); + } else if (_topUpSiSwitcher == false) { + removeAddonsGmcSiToAPI(); + Navigator.pushNamed(context, 'empReviewDetails', + arguments: {'siData': [], 'siParentData': [], 'dependentData': []}); + } else if (_topUpParentSiSwitcher == false) { + removeAddonsGmcParentSiToAPI(); + Navigator.pushNamed(context, 'empReviewDetails', + arguments: {'siData': [], 'siParentData': [], 'dependentData': []}); + } else if (_addOnsDependentSwitcher == false) { + removeAddonsGmcDependentToAPI(); + Navigator.pushNamed(context, 'empReviewDetails', + arguments: {'siData': [], 'siParentData': [], 'dependentData': []}); + } + } + + void topUpSiCalculation(choosedSiValue) async { + try { + print(choosedSiValue); + + var calculation = { + 'client_policy_id': topUpClientPolicyId, + 'emp_code': empCodeString, + 'si': choosedSiValue + }; + + print(calculation); + // Iterate through familyMembers list and send each member's data to the API + + final response = await apiService.topUpSiCalculationToAPI(calculation); + + if (response['status'] == 'success') { + print(response); + List? topUpEmpArray; + for (var item in response['data']) { + if (item.containsKey(empCodeString)) { + topUpEmpArray = item[empCodeString]; + break; + } + } + + if (topUpEmpArray != null) { + print('Array for emp_code $empCodeString:'); + print(topUpEmpArray); + double topUpRataPremimumSum = 0; + for (var item in topUpEmpArray) { + var topUpRataPremimum = item['policy_details']['rata_premimum']; + if (topUpRataPremimum != null) { + topUpRataPremimumSum += topUpRataPremimum; + } + } + print('Sum of rata_premimum: $topUpRataPremimumSum'); + + double topUpGstSum = 0; + for (var item in topUpEmpArray) { + var topUpGst = item['policy_details']['gst']; + if (topUpGst != null) { + topUpGstSum += topUpGst; + } + } + print('Sum of gst: $topUpGstSum'); + setState(() { + topUpSiPremiumValue = topUpRataPremimumSum; + print(topUpSiPremiumValue); + topUpSiPremiumGst = topUpGstSum; + print(topUpSiPremiumGst); + topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst; + print(topUpSiTotalAmt); + }); + sendAddonsGmcSiToAPI(); + } else { + print('Array not found for emp_code $empCodeString'); + } + } else { + print('Operation Failed!'); + } + } catch (error) { + print('Error saving family members'); + // ToastHelper.showErrorToast(context, "Error saving family members"); + } + } + + void topUpParentSiCalculation(choosedSiValue) async { + try { + print(choosedSiValue); + + var calculation = { + 'client_policy_id': topUpParentClientPolicyId, + 'emp_code': empCodeString, + 'si': choosedSiValue + }; + + print(calculation); + // Iterate through familyMembers list and send each member's data to the API + + final response = + await apiService.topUpParentSiCalculationToAPI(calculation); + + if (response['status'] == 'success') { + print(response['data']); + List? topUpEmpArray; + for (var item in response['data']) { + if (item.containsKey(empCodeString)) { + topUpEmpArray = item[empCodeString]; + break; + } + } + + if (topUpEmpArray != null) { + print('Array for emp_code $empCodeString:'); + print(topUpEmpArray); + double topUpRataPremimumSum = 0; + for (var item in topUpEmpArray) { + var topUpRataPremimum = item['policy_details']['rata_premimum']; + if (topUpRataPremimum != null) { + topUpRataPremimumSum += topUpRataPremimum; + } + } + print('Sum of rata_premimum: $topUpRataPremimumSum'); + + double topUpGstSum = 0; + for (var item in topUpEmpArray) { + var topUpGst = item['policy_details']['gst']; + if (topUpGst != null) { + topUpGstSum += topUpGst; + } + } + print('Sum of gst: $topUpGstSum'); + setState(() { + topUpParentSiPremiumValue = topUpRataPremimumSum; + print(topUpParentSiPremiumValue); + topUpParentSiPremiumGst = topUpGstSum; + print(topUpSiPremiumGst); + topUpParentSiTotalAmt = + topUpParentSiPremiumValue + topUpParentSiPremiumGst; + print(topUpParentSiTotalAmt); + }); + sendAddonsGmcParentSiToAPI(); + } else { + print('Array not found for emp_code $empCodeString'); + } + } else { + print('Operation Failed!'); + } + } catch (error) { + print('Error saving family members'); + // ToastHelper.showErrorToast(context, "Error saving family members"); + } + } + + void addOnsDependentCalculation(choosedDependentValue) async { + try { + print(choosedDependentValue); + + var calculation = { + 'client_policy_id': addOnsDependentClientPolicyId, + 'emp_code': empCodeString, + 'si': choosedDependentValue + }; + + print(calculation); + // Iterate through familyMembers list and send each member's data to the API + + final response = + await apiService.addOnsDependentCalculationToAPI(calculation); + + if (response['status'] == 'success') { + print(response['data']); + List? addOnsEmpArray; + for (var item in response['data']) { + if (item.containsKey(empCodeString)) { + addOnsEmpArray = item[empCodeString]; + break; + } + } + + if (addOnsEmpArray != null) { + print('Array for emp_code $empCodeString:'); + print(addOnsEmpArray); + double addOnsRataPremimumSum = 0; + for (var item in addOnsEmpArray) { + var addOnsRataPremimum = item['policy_details']['rata_premimum']; + if (addOnsRataPremimum != null) { + addOnsRataPremimumSum += addOnsRataPremimum; + } + } + print('Sum of rata_premimum: $addOnsRataPremimumSum'); + + double addOnsGstSum = 0; + for (var item in addOnsEmpArray) { + var addOnsGst = item['policy_details']['gst']; + if (addOnsGst != null) { + addOnsGstSum += addOnsGst; + } + } + print('Sum of gst: $addOnsGstSum'); + setState(() { + addOnDependentPremiumValue = addOnsRataPremimumSum; + print(addOnDependentPremiumValue); + addOnsDependentPremiumGst = addOnsGstSum; + print(addOnsDependentPremiumGst); + addOnsDependentTotalAmt = + addOnDependentPremiumValue + addOnsDependentPremiumGst; + print(topUpSiTotalAmt); + }); + } else { + print('Array not found for emp_code $empCodeString'); + } + } else { + print('Operation Failed!'); + } + } catch (error) { + print('Error saving family members'); + // ToastHelper.showErrorToast(context, "Error saving family members"); + } + } + + Future sendAddOnAPI() async { + print('sendAddOnAPI'); + if (gpaDataIsEmpty != 0) { + iAgreeForAddOn.add(int.parse(gpaClintPolicyId)); + } + + if (gmcDataIsEmpty != 0) { + for (var item in gmcPolicies) { + // Extract ClientPolicyId value from each object + String clientPolicyId = item['ClientPolicyId']; + // Convert to integer and add to iAgreeForAddOn list + iAgreeForAddOn.add(int.parse(clientPolicyId)); + } + } + + print('iAgreeForAddOn'); + iAgreeForAddOn = iAgreeForAddOn.toSet().toList(); + print(iAgreeForAddOn); // Output: [90, 92, 88, 89] + + Map apiParams = { + 'emp_code': empCodeString, + 'client_policy_id': iAgreeForAddOn, + 'client_id': client_id, + }; + + // Convert the list of objects to JSON + // String formDataJson = jsonEncode(apiParams); + + try { + final response = await apiService.sendAddOnToAPI(apiParams); + + if (response['status'] == 'success') { + print('response.statusCode == 200'); + ToastHelper.showSuccessToast(context, 'Saved Successfully...'); + } else { + // Handle other status codes + ToastHelper.showErrorToast(context, 'failed to save'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future backFunction() async { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + if (prefs.containsKey('hrtoken')) { + String? mobileNo = prefs.getString('fromHrLoginMobileNo'); + print('mobileNo'); + print(mobileNo); + Navigator.pushNamed(context, 'empDetails', + arguments: {'mobile': mobileNo}); + } else { + Navigator.pushNamed(context, 'empDetails'); + } + } + + void checkSiTopUp() async { + print('checkSiTopUp'); + List> siData = [ + { + 'topUpSiPremiumValue': topUpSiPremiumValue, + 'topUpSiPremiumGst': topUpSiPremiumGst, + 'topUpSiTotalAmt': topUpSiTotalAmt, + } + ]; + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString('siData', jsonEncode(siData)); + } + + void checkSiParentTopUp() async { + print('checkSiParentTopUp'); + List> siParentData = [ + { + 'topUpParentSiPremiumValue': topUpParentSiPremiumValue, + 'topUpParentSiPremiumGst': topUpParentSiPremiumGst, + 'topUpParentSiTotalAmt': topUpParentSiTotalAmt, + } + ]; + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString('siParentData', jsonEncode(siParentData)); + } + + void checkDependentTopUp() async { + print('checkDependentTopUp'); + List> dependentData = [ + { + 'addOnDependentPremiumValue': addOnDependentPremiumValue, + 'addOnsDependentPremiumGst': addOnsDependentPremiumGst, + 'addOnsDependentTotalAmt': addOnsDependentTotalAmt, + } + ]; + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString('dependentData', jsonEncode(dependentData)); + } + + @override + Widget build(BuildContext context) { + print('CVC'); + print('Check1: $topUpSiPolicies'); + print('CVC'); + print('Check2: $addOnsDependentPolicies'); + if (gpaDataIsEmpty == 0 && gmcDataIsEmpty == 0) { + return Scaffold( + appBar: CustomAppBar(), + body: Center( + child: Container( + color: Color(0xFFEFF3F6), + child: Center( + child: Text('No Data Available', + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.bold, + )), + ), + ), + ), + ); + } else { + List familyFloaterContainers = []; + if (addOnsDependentMappedFamilyFloatersDependent != null) { + for (var floater in addOnsDependentMappedFamilyFloatersDependent) { + bool isValueExist = floater['is_value_exist']; + Map floaterData = floater['data']; + + if (isValueExist) { + familyFloaterContainers.add( + Container( + decoration: BoxDecoration( + border: Border.all( + color: Color(0xFF000000), + width: 1, + ), + borderRadius: BorderRadius.circular(5), + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(15) + : EdgeInsets.only(top: 8, bottom: 8, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: Responsive.isDesktop(context) ? 1 : 2, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(10) + : EdgeInsets.all(5), + decoration: BoxDecoration( + color: Color(0xFF00989E), + borderRadius: BorderRadius.circular(5), + ), + child: Icon( + Icons.account_circle, + color: Colors.white, + size: 32, + ), + ), + ], + ), + ), + ), + SizedBox(width: Responsive.isDesktop(context) ? 5 : 0), + Expanded( + flex: Responsive.isDesktop(context) ? 9 : 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + floaterData['name'] ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 18 : 16, + fontWeight: FontWeight.w600, + ), + ), + Text( + '${floaterData['relationship']} - ${floaterData['dob']}', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 18 : 16, + ), + ), + ], + ), + ), + ), + if (addOnsDependentOpenForEnrollment != 0) + if (addOnsDependentECardDownload == null) + if (isValueExist && + floaterData['relationship'] != 'Self') + Expanded( + flex: Responsive.isDesktop(context) ? 1 : 2, + child: Container( + alignment: Alignment.topRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: () { + deleteItem(floaterData); + }, + child: Text( + 'Delete', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 16 + : 15, + color: Color( + 0xFFE26728), // Add underline decoration + ), + ), + ), + ) + ], + ), + ), + ), + if (addOnsDependentOpenForEnrollment != 0) + if (addOnsDependentECardDownload == null) + Expanded( + flex: (isValueExist && + floaterData['relationship'] != 'Self') + ? Responsive.isDesktop(context) + ? 1 + : 2 + : Responsive.isDesktop(context) + ? 2 + : 4, + child: Container( + alignment: Alignment.topRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: () { + openForm(floaterData, 'Edit'); + }, + child: Text( + floaterData['relationship'] == 'Self' + ? 'View' + : 'Edit', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 16 + : 15, + color: Color( + 0xFFE26728), // Add underline decoration + ), + ), + ), + ) + ], + ), + ), + ), + ], + ), + ), + ); + } else { + familyFloaterContainers.add(MouseRegion( + cursor: SystemMouseCursors.click, // Set cursor to pointer + child: GestureDetector( + onTap: () { + // Handle the click event to open the form + if (addOnsSelectedDependent != null) { + if (addOnsDependentOpenForEnrollment != 0) { + if (addOnsDependentECardDownload == null) { + openForm(floaterData, 'Add'); + } + } + } else { + ToastHelper.showWarningToast( + context, 'Please Select Sum Insured Amount'); + } + }, + child: Container( + decoration: BoxDecoration( + border: Border.all( + color: Color(0xFF000000), + width: 1, + ), + borderRadius: BorderRadius.circular(5), + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(12) + : EdgeInsets.all(10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: Responsive.isDesktop(context) ? 1 : 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + padding: EdgeInsets.all(5), + decoration: BoxDecoration( + color: Color(0xFF6A6A6A), + borderRadius: BorderRadius.circular(5), + ), + child: Icon( + Icons.person_add, + color: Colors.white, + size: 20, + ), + ), + ], + ), + ), + ), + SizedBox(width: Responsive.isDesktop(context) ? 5 : 10), + Expanded( + flex: Responsive.isDesktop(context) ? 11 : 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + floaterData['button_name'] ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 22 : 18, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + ), + ), + ], + ), + ), // Replace YourChildWidget with the widget you want to wrap + ), + )); + } + familyFloaterContainers.add(SizedBox(height: 15)); + } + } + + return Scaffold( + appBar: CustomAppBar(), + body: 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: Color(0xFFEFF3F6), + child: Column( + children: [ + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 12, + bottom: 12, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerLeft, + child: Image.network( + clientLogo ?? '', + width: 80, // Set the width here + height: 80, // Set the height here + loadingBuilder: (BuildContext context, + Widget child, + ImageChunkEvent? loadingProgress) { + if (loadingProgress == null) return child; + return Center( + child: CircularProgressIndicator( + value: loadingProgress.expectedTotalBytes != + null + ? loadingProgress + .cumulativeBytesLoaded / + loadingProgress.expectedTotalBytes! + : null, + ), + ); + }, + errorBuilder: (BuildContext context, Object error, + StackTrace? stackTrace) { + return Image.asset( + 'assets/Solid_gray.png', // Replace 'default_image.png' with your default image asset path + width: 80, + height: 80, + fit: BoxFit.cover, + ); + }, + ), + ), + ), + Expanded( + flex: 9, + child: Text( + clientName ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 20 : 18, + fontWeight: FontWeight.w600, + ), + ), + ) + ], + ), + ), + ), + SizedBox(height: 16), + if (gpaPolicies != null && gpaPolicies.length > 0) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + gpaPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + 'Group Personal Accident Coverage', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + if (gpaECardDownload != null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = Uri.parse( + gpaECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl( + uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $gpaECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors + .click, + child: Icon( + Icons.file_download, + color: + Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + 'Sum Insured', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${gpasumInsured != null ? gpasumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: + Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + gpaSelfDetails ?? '', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ), + ], + ), + ), + ], + ), + )), + SizedBox(height: 16), + if (gmcPolicies != null && gmcPolicies.length > 0) + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ...generateGmcCards(gmcPolicies), + ], + ), + SizedBox(height: 16), + if (addOnsDependentMappedFamilyFloatersDependent != null || + topUpMappedFamilyFloatersSi != null) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Add Ons', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 18, + fontWeight: FontWeight.w600, + color: Color(0xFF181818)), + ), + Text( + 'Increase your medical cover for your family or add parents or parent in laws by paying additional premium', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 15, + color: Color(0xFF181818), + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + if (topUpMappedFamilyFloatersSi != null) + Container( + decoration: BoxDecoration( + color: Color( + 0xFFDDF3FF), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(25) + : EdgeInsets.all(10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: Responsive.isDesktop(context) + ? 6 + : 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + topUpPolicyName ?? '', + textAlign: TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + topUpTypeName ?? '', + textAlign: TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + ], + ))), + if (Responsive.isDesktop(context) && + _topUpSiSwitcher == true) + Expanded( + flex: 3, + child: Container( + width: 50, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + IgnorePointer( + ignoring: (topUpOpenForEnrollment == + 0 || + (topUpOpenForEnrollment != + 0 && + topUpECardDownload != + null)), + child: + DropdownButtonFormField< + String>( + onChanged: (value) { + setState(() { + topUpSiSelectedSI = + value; + }); + topUpSiCalculation( + value); + // calculationForTopUpSiSumValue( + // 'Edit'); + }, + decoration: + InputDecoration( + border: + OutlineInputBorder(), + hintText: + 'Sum Insured', + labelText: + 'Sum Insured', + contentPadding: + EdgeInsets + .symmetric( + vertical: + 5, + horizontal: + 5), + ), + value: + topUpSiSelectedSI, + items: (topUpSlabRates ?? + []) + .map< + DropdownMenuItem< + String>>( + (addOn) { + return DropdownMenuItem< + String>( + value: addOn['si'] + .toString(), + child: Text( + '₹ ${addOn['si']}'), + ); + }).toList(), + ), + ) + ], + ))), + Expanded( + flex: 3, + child: Container( + alignment: + Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Switch( + value: _topUpSiSwitcher, + onChanged: (topUpOpenForEnrollment == + 0 || + (topUpOpenForEnrollment != + 0 && + topUpECardDownload != + null)) + ? null + : (value) { + setState(() { + _topUpSiSwitcher = + value; + // Add your logic here based on the toggle state + }); + }, + activeColor: Color( + 0xFFE26728), // Color when the switch is ON + inactiveTrackColor: Colors + .grey, // Color of the switch track when OFF + ), + ], + ))), + ], + ), + if (_topUpSiSwitcher == true) + SizedBox(height: 10), + if (!Responsive.isDesktop(context) && + _topUpSiSwitcher == true) + Row( + children: [ + Expanded( + flex: 12, + child: Container( + width: 50, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + IgnorePointer( + ignoring: (topUpOpenForEnrollment == + 0 || + (topUpOpenForEnrollment != + 0 && + topUpECardDownload != + null)), + child: + DropdownButtonFormField< + String>( + onChanged: (value) { + setState(() { + topUpSiSelectedSI = + value; + }); + topUpSiCalculation( + value); + // calculationForTopUpSiSumValue( + // 'Edit'); + }, + decoration: + InputDecoration( + border: + OutlineInputBorder(), + hintText: + 'Sum Insured', + labelText: + 'Sum Insured', + contentPadding: + EdgeInsets + .symmetric( + vertical: + 5, + horizontal: + 5), + ), + value: + topUpSiSelectedSI, + items: (topUpSlabRates ?? + []) + .map< + DropdownMenuItem< + String>>( + (addOn) { + return DropdownMenuItem< + String>( + value: addOn['si'] + .toString(), + child: Text( + '₹ ${addOn['si']}'), + ); + }).toList(), + ), + ) + ], + ))), + ], + ), + if (_topUpSiSwitcher == true) + SizedBox(height: 10), + if (_topUpSiSwitcher == + true) // Add space between rows + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: + topUpMappedFamilyFloatersSi + .where((item) => + item[ + 'is_value_exist'] == + true) + .map((item) { + Map data = + item['data']; + String formattedDate = + formatDate(data['dob']); + return Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: Color( + 0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive + .isDesktop( + context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 16, + color: + Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ) + ], + ), + if (_topUpSiSwitcher == true) + SizedBox(height: 20), + if (Responsive.isDesktop(context) && + _topUpSiSwitcher == true) + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + topUpSiPremiumValue != + null + ? '₹ $topUpSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 18, + ), + ), + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + topUpSiPremiumGst != + null + ? '₹ $topUpSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 18, + ), + ), + ], + ))), + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Total Payable', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + topUpSiTotalAmt != null + ? '₹ $topUpSiTotalAmt/-' + : 'N/A', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 18, + ), + ), + ], + ))), + ], + ), + if (!Responsive.isDesktop(context) && + _topUpSiSwitcher == true) + Container( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpSiPremiumValue != + null + ? '₹ $topUpSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpSiPremiumGst != + null + ? '₹ $topUpSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Total Payable', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 5, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpSiTotalAmt != + null + ? '₹ $topUpSiTotalAmt/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + ])) + ], + ), + ), + SizedBox(height: 15), + if (topUpParentMappedFamilyFloatersSi != null) + Container( + decoration: BoxDecoration( + color: Color( + 0xFFDDF3FF), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(25) + : EdgeInsets.all(10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: Responsive.isDesktop(context) + ? 6 + : 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + topUpParentPolicyName ?? + '', + textAlign: TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + topUpParentTypeName ?? '', + textAlign: TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + ], + ))), + if (Responsive.isDesktop(context) && + _topUpParentSiSwitcher == true) + Expanded( + flex: 3, + child: Container( + width: 50, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + IgnorePointer( + ignoring: (topUpParentOpenForEnrollment == + 0 || + (topUpParentOpenForEnrollment != + 0 && + topUpParentECardDownload != + null)), + child: + DropdownButtonFormField< + String>( + onChanged: (value) { + setState(() { + topUpParentSiSelectedSI = + value; + }); + topUpParentSiCalculation( + value); + // calculationForTopUpSiSumValue( + // 'Edit'); + }, + decoration: + InputDecoration( + border: + OutlineInputBorder(), + hintText: + 'Sum Insured', + labelText: + 'Sum Insured', + contentPadding: + EdgeInsets + .symmetric( + vertical: + 5, + horizontal: + 5), + ), + value: + topUpParentSiSelectedSI, + items: (topUpParentSlabRates ?? + []) + .map< + DropdownMenuItem< + String>>( + (addOn) { + return DropdownMenuItem< + String>( + value: addOn['si'] + .toString(), + child: Text( + '₹ ${addOn['si']}'), + ); + }).toList(), + ), + ) + ], + ))), + Expanded( + flex: 3, + child: Container( + alignment: + Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Switch( + value: + _topUpParentSiSwitcher, + onChanged: (topUpParentOpenForEnrollment == + 0 || + (topUpParentOpenForEnrollment != + 0 && + topUpParentECardDownload != + null)) + ? null + : (value) { + setState(() { + _topUpParentSiSwitcher = + value; + // Add your logic here based on the toggle state + }); + }, + activeColor: Color( + 0xFFE26728), // Color when the switch is ON + inactiveTrackColor: Colors + .grey, // Color of the switch track when OFF + ), + ], + ))), + ], + ), + if (_topUpParentSiSwitcher == true) + SizedBox(height: 10), + if (!Responsive.isDesktop(context) && + _topUpParentSiSwitcher == true) + Row( + children: [ + Expanded( + flex: 12, + child: Container( + width: 50, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + IgnorePointer( + ignoring: (topUpParentOpenForEnrollment == + 0 || + (topUpParentOpenForEnrollment != + 0 && + topUpParentECardDownload != + null)), + child: + DropdownButtonFormField< + String>( + onChanged: (value) { + setState(() { + topUpParentSiSelectedSI = + value; + }); + topUpParentSiCalculation( + value); + // calculationForTopUpSiSumValue( + // 'Edit'); + }, + decoration: + InputDecoration( + border: + OutlineInputBorder(), + hintText: + 'Sum Insured', + labelText: + 'Sum Insured', + contentPadding: + EdgeInsets + .symmetric( + vertical: + 5, + horizontal: + 5), + ), + value: + topUpParentSiSelectedSI, + items: (topUpParentSlabRates ?? + []) + .map< + DropdownMenuItem< + String>>( + (addOn) { + return DropdownMenuItem< + String>( + value: addOn['si'] + .toString(), + child: Text( + '₹ ${addOn['si']}'), + ); + }).toList(), + ), + ) + ], + ))), + ], + ), + if (_topUpParentSiSwitcher == true) + SizedBox(height: 10), + if (_topUpParentSiSwitcher == + true) // Add space between rows + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: + topUpParentMappedFamilyFloatersSi + .where((item) => + item[ + 'is_value_exist'] == + true) + .map((item) { + Map data = + item['data']; + String formattedDate = + formatDate(data['dob']); + return Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: Color( + 0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive + .isDesktop( + context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 16, + color: + Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ) + ], + ), + if (_topUpParentSiSwitcher == true) + SizedBox(height: 20), + if (Responsive.isDesktop(context) && + _topUpParentSiSwitcher == true) + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + topUpParentSiPremiumValue != + null + ? '₹ $topUpParentSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 18, + ), + ), + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + topUpParentSiPremiumGst != + null + ? '₹ $topUpParentSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 18, + ), + ), + ], + ))), + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Total Payable', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + topUpParentSiTotalAmt != + null + ? '₹ $topUpParentSiTotalAmt/-' + : 'N/A', + textAlign: + TextAlign.start, + style: + GoogleFonts.poppins( + fontSize: 18, + ), + ), + ], + ))), + ], + ), + if (!Responsive.isDesktop(context) && + _topUpParentSiSwitcher == true) + Container( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpParentSiPremiumValue != + null + ? '₹ $topUpParentSiPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpParentSiPremiumGst != + null + ? '₹ $topUpParentSiPremiumGst/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Total Payable', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 5, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + topUpParentSiTotalAmt != + null + ? '₹ $topUpParentSiTotalAmt/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + ])) + ], + ), + ), + SizedBox(height: 15), + if (addOnsDependentMappedFamilyFloatersDependent != + null) + Container( + decoration: BoxDecoration( + color: Color( + 0xFFDDF3FF), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(25) + : EdgeInsets.all(10), + child: Column( + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: + Responsive.isDesktop(context) + ? 6 + : 8, + child: Container( + alignment: + Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment + .start, + children: [ + Text( + addOnsDependentPolicyName ?? + '', + textAlign: + TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + 'Group Medical Coverage - Dependent AddOns', + textAlign: + TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + ], + ))), + if (Responsive.isDesktop(context) && + _addOnsDependentSwitcher) + Expanded( + flex: 3, + child: Container( + width: 50, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + IgnorePointer( + ignoring: (addOnsDependentOpenForEnrollment == + 0 || + (addOnsDependentOpenForEnrollment != + 0 && + addOnsDependentECardDownload != + null)), + child: + DropdownButtonFormField< + String>( + onChanged: (value) { + setState(() { + addOnsSelectedDependent = + value; + }); + addOnsDependentCalculation( + value); + // calculationForDependentSumValue( + // 'Edit'); + }, + decoration: + InputDecoration( + border: + OutlineInputBorder(), + hintText: + 'Sum Insured', + labelText: + 'Sum Insured', + contentPadding: + EdgeInsets.symmetric( + vertical: + 5, + horizontal: + 5), + ), + value: + addOnsSelectedDependent, + items: (addOnsDependentSlabRates ?? + []) + .map< + DropdownMenuItem< + String>>( + (addOn) { + return DropdownMenuItem< + String>( + value: addOn[ + 'si'] + .toString(), + child: Text( + '₹ ${addOn['si']}'), + ); + }).toList(), + ), + ) + ], + ))), + Expanded( + flex: 3, + child: Container( + alignment: + Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Switch( + value: + _addOnsDependentSwitcher, + onChanged: (addOnsDependentOpenForEnrollment == + 0 || + (addOnsDependentOpenForEnrollment != + 0 && + addOnsDependentECardDownload != + null)) + ? null + : (value) { + setState(() { + _addOnsDependentSwitcher = + value; + // Add your logic here based on the toggle state + }); + }, + activeColor: Color( + 0xFFE26728), // Color when the switch is ON + inactiveTrackColor: Colors + .grey, // Color of the switch track when OFF + ), + ], + ))), + ], + ), + if (_addOnsDependentSwitcher == true) + SizedBox(height: 10), + if (!Responsive.isDesktop(context) && + _addOnsDependentSwitcher == true) + Row( + children: [ + Expanded( + flex: 3, + child: Container( + width: 50, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + IgnorePointer( + ignoring: (addOnsDependentOpenForEnrollment == + 0 || + (addOnsDependentOpenForEnrollment != + 0 && + addOnsDependentECardDownload != + null)), + child: + DropdownButtonFormField< + String>( + onChanged: (value) { + setState(() { + addOnsSelectedDependent = + value; + }); + addOnsDependentCalculation( + value); + // calculationForDependentSumValue( + // 'Edit'); + }, + decoration: + InputDecoration( + border: + OutlineInputBorder(), + hintText: + 'Sum Insured', + labelText: + 'Sum Insured', + contentPadding: + EdgeInsets.symmetric( + vertical: + 5, + horizontal: + 5), + ), + value: + addOnsSelectedDependent, + items: (addOnsDependentSlabRates ?? + []) + .map< + DropdownMenuItem< + String>>( + (addOn) { + return DropdownMenuItem< + String>( + value: addOn[ + 'si'] + .toString(), + child: Text( + '₹ ${addOn['si']}'), + ); + }).toList(), + ), + ) + ], + ))), + ], + ), + SizedBox(height: 20), + if (_addOnsDependentSwitcher == true) + Column( + children: familyFloaterContainers, + ), + if (_addOnsDependentSwitcher) + SizedBox(height: 20), + if (Responsive.isDesktop(context) && + _addOnsDependentSwitcher) + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + addOnDependentPremiumValue != + null + ? '₹ $addOnDependentPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: 18, + ), + ), + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + addOnsDependentPremiumGst != + null + ? '₹ $addOnsDependentPremiumGst/-' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: 18, + ), + ), + ], + ))), + Expanded( + flex: 5, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Total Payable', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: 20, + fontWeight: + FontWeight.w500, + ), + ), + Text( + addOnsDependentTotalAmt != + null + ? '₹ $addOnsDependentTotalAmt/-' + : 'N/A', + textAlign: + TextAlign.start, + style: GoogleFonts + .poppins( + fontSize: 18, + ), + ), + ], + ))), + ], + ), + if (!Responsive.isDesktop(context) && + _addOnsDependentSwitcher == true) + Container( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Additional Premium', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + addOnDependentPremiumValue != + null + ? '₹ $addOnDependentPremiumValue/Year' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'GST', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + addOnsDependentPremiumGst != + null + ? '₹ $addOnsDependentPremiumGst/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment + .centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + 'Total Payable', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: 18, + fontWeight: + FontWeight + .w500, + ), + ), + ], + ))), + Expanded( + flex: 5, + child: Container( + alignment: Alignment + .centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + Text( + addOnsDependentTotalAmt != + null + ? '₹ $addOnsDependentTotalAmt/-' + : 'N/A', + textAlign: + TextAlign + .start, + style: + GoogleFonts + .poppins( + fontSize: 16, + ), + ), + ], + ))), + ], + ), + ])) + ], + )), + ], + ), + )), + SizedBox(height: 16), + if (addOnsDependentMappedFamilyFloatersDependent == null && + topUpMappedFamilyFloatersSi == null && + topUpParentMappedFamilyFloatersSi == null) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 1, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Checkbox( + value: isChecked, + onChanged: (bool? value) { + setState(() { + isChecked = value!; + }); + }, + activeColor: Color(0xFFE26728), + ), + ], + ))), + Expanded( + flex: 11, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + 'I declare that the information I have provided is true and accurate to the best of my knowledge', + textAlign: Responsive.isDesktop( + context) + ? TextAlign.left + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 15, + color: Color(0xFF292929), + ), + ), + ], + ))), + ], + ), + ), + SizedBox( + height: Responsive.isDesktop(context) ? 15 : 0), + Container( + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: Responsive.isDesktop(context) + ? 150 + : 100, + alignment: Alignment.centerLeft, + child: ElevatedButton( + onPressed: () { + Navigator.pushNamed( + context, 'empDetails'); + }, + child: Text( + 'Back', + style: GoogleFonts.poppins( + color: Color(0xFFE26728)), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + side: BorderSide( + color: Color(0xFFE26728)), + ), + ), + ), + )), + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: + isChecked ? sendAddOnAPI : null, + child: Text( + 'Submit', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ), + ], + ), + )) + else + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 10, + bottom: 10, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerLeft, + child: ElevatedButton( + onPressed: () { + backFunction(); + }, + child: Text( + 'Back', + style: GoogleFonts.poppins( + color: Color(0xFFE26728)), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5), + side: + BorderSide(color: Color(0xFFE26728)), + ), + ), + ), + )), + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: + addOnsDependentMappedFamilyFloatersDependent != + null || + topUpMappedFamilyFloatersSi != + null || + topUpParentMappedFamilyFloatersSi != + null + ? () { + if (_topUpSiSwitcher == false) { + removeAddonsGmcSiToAPI(); + } else { + print('checkSiTopUp'); + checkSiTopUp(); + } + + if (_topUpParentSiSwitcher == + false) { + removeAddonsGmcParentSiToAPI(); + } else { + print('checkSiParentTopUp'); + checkSiParentTopUp(); + } + + if (_addOnsDependentSwitcher == + false) { + removeAddonsGmcDependentToAPI(); + } else { + print('checkDependentTopUp'); + checkDependentTopUp(); + sendAddonsGmcDependentToAPI(); + } + Navigator.pushNamed( + context, 'empReviewDetails'); + } + : null, + child: Text( + 'Continue ', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ), + ), + ], + ), + ), + ), + ); + } + } + + void openForm(Map floaterData, action) { + print(action); + print(floaterData); + print(relationshipOptions); + print('test'); + print(_relationShipController); + print(_memberNameController); + print(_dobController); + + dynamic popupName = floaterData['button_name']; + // Check if the action is 'Edit' + selectedRelationships = relationshipOptions + .where( + (option) => option['dependent'] == floaterData['form_type'], + ) + .toList(); + + print(selectedRelationships); + print(addOnsDependentMappedFamilyFloatersDependent); + if (action == 'Add') { + if (floaterData['form_type'] == 'parent_in_law' || + floaterData['form_type'] == 'parent') { + print('Add'); + // Filter the addOnsDependentMappedFamilyFloatersDependent list to get only the objects where is_value_exist is true + dynamic getTrueObjects = addOnsDependentMappedFamilyFloatersDependent + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + List> getTrueDataObjects = getTrueObjects + .map>( + (element) => element['data'] as Map) + .toList(); + + print(getTrueDataObjects); + + selectedRelationships.removeWhere((relationship) => + getTrueDataObjects.any((dataObject) => + dataObject['relationship'] == + relationship['relationship_name'])); + + print(selectedRelationships); + } + } + + if (action == 'Edit') { + // Set values to all fields + _relationShipController.text = floaterData['relationship'] ?? ''; + _memberNameController.text = floaterData['name'] ?? ''; + _dobController.text = floaterData['dob'] ?? ''; + // Add more fields as needed + } + + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(30.0), + ), + elevation: 0, + backgroundColor: Colors.transparent, + content: SizedBox( + width: Responsive.isDesktop(context) ? 500 : 800, + child: SingleChildScrollView( + child: Card( + elevation: 0, + child: Padding( + padding: EdgeInsets.all(30), + child: Column( + children: [ + Container( + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text(popupName ?? '', + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Color(0xFFE26728), + )), + ], + ), + ), + ), + ], + ), + SizedBox(height: 15), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: double.infinity, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + DropdownButtonFormField( + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Relationship', + labelText: 'Relationship', + contentPadding: EdgeInsets.symmetric( + vertical: 5, horizontal: 5), + ), + value: action == 'Edit' + ? _relationShipController.text + : null, + onChanged: (value) { + _relationShipController.text = value!; + }, + items: selectedRelationships + .map((relationship) { + final String relationshipName = + relationship[ + 'relationship_name'] ?? + ''; + return DropdownMenuItem( + value: relationshipName, + child: Text(relationshipName), + ); + }).toList(), + ), + ], + ), + ), + SizedBox(height: 10), + Container( + width: double.infinity, + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + child: TextFormField( + controller: _memberNameController, + onChanged: (value) => null, + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Member Full Name', + labelText: 'Member Full Name', + contentPadding: + EdgeInsets.symmetric( + vertical: 10, + horizontal: 15), + ), + validator: (value) { + if (value == null || + value.isEmpty) { + return 'Member Full Name is required'; + } + return null; + }, + ), + ), + ], + ), + ), + SizedBox(height: 10), + Container( + width: double.infinity, + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Container( + child: TextFormField( + controller: _dobController, + onTap: () { + _selectDate(context, floaterData); + }, + readOnly: true, + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'DD-MM-YYYY', + labelText: 'Date of Birth', + suffixIcon: IconButton( + icon: Icon(Icons.calendar_today), + onPressed: () { + _selectDate( + context, floaterData); + }, + ), + contentPadding: + EdgeInsets.symmetric( + vertical: 10, + horizontal: 15, + ), + ), + ), + ), + ], + ), + ), + ], + ), + SizedBox(height: 15), + Row( + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: ElevatedButton( + onPressed: () { + // Close the dialog without sending data + cancelPopUp(); + Navigator.of(context).pop(); + }, + child: Text( + 'Cancel', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: () { + // Check if any of the fields are empty + if (_relationShipController + .text.isEmpty || + _memberNameController + .text.isEmpty || + _dobController.text.isEmpty) { + ToastHelper.showWarningToast(context, + 'All fields are required'); + } else { + // Create a map to hold the form data + Map formData = { + 'relationship': + _relationShipController.text, + 'memberName': + _memberNameController.text, + 'dateOfBirth': _dobController.text, + // Add more form fields as needed + }; + + // Call the function to send form data to API + saveAddOnsDetails( + formData, floaterData, action); + + // Close the dialog + Navigator.of(context).pop(); + } + }, + child: Text( + 'Save', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + ), + ), + ], + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + ); + }, + ); + } + + List generateGmcCards(List data) { + List cards = []; + + for (var item in data) { + setState(() { + gmcPolicyName = item['Policy_Name']; + gmcFloaterTextHeading = item['floter_text_heading']; + gmcFloaterTextDescription = item['floter_text_description']; + gmcNotes = item['notes']; + gmcECardDownload = item['eCardDownload']; + // gmcSumInsured = item['Policy_Terms']['sum_insured']; + gmcMappedFamilyFloaters = item['mapped_family_floaters']; + dynamic getTrueObjects = gmcMappedFamilyFloaters + .where((element) => element['is_value_exist'] == true) + .toList(); + print('getTrueObjects'); + print(getTrueObjects); + if (getTrueObjects.length > 0) { + print('true'); + gmcSumInsured = gmcMappedFamilyFloaters[0]["data"]["basic_cover_si"]; + } else { + print('false'); + gmcSumInsured = item['Policy_Terms']['sum_insured']; + } + gmcTypeName = item['type']; + }); + print('forEach Card'); + print(gmcMappedFamilyFloaters); + dynamic getTrueObjects = gmcMappedFamilyFloaters + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + Widget card = getTrueObjects.length > 0 + ? Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + gmcPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + gmcTypeName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + if (gmcECardDownload != null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = + Uri.parse(gmcECardDownload); + // Check if the URL is valid + if (await canLaunchUrl(uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $gmcECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors.click, + child: Icon( + Icons.file_download, + color: Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + gmcFloaterTextHeading ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${gmcSumInsured != null ? gmcSumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: gmcMappedFamilyFloaters + .where((item) => item['is_value_exist'] == true) + .map((item) { + Map data = item['data']; + String formattedDate = formatDate(data['dob']); + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 18 : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ), + ], + ), + )) + : SizedBox(height: 0); + + cards.add(card); + } + + return cards; + } +} diff --git a/lib/pages/enrollment/empDetails.dart b/lib/pages/enrollment/empDetails.dart new file mode 100644 index 0000000..ae43108 --- /dev/null +++ b/lib/pages/enrollment/empDetails.dart @@ -0,0 +1,2297 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:nhance_app_pwa/customAppBar/enrollmentAppBar.dart'; +import 'package:nhance_app_pwa/pages/enrollment/service/api_service.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/toastHelper.dart'; +import '../../models/environment.dart'; +import 'package:jwt_decode/jwt_decode.dart'; +import 'package:http/http.dart' as http; +import 'package:flutter/widgets.dart'; +import 'package:flutter/services.dart'; +import 'dart:convert'; +import 'package:intl/intl.dart'; +import 'dart:io'; +import 'dart:async'; +import 'package:url_launcher/url_launcher.dart'; + +class empDetails extends StatefulWidget { + const empDetails({Key? key}) : super(key: key); + + @override + State createState() => _empDetailsState(); +} + +class _empDetailsState extends State { + late ApiService apiService; + bool isLoading = true; + dynamic _token; + dynamic empCodeString; + dynamic empPrimaryId; + dynamic gpaEmpName; + dynamic client_id; + dynamic gpaPolicies; + dynamic gpaPolicyName; + dynamic gpaGridMaster; + dynamic gpasumInsured; + dynamic gpaClintPolicyId; + dynamic gpaSlabRates = []; + dynamic gpaMappedFamilyFloaters; + dynamic gpaSelfName; + dynamic gpaSelfDob; + dynamic gpaSelfRelationship; + dynamic gpaSelfDetails; + dynamic gpaOpenForEnrollment; + dynamic gpaECardDownload; + dynamic gmcECardDownload; + int gmcOpenForEnrollment = 0; + dynamic gmcPolicies; + dynamic gmcSlabRates = []; + dynamic gmcMappedFamilyFloaters = []; + dynamic gmcSelfName; + dynamic gmcSelfDob; + dynamic gmcSelfRelationship; + dynamic gmcSelfDetails; + dynamic gmcPolicyName; + dynamic gmcNotes; + dynamic gmcGridMaster; + dynamic gmcSumInsured; + dynamic gmcFloaterTextDescription; + dynamic gmcFloaterTextHeading; + dynamic gmcTypeName; + dynamic clientName; + dynamic clientLogo; + late TextEditingController _relationShipController; + late TextEditingController _dobController; + late TextEditingController _memberNameController; + late DateTime? selectedDate; + List> relationshipOptions = []; + List> selectedRelationships = []; + List> formDataList = []; + late DateTime _selectedDate = DateTime.now(); // Define _selectedDate here + dynamic mobileNumber; + 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 gmcDataIsEmpty = 1; + dynamic gpaDataIsEmpty = 1; + dynamic hrPrimaryId; + dynamic empRefId; + dynamic empClientBranchId; + + @override + void initState() { + super.initState(); + apiService = ApiService(context); // Initialize ApiService here + _dobController = TextEditingController(); + _memberNameController = TextEditingController(); + _relationShipController = TextEditingController(); + _loadToken(); + + Future.delayed(Duration(seconds: 3), () { + setState(() { + isLoading = false; + }); + }); + } + + @override + void dispose() { + _dobController.dispose(); + _memberNameController.dispose(); + _relationShipController.dispose(); + super.dispose(); + } + + Future _loadToken() async { + print('_loadToken'); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + if (token != null && token.isNotEmpty) { + setState(() { + _token = token; + }); + // Decode the JWT token received from the API response + Map? decodedToken = Jwt.parseJwt(token); + print('decodedToken : $decodedToken'); + empClientBranchId = prefs.getString('empClientBranchId'); + empCodeString = prefs.getString('empCode'); + print('empCodeString : $empCodeString'); // Check if emp_code is correct + empPrimaryId = prefs.getString('empPrimaryId'); + gpaEmpName = prefs.getString('gpaEmpName'); + client_id = prefs.getString('client_id'); + print('client_id : $client_id'); + + if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) { + clientLogo = prefs.getString('clientLogo'); + clientName = prefs.getString('clientName'); + } else { + getClientLogoAndDetails(); + } + + // Call the API when the page enters + getSelfEmployeeProfile(); + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + fetchRelationshipList(); + } 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, 'phone'); + } + } + + Future getClientLogoAndDetails() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getClientLogoAndDetailsToApi( + client_id!, empCodeString!, empClientBranchId!); + print('check 1'); + + if (response['status'] == 'success') { + if (response.containsKey('data')) { + dynamic clientDetails = response['data']; + final SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setString('clientLogo', clientDetails['client']['client_logo']); + prefs.setString('clientName', clientDetails['client']['client_name']); + setState(() { + // dynamic clientDetails = data['data']; + // print(clientDetails); + clientName = clientDetails['client']['client_name']; + print(clientName); + clientLogo = clientDetails['client']['client_logo']; + print(clientLogo); + }); + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getSelfEmployeeProfile() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getSelfEmployeeProfileToApi( + client_id!, empCodeString!, empClientBranchId!); + + if (response['status'] == 'success') { + if (response.containsKey('data')) { + setState(() { + dynamic selfDetails = response['data']; + print(selfDetails); + mobileNumber = selfDetails['relationship']; + selfRelationship = selfDetails['relationship']; + selfName = selfDetails['name']; + selfMobile = selfDetails['mobile']; + selfDesignation = selfDetails['designation']; + selfDob = convertDateFormat(selfDetails['dob']); + selfDoj = convertDateFormat(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']; + }); + 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + String convertDateFormat(String? date) { + if (date == null || date.isEmpty) + return ''; // Return empty string if date is null or empty + + // Parse the date string to DateTime + DateTime dateTime = DateTime.parse(date); + + // Format the DateTime object to the desired format (DD-MM-YYYY) + String formattedDate = + '${dateTime.day.toString().padLeft(2, '0')}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.year}'; + + return formattedDate; + } + + Future getGpaEmpPolicyDetails(empPrimaryId) async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGpaEmpPolicyDetailsToApi( + empPrimaryId, empCodeString!, client_id!, 'GPA', empClientBranchId!); + + if (response['status'] == 'success') { + if (response.containsKey('data')) { + gpaPolicies = response['data']; + print('gpaPolicies'); + // Assuming data is a List + print(gpaPolicies); + if (gpaPolicies.isNotEmpty) { + setState(() { + // You can use gpaPolicies as needed + print('GPA Policies found: $gpaPolicies'); + gpaPolicyName = gpaPolicies['Policy_Name'].toString(); + print(gpaPolicyName); + gpasumInsured = gpaPolicies['mapped_family_floaters']['data'] + ['basic_cover_si']; + print(gpasumInsured); + gpaMappedFamilyFloaters = + gpaPolicies['mapped_family_floaters']['data']; + print(gpaMappedFamilyFloaters); + gpaSelfName = gpaMappedFamilyFloaters['name'].toString(); + // gpaSelfMobileNo = gpaMappedFamilyFloaters['mobile']; + gpaSelfDob = gpaMappedFamilyFloaters['dob'].toString(); + gpaSelfRelationship = + gpaMappedFamilyFloaters['relationship'].toString(); + gpaSelfDetails = gpaSelfRelationship + ' . ' + gpaSelfDob; + + gpaOpenForEnrollment = gpaPolicies['OpenForEnrollment']; + + gpaECardDownload = gpaPolicies['eCardDownload']; + }); + } else { + setState(() { + gpaDataIsEmpty = 0; + }); + + // ToastHelper.showErrorToast(context, 'Something went wrong'); + print('No data found in the response'); + } + } else { + // Handle other status messages if needed + // ToastHelper.showErrorToast(context, 'Something went wrong'); + print('API request failed with status: ${response['status']}'); + } + } else { + // Handle other status codes + ToastHelper.showWarningToast(context, 'Something went wrong'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcEmpPolicyDetails(empPrimaryId) async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcEmpPolicyDetailsToApi( + empPrimaryId, empCodeString!, client_id!, 'GMC', empClientBranchId!); + if (response['status'] == 'success') { + setState(() { + gmcPolicies = response['data']; + print('gmcPolicies'); + }); + // Assuming data is a List + print(gmcPolicies); + } else { + setState(() { + gmcDataIsEmpty = 0; + }); + // Handle other status messages if needed + // ToastHelper.showErrorToast( + // context, 'API request failed with status: ${data['status']}'); + print('API request failed with status: ${response['status']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future fetchRelationshipList() async { + // Replace the URL with your API endpoint + try { + final response = await apiService.fetchRelationshipListToApi(); + if (response['status'] == 'success') { + for (var item in response['data']) { + String relationshipName = item['relationship_name']; + String dependent = item['dependent']; + + relationshipOptions.add({ + 'relationship_name': relationshipName, + 'dependent': dependent, + }); + } + // final List relationships = + // List.from(data.map((item) => item['relationship_name'])); + // setState(() { + // relationshipOptions = relationships; + // }); + } else { + throw Exception('Failed to fetch relationship list'); + } + } catch (error) { + // ToastHelper.showErrorToast( + // context, 'Error fetching relationship list: $error'); + print('Error fetching relationship list: $error'); + // Handle error accordingly, e.g., show a snackbar with an error message + } + } + + Future _selectDate(BuildContext context, formType) async { + print(formType); + var ageValidation = formType['age_validation']; + int min = + int.parse(ageValidation['min']); // Parsing the string to an integer + int max = + int.parse(ageValidation['max']); // Parsing the string to an integer + print(min); + print(max); + late DateTime minDate; + late DateTime maxDate; + + final DateTime now = DateTime.now(); + + maxDate = DateTime(now.year - min, now.month, now.day); + print(maxDate); + minDate = DateTime(now.year - max, now.month, now.day); + print(minDate); + + // if (formType['form_type'] == 'child') { + // // For 'child' form type, allow 0-25 age + // minDate = DateTime(now.year - 25, now.month, now.day); + // maxDate = now; + // } else { + // // For other form types, allow 18-100 age + // minDate = DateTime(1900); + // maxDate = DateTime(now.year - 18, now.month, now.day); + // } + + // Ensure initialDate is within the range of minDate and maxDate + DateTime initialDate = + _selectedDate ?? maxDate; // Use maxDate if _selectedDate is null + initialDate = initialDate.isBefore(minDate) ? minDate : initialDate; + initialDate = initialDate.isAfter(maxDate) ? maxDate : initialDate; + + final DateTime? picked = await showDatePicker( + context: context, + initialDate: initialDate, + firstDate: minDate, + lastDate: maxDate, + selectableDayPredicate: (DateTime date) { + return date.isAfter(minDate.subtract(const Duration(days: 1))) && + date.isBefore(maxDate.add(const Duration(days: 1))); + }, + ); + + if (picked != null && picked != _selectedDate) { + setState(() { + _selectedDate = picked; + _dobController.text = DateFormat('dd-MM-yyyy').format(_selectedDate); + }); + } + } + + Future deleteItem(Map deletedItem) async { + print(deletedItem); + try { + var id = deletedItem['employee_id']; + final response = await apiService.deleteItemToApi(id); + + // Check if the request was successful (status code 200) + if (response['status'] == 'success') { + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + relationshipOptions.clear(); + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + fetchRelationshipList(); + ToastHelper.showSuccessToast(context, 'Item deleted successfully'); + print('Item deleted successfully'); + } else { + // Handle errors + ToastHelper.showErrorToast(context, 'Failed to delete item'); + print('Failed to delete item. Status code: ${response['code']}'); + print('Response body: ${response}'); + } + } catch (error) { + // Handle network errors + print('Error deleting item: $error'); + } + } + + void saveFamilyMemberDetails(Map formData, + Map floatedData, action) async { + // Construct the array of objects + print(formData); + print(floatedData); + print(action); + + final SharedPreferences prefs = await SharedPreferences.getInstance(); + dynamic primaryId; + dynamic is_createdby_hr; + if (prefs.containsKey('hrtoken')) { + primaryId = hrPrimaryId; + is_createdby_hr = 1; + } else { + primaryId = empPrimaryId; + is_createdby_hr = 0; + } + + formDataList.add({ + 'client_branch_id': empClientBranchId, + 'relationship': formData['relationship'], + 'name': formData['memberName'], + 'dob': formData['dateOfBirth'], + 'emp_code': empCodeString, + 'client_id': client_id, + 'client_policy_id': floatedData['client_policy_id'], + 'created_by': primaryId, + 'is_createdby_hr': is_createdby_hr, + // Add the 'id' field only if action is 'Edit' + if (action == 'Edit') 'id': floatedData['employee_id'], + }); + + // Convert the list of objects to JSON + // String formDataJson = jsonEncode(formDataList); + + // Prepare the API request + final response = + await apiService.saveFamilyMemberDetailsToApi(formDataList); + + // Check the response + if (response['status'] == 'success') { + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + relationshipOptions.clear(); + // Request successful, handle response + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + fetchRelationshipList(); + ToastHelper.showSuccessToast(context, 'Saved Successfully.'); + print('Form data sent successfully.'); + } else { + // Request failed, handle error + ToastHelper.showErrorToast(context, 'Failed'); + print('Failed to send form data. Error: ${response}'); + } + } + + void cancelPopUp() { + formDataList.clear(); + selectedRelationships.clear(); + _relationShipController.clear(); + _memberNameController.clear(); + _dobController.clear(); + } + + @override + Widget build(BuildContext context) { + if (gpaDataIsEmpty == 0 && gmcDataIsEmpty == 0) { + print('body if'); + print(gpaPolicies); + return Scaffold( + appBar: CustomAppBar(), + body: 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: Color(0xFFEFF3F6), + child: Column( + children: [ + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 12, + bottom: 12, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerLeft, + child: Image.network( + clientLogo ?? '', + width: 80, // Set the width here + height: 80, // Set the height here + loadingBuilder: (BuildContext context, + Widget child, + ImageChunkEvent? loadingProgress) { + if (loadingProgress == null) return child; + return Center( + child: CircularProgressIndicator( + value: + loadingProgress.expectedTotalBytes != + null + ? loadingProgress + .cumulativeBytesLoaded / + loadingProgress + .expectedTotalBytes! + : null, + ), + ); + }, + errorBuilder: (BuildContext context, + Object error, StackTrace? stackTrace) { + return Image.asset( + 'assets/Solid_gray.png', // Replace 'default_image.png' with your default image asset path + width: 80, + height: 80, + fit: BoxFit.cover, + ); + }, + ), + ), + ), + Expanded( + flex: 9, + child: Text( + clientName ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 20 : 18, + fontWeight: FontWeight.w600, + ), + ), + ) + ], + ), + ), + ), + SizedBox(height: 16), + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: MediaQuery.of(context).size.height, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 12, bottom: 12, left: 10, right: 10), + child: Center( + child: Text( + 'No Active Current policies ', + textAlign: TextAlign + .center, // Align text center within the Card + style: GoogleFonts.poppins( + fontSize: 18, + fontWeight: FontWeight.w500, + height: 5, + ), + ), + ), + ), + ), + ], + ), + ), + )); + } else { + return Scaffold( + 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: Color(0xFFEFF3F6), + child: Column( + children: [ + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 12, + bottom: 12, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerLeft, + child: Image.network( + clientLogo ?? '', + width: 80, // Set the width here + height: 80, // Set the height here + loadingBuilder: (BuildContext context, + Widget child, + ImageChunkEvent? loadingProgress) { + if (loadingProgress == null) return child; + return Center( + child: CircularProgressIndicator( + value: loadingProgress + .expectedTotalBytes != + null + ? loadingProgress + .cumulativeBytesLoaded / + loadingProgress + .expectedTotalBytes! + : null, + ), + ); + }, + errorBuilder: (BuildContext context, + Object error, StackTrace? stackTrace) { + return Image.asset( + 'assets/Solid_gray.png', // Replace 'default_image.png' with your default image asset path + width: 80, + height: 80, + fit: BoxFit.cover, + ); + }, + ), + ), + ), + Expanded( + flex: 9, + child: Text( + clientName ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 20 : 18, + fontWeight: FontWeight.w600, + ), + ), + ) + ], + ), + ), + ), + SizedBox(height: 16), + if (gpaPolicies != null && gpaPolicies.length > 0) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, + bottom: 15, + left: 25, + right: 25) + : EdgeInsets.only( + top: 10, + bottom: 10, + left: 10, + right: 10), + child: Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + gpaPolicyName ?? 'NA', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + 'Group Personal Accident Coverage ', + textAlign: + TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + if (gpaECardDownload != + null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = Uri.parse( + gpaECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl( + uri)) { + // Open the URL in the default browser + await launchUrl( + uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $gpaECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors + .click, + child: Icon( + Icons + .file_download, + color: Color( + 0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + 'Sum Insured', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${gpasumInsured != null ? gpasumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 10), + + // Container( + // padding: EdgeInsets.only( + // top: 0, bottom: 0, left: 10, right: 10), + // child: Text( + // 'This is a floater sum insured. A floater is a type ot sum insured that provides coverage to more than one member ot a tamily at the same time. Simply put, its a single insurance cover tor the entire family.', + // style: TextStyle( + // fontSize: + // Responsive.isDesktop(context) ? 14 : 11, + // color: Color(0xFF727272), + // )), + // ), + SizedBox( + height: Responsive.isDesktop(context) + ? 15 + : 15), + // Container( + // decoration: BoxDecoration( + // color: Color( + // 0xFFF9F9FB), // Set background color for the container + // borderRadius: BorderRadius.circular( + // 5), // Set border radius for the container + // ), + // padding: EdgeInsets.only( + // top: 15, bottom: 15, left: 25, right: 25), + // child: Row( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Expanded( + // flex: 12, + // child: Container( + // alignment: Alignment.centerLeft, + // child: Column( + // mainAxisAlignment: + // MainAxisAlignment.start, + // crossAxisAlignment: + // CrossAxisAlignment.start, + // children: [ + // Text( + // 'Please Note', + // textAlign: TextAlign.left, + // style: TextStyle( + // fontSize: 18, + // fontWeight: FontWeight.w600, + // ), + // ), + // Text( + // 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', + // textAlign: TextAlign.left, + // style: TextStyle( + // fontSize: 18, + // ), + // ), + // ], + // ))), + // ], + // ), + // ), + Container( + decoration: BoxDecoration( + border: Border.all( + color: + Color(0xFF000000), // Set border color + width: 1, // Set border width + ), + // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, + bottom: 15, + left: 25, + right: 25) + : EdgeInsets.only( + top: 8, + bottom: 8, + left: 10, + right: 10), + child: Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Expanded( + flex: Responsive.isDesktop(context) + ? 1 + : 2, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + padding: Responsive + .isDesktop(context) + ? EdgeInsets.all(10) + : EdgeInsets.all( + 5), // Padding around the icon + decoration: BoxDecoration( + color: Color( + 0xFF00989E), // Background color of the icon container + borderRadius: + BorderRadius.circular( + 5), // Radius of the container + ), + child: Icon( + Icons + .account_circle, // Icon data + color: Colors.white, + size: + 32, // Color of the icon + ), + ), + ], + ))), + Expanded( + flex: Responsive.isDesktop(context) + ? 9 + : 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + gpaSelfName ?? 'NA', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + Text( + gpaSelfDetails ?? 'NA', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 16, + ), + ), + ], + ))), + Expanded( + flex: 2, + child: Container( + alignment: Alignment.topRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + MouseRegion( + cursor: SystemMouseCursors + .click, + child: GestureDetector( + onTap: () { + openSelfForm('View'); + }, + child: Text( + 'View', + textAlign: + TextAlign.left, + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 16 + : 15, + color: Color( + 0xFFE26728), // Add underline decoration + ), + ), + ), + ) + ], + ))), + ], + ), + ), + ], + ), + )), + SizedBox(height: 16), + if (gmcPolicies != null && gmcPolicies.length > 0) + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ...generateCards(gmcPolicies), + ], + ), + SizedBox(height: 16), + if (gmcPolicies != null && gmcPolicies.length > 0) + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 10, + bottom: 10, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 12, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: () { + Navigator.pushNamed( + context, 'addOnsDetails'); + }, + child: Text( + 'Continue', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ), + ), + ], + ), + ), + ), + if (isLoading) + Container( + color: Color(0xFFFFFCE5), // 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 + ), + ), + ])); + } + } + + void openForm(Map floaterData, action) { + print(action); + print(floaterData); + print(relationshipOptions); + print('test'); + // Check if the action is 'Edit' + dynamic popupName = floaterData['button_name']; + + selectedRelationships = relationshipOptions + .where( + (option) => option['dependent'] == floaterData['form_type'], + ) + .toList(); + + print(selectedRelationships); + print(gmcMappedFamilyFloaters); + if (action == 'Add') { + if (floaterData['form_type'] == 'parent_in_law' || + floaterData['form_type'] == 'parent') { + print('Add'); + // Filter the addOnsDependentMappedFamilyFloatersDependent list to get only the objects where is_value_exist is true + dynamic getTrueObjects = gmcMappedFamilyFloaters + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + List> getTrueDataObjects = getTrueObjects + .map>( + (element) => element['data'] as Map) + .toList(); + + print(getTrueDataObjects); + + selectedRelationships.removeWhere((relationship) => + getTrueDataObjects.any((dataObject) => + dataObject['relationship'] == + relationship['relationship_name'])); + + print(selectedRelationships); + } + } else { + // Set values to all fields + _relationShipController.text = floaterData['relationship'] ?? ''; + _memberNameController.text = floaterData['name'] ?? ''; + _dobController.text = floaterData['dob'] ?? ''; + // Add more fields as needed + } + + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(30.0), + ), + elevation: 0, + backgroundColor: Colors.transparent, + content: SizedBox( + width: Responsive.isDesktop(context) ? 500 : 800, + child: SingleChildScrollView( + child: Card( + elevation: 0, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(15), + child: Column( + children: [ + Container( + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text(popupName ?? '', + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Color(0xFFE26728), + )), + ], + ), + ), + ), + ], + ), + SizedBox(height: 15), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: double.infinity, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + DropdownButtonFormField( + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Relationship', + labelText: 'Relationship', + contentPadding: EdgeInsets.symmetric( + vertical: 5, horizontal: 5), + ), + value: action == 'Edit' + ? _relationShipController.text + : null, + onChanged: (value) { + _relationShipController.text = value!; + }, + items: selectedRelationships + .map((relationship) { + final String relationshipName = + relationship[ + 'relationship_name'] ?? + ''; + return DropdownMenuItem( + value: relationshipName, + child: Text(relationshipName), + ); + }).toList(), + ), + ], + ), + ), + SizedBox(height: 10), + Container( + width: double.infinity, + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + child: TextFormField( + controller: _memberNameController, + onChanged: (value) => null, + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Member Full Name', + labelText: 'Member Full Name', + contentPadding: + EdgeInsets.symmetric( + vertical: 10, + horizontal: 15), + ), + validator: (value) { + if (value == null || + value.isEmpty) { + return 'Member Full Name is required'; + } + return null; + }, + ), + ), + ], + ), + ), + SizedBox(height: 10), + Container( + width: double.infinity, + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Container( + child: TextFormField( + controller: _dobController, + onTap: () { + _selectDate(context, floaterData); + }, + readOnly: true, + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'DD-MM-YYYY', + labelText: 'Date of Birth', + suffixIcon: IconButton( + icon: Icon(Icons.calendar_today), + onPressed: () { + _selectDate( + context, floaterData); + }, + ), + contentPadding: + EdgeInsets.symmetric( + vertical: 10, + horizontal: 15, + ), + ), + ), + ), + ], + ), + ), + ], + ), + SizedBox(height: 15), + Row( + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: ElevatedButton( + onPressed: () { + // Close the dialog without sending data + cancelPopUp(); + Navigator.of(context).pop(); + }, + child: Text( + 'Cancel', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: () { + if (_relationShipController + .text.isEmpty || + _memberNameController + .text.isEmpty || + _dobController.text.isEmpty) { + ToastHelper.showWarningToast( + context, + 'All fields are required'); + } else { + Map formData = { + 'relationship': + _relationShipController.text, + 'memberName': + _memberNameController.text, + 'dateOfBirth': + _dobController.text, + + // Add more form fields as needed + }; + + // Call the function to send form data to API + saveFamilyMemberDetails( + formData, floaterData, action); + + // Close the dialog + Navigator.of(context).pop(); + } + }, + child: Text( + 'Save', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + ); + }, + ); + } + + void openSelfForm(action) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(30.0), + ), + elevation: 0, + backgroundColor: Colors.transparent, + content: SizedBox( + width: Responsive.isDesktop(context) ? 1000 : 800, + child: SingleChildScrollView( + child: Card( + elevation: 0, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(15), + child: Column( + children: [ + Container( + child: Column( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Text('Member Details', + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Color(0xFFE26728), + )), + ], + ), + ), + ), + ], + ), + SizedBox(height: 20), + if (Responsive.isDesktop(context)) + Row( + children: [ + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfEmpCode ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Employee ID', + labelText: 'Employee ID', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfName ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Employee Name', + labelText: 'Employee Name', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfRelationship ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Relationship', + labelText: 'Relationship', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + ], + ), + SizedBox( + height: Responsive.isDesktop(context) ? 30 : 0), + if (Responsive.isDesktop(context)) + Row( + children: [ + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfMobile ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Mobile No', + labelText: 'Mobile No', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfEmailPersonal ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Email personal', + labelText: 'Email personal', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfEmailCorporate ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Email Corporate', + labelText: 'Email Corporate', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + ], + ), + SizedBox( + height: Responsive.isDesktop(context) ? 30 : 0), + if (Responsive.isDesktop(context)) + Row( + children: [ + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: + selfGender == 'M' ? 'Male' : 'Female', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Gender', + labelText: 'Gender', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfDob ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Date of Birth', + labelText: 'Date of Birth', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + SizedBox(width: 10), + Expanded( + flex: 4, + child: TextFormField( + readOnly: true, + initialValue: selfDoj ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Date of Joining', + labelText: 'Date of Joining', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ), + ], + ), + SizedBox( + height: Responsive.isDesktop(context) ? 30 : 0), + if (!Responsive.isDesktop(context)) + ListView(shrinkWrap: true, children: [ + TextFormField( + readOnly: true, + initialValue: selfEmpCode ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Employee ID', + labelText: 'Employee ID', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfName ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Employee Name', + labelText: 'Employee Name', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfRelationship ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Relationship', + labelText: 'Relationship', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfMobile ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Mobile No', + labelText: 'Mobile No', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfEmailPersonal ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Email personal', + labelText: 'Email personal', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfEmailCorporate ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Email Corporate', + labelText: 'Email Corporate', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: + selfGender == 'M' ? 'Male' : 'Female', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Gender', + labelText: 'Gender', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfDob ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Date of Birth', + labelText: 'Date of Birth', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + SizedBox(height: 15), + TextFormField( + readOnly: true, + initialValue: selfDoj ?? '', + decoration: InputDecoration( + border: OutlineInputBorder(), + hintText: 'Date of Joining', + labelText: 'Date of Joining', + contentPadding: EdgeInsets.symmetric( + vertical: 10, horizontal: 15), + ), + ), + ]), + SizedBox(height: 15), + Row( + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text( + 'Close', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + ); + }, + ); + } + + List generateCards(List data) { + List cards = []; + + for (var item in data) { + print('item'); + print(item); + setState(() { + gmcPolicyName = item['Policy_Name']; + gmcFloaterTextHeading = item['floter_text_heading']; + gmcFloaterTextDescription = item['floter_text_description']; + gmcNotes = item['notes']; + gmcECardDownload = item['eCardDownload']; + + gmcMappedFamilyFloaters = item['mapped_family_floaters']; + dynamic getTrueObjects = gmcMappedFamilyFloaters + .where((element) => element['is_value_exist'] == true) + .toList(); + print('getTrueObjects'); + print(getTrueObjects); + if (getTrueObjects.length > 0) { + print('true'); + gmcSumInsured = gmcMappedFamilyFloaters[0]["data"]["basic_cover_si"]; + } else { + print('false'); + gmcSumInsured = item['Policy_Terms']['sum_insured']; + } + String intOpenForEnrollment = item['OpenForEnrollment']; + gmcOpenForEnrollment = int.parse(intOpenForEnrollment); + gmcTypeName = item['type']; + }); + + List familyFloaterContainers = []; + for (var floater in gmcMappedFamilyFloaters) { + bool isValueExist = floater['is_value_exist']; + Map floaterData = floater['data']; + + if (isValueExist) { + familyFloaterContainers.add( + Container( + decoration: BoxDecoration( + border: Border.all( + color: Color(0xFF000000), + width: 1, + ), + borderRadius: BorderRadius.circular(5), + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(15) + : EdgeInsets.only(top: 8, bottom: 8, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: Responsive.isDesktop(context) ? 1 : 2, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(10) + : EdgeInsets.all(5), + decoration: BoxDecoration( + color: Color(0xFF00989E), + borderRadius: BorderRadius.circular(5), + ), + child: Icon( + Icons.account_circle, + color: Colors.white, + size: 32, + ), + ), + ], + ), + ), + ), + SizedBox(width: Responsive.isDesktop(context) ? 5 : 0), + Expanded( + flex: Responsive.isDesktop(context) ? 9 : 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + floaterData['name'] ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 18 : 16, + fontWeight: FontWeight.w600, + ), + ), + Text( + '${floaterData['relationship']} - ${floaterData['dob']}', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 18 : 16, + ), + ), + ], + ), + ), + ), + if (gmcOpenForEnrollment != 0) + if (gmcECardDownload == null) + if (isValueExist && floaterData['relationship'] != 'Self') + Expanded( + flex: Responsive.isDesktop(context) ? 1 : 2, + child: Container( + alignment: Alignment.topRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: () { + deleteItem(floaterData); + }, + child: Text( + 'Delete', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 16 + : 15, + color: Color( + 0xFFE26728), // Add underline decoration + ), + ), + ), + ) + ], + ), + ), + ), + if (gmcOpenForEnrollment != 0) + if (gmcECardDownload == null) + Expanded( + flex: (isValueExist && + floaterData['relationship'] != 'Self') + ? Responsive.isDesktop(context) + ? 1 + : 2 + : Responsive.isDesktop(context) + ? 2 + : 4, + child: Container( + alignment: Alignment.topRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + MouseRegion( + cursor: SystemMouseCursors.click, + child: GestureDetector( + onTap: () { + if (floaterData['relationship'] == 'Self') { + openSelfForm('View'); + } else { + openForm(floaterData, 'Edit'); + } + }, + child: Text( + floaterData['relationship'] == 'Self' + ? 'View' + : 'Edit', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 16 + : 15, + color: Color( + 0xFFE26728), // Add underline decoration + ), + ), + ), + ) + ], + ), + ), + ), + ], + ), + ), + ); + } else { + familyFloaterContainers.add(MouseRegion( + cursor: SystemMouseCursors.click, // Set cursor to pointer + child: GestureDetector( + onTap: () { + // Handle the click event to open the form + if (gmcOpenForEnrollment != 0) { + if (gmcECardDownload == null) { + openForm(floaterData, 'Add'); + } + } + }, + child: Container( + decoration: BoxDecoration( + border: Border.all( + color: Color(0xFF000000), + width: 1, + ), + borderRadius: BorderRadius.circular(5), + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(12) + : EdgeInsets.all(10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: Responsive.isDesktop(context) ? 1 : 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + padding: EdgeInsets.all(5), + decoration: BoxDecoration( + color: Color(0xFF6A6A6A), + borderRadius: BorderRadius.circular(5), + ), + child: Icon( + Icons.person_add, + color: Colors.white, + size: 20, + ), + ), + ], + ), + ), + ), + SizedBox(width: Responsive.isDesktop(context) ? 5 : 10), + Expanded( + flex: Responsive.isDesktop(context) ? 11 : 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + floaterData['button_name'] ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 22 : 18, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + ), + ), + ], + ), + ), // Replace YourChildWidget with the widget you want to wrap + ), + )); + } + familyFloaterContainers.add(SizedBox(height: 15)); + } + + Widget card = Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + gmcPolicyName ?? 'NA', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + gmcTypeName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + if (gmcECardDownload != null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = + Uri.parse(gmcECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl(uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $gmcECardDownload'); + } + }, + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: Icon( + Icons.file_download, + color: Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + gmcFloaterTextHeading ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${gmcSumInsured != null ? gmcSumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 10), + Container( + padding: + EdgeInsets.only(top: 0, bottom: 0, left: 10, right: 10), + child: Text(gmcFloaterTextDescription, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 14 : 11, + color: Color(0xFF727272), + )), + ), + SizedBox(height: 15), + Container( + decoration: BoxDecoration( + color: Color( + 0xFFF9F9FB), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Please Note', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 14, + fontWeight: FontWeight.w600, + ), + ), + Text( + gmcNotes ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 15, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: + EdgeInsets.only(top: 0, bottom: 0, left: 15, right: 15), + child: Text('Please review your enrolled dependents.', + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 18 : 16, + color: Color(0xFF181818), + fontWeight: FontWeight.w500, + )), + ), + SizedBox(height: 15), + Column( + children: familyFloaterContainers, + ), + ], + ), + )); + + cards.add(card); + } + + return cards; + } +} diff --git a/lib/pages/enrollment/empReview.dart b/lib/pages/enrollment/empReview.dart new file mode 100644 index 0000000..c808533 --- /dev/null +++ b/lib/pages/enrollment/empReview.dart @@ -0,0 +1,2518 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:intl/intl.dart'; +import 'package:nhance_app_pwa/customAppBar/enrollmentAppBar.dart'; +import 'package:nhance_app_pwa/pages/enrollment/service/api_service.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:jwt_decode/jwt_decode.dart'; +import 'package:http/http.dart' as http; +import 'package:flutter/widgets.dart'; +import 'package:flutter/services.dart'; +import 'dart:convert'; +import 'package:url_launcher/url_launcher.dart'; + +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/toastHelper.dart'; + +class empReviewDetails extends StatefulWidget { + const empReviewDetails({Key? key}) : super(key: key); + + @override + State createState() => _empReviewDetailsState(); +} + +class _empReviewDetailsState extends State { + late ApiService apiService; + bool isChecked = false; // Declare the _isSwitched variable here + dynamic _token; + dynamic empCodeString; + dynamic empPrimaryId; + dynamic gpaEmpName; + dynamic client_id; + dynamic gpaPolicies; + dynamic gpaPolicyName; + dynamic gpaGridMaster; + dynamic gmcPolicies; + dynamic gpasumInsured; + dynamic gpaClintPolicyId = 0; + dynamic gpaMappedFamilyFloaters = []; + dynamic gpaSelfName; + dynamic gpaSelfDob; + dynamic gpaSelfRelationship; + dynamic gpaSelfDetails; + dynamic gpaECardDownload; + dynamic gmcECardDownload; + dynamic gmcClintPolicyId = 0; + dynamic gmcMappedFamilyFloaters = []; + dynamic gmcSelfName; + dynamic gmcSelfDob; + dynamic gmcSelfRelationship; + dynamic gmcSelfDetails; + dynamic gmcPolicyName; + dynamic gmcNotes; + dynamic gmcSumInsured; + dynamic gmcTypeName; + dynamic clientName; + dynamic clientLogo; + dynamic addOnsDependentMappedFamilyFloatersArray; + dynamic addOnsDependentClientPolicyId; + dynamic gmcAddOnsselectedSI; + dynamic gmcAddOnsselectedDependent; + dynamic gmcFloaterTextDescription; + dynamic gmcFloaterTextHeading; + dynamic dependentValue; + dynamic siValue; + dynamic addOnsDependentSumInsured; + dynamic addOnsDependentPolicyName; + dynamic addOnsFloaterTextHeading; + dynamic addOnsDependentECardDownload; + dynamic addOnsFamilyFloater; + late DateTime? selectedDate; + int totalPayableAmt = 0; + List> relationshipOptions = []; + List> selectedRelationships = []; + List> formDataList = []; + dynamic topUpMappedFamilyFloatersSi; + dynamic topUpMappedFamilyFloatersSiArray; + dynamic topUpClientPolicyId; + dynamic topUpSlabRates; + dynamic topUpFamilyFloater; + dynamic topUpPolicyName; + dynamic topUpTypeName; + int topUpSiPremiumValue = 0; + int topUpSiPremiumGst = 0; + int topUpSiTotalAmt = 0; + int topUpParentSiPremiumValue = 0; + int topUpParentSiPremiumGst = 0; + int topUpParentSiTotalAmt = 0; + int addOnDependentPremiumValue = 0; + int addOnsDependentPremiumGst = 0; + int addOnsDependentTotalAmt = 0; + dynamic topUpSiValue; + dynamic topUpSiSelectedSI; + dynamic topUpSumInsured; + dynamic topUpFloaterTextHeading; + dynamic topUpECardDownload; + int showHideTopUpCard = 0; + int showHideAddOnsCard = 0; + int showHideTopUpParentCard = 0; + dynamic iAgreeForAddOn = []; + dynamic topUpSiParentPolicies = []; + dynamic topUpParentClientPolicyId; + dynamic topUpParentSlabRates; + dynamic topUpParentPolicyName; + dynamic topUpParentFamilyFloater; + dynamic topUpParentMappedFamilyFloatersSi; + dynamic topUpParentECardDownload; + dynamic topUpParentSiValue; + dynamic topUpParentSiSelectedSI; + dynamic topUpParentTypeName; + dynamic topUpParentFloterTextHeading; + int topUpParentOpenForEnrollment = 0; + int activeSiData = 0; + int activeSiParentData = 0; + int activeDependentData = 0; + int activePremiumSummary = 0; + dynamic gmcDataIsEmpty = 1; + dynamic gpaDataIsEmpty = 1; + dynamic empClientBranchId; + + @override + void initState() { + super.initState(); + apiService = ApiService(context); // Initialize ApiService here + _loadToken(); + } + + @override + void dispose() { + super.dispose(); + } + + String formatDate(String inputDate) { + // Parse the input date string + DateTime dateTime = DateFormat('dd-MM-yyyy').parse(inputDate); + + // Format the date to the desired format + String formattedDate = DateFormat('dd MMM yyyy').format(dateTime); + + return formattedDate; + } + + Future _loadToken() async { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + if (token != null && token.isNotEmpty) { + setState(() { + _token = token; + }); + empClientBranchId = prefs.getString('empClientBranchId'); + empCodeString = prefs.getString('empCode'); + print(empCodeString); // Check if emp_code is correct + empPrimaryId = prefs.getString('empPrimaryId'); + gpaEmpName = prefs.getString('gpaEmpName'); + client_id = prefs.getString('client_id'); + print(client_id); + + // print(empPrimaryId); + // Call the API when the page enters + if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) { + clientLogo = prefs.getString('clientLogo'); + clientName = prefs.getString('clientName'); + } else { + getClientLogoAndDetails(); + } + getGmcSiTopUp(); + getGmcSiParentTopUp(); + getGmcDependentAddOns(); + getGpaEmpPolicyDetails(empPrimaryId); + getGmcEmpPolicyDetails(empPrimaryId); + primarySummary(); + } 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, 'phone'); + } + } + + void primarySummary() async { + final SharedPreferences prefs = await SharedPreferences.getInstance(); + if (prefs.containsKey('siData')) { + activeSiData = 1; + String? siDataJson = prefs.getString('siData'); + print('siDataJson'); + print(siDataJson); + + List siDataList = jsonDecode(siDataJson!); + if (siDataList.isNotEmpty) { + // Access the first map in the list + Map firstSiData = siDataList.first; + // Get the value of topUpSiPremiumValue + topUpSiPremiumValue = firstSiData['topUpSiPremiumValue']; + topUpSiPremiumGst = firstSiData['topUpSiPremiumGst']; + topUpSiTotalAmt = firstSiData['topUpSiTotalAmt']; + } + } + if (prefs.containsKey('siParentData')) { + activeSiParentData = 1; + String? siParentDataJson = prefs.getString('siParentData'); + print('siParentDataJson'); + print(siParentDataJson); + + List siParentDataList = jsonDecode(siParentDataJson!); + if (siParentDataList.isNotEmpty) { + // Access the first map in the list + Map firstSiParentData = siParentDataList.first; + // Get the value of topUpSiPremiumValue + topUpParentSiPremiumValue = + firstSiParentData['topUpParentSiPremiumValue']; + topUpParentSiPremiumGst = firstSiParentData['topUpParentSiPremiumGst']; + topUpParentSiTotalAmt = firstSiParentData['topUpParentSiTotalAmt']; + } + } + if (prefs.containsKey('dependentData')) { + activeDependentData = 1; + String? dependentDataJson = prefs.getString('dependentData'); + print('dependentDataJson'); + print(dependentDataJson); + + List dependentDataList = jsonDecode(dependentDataJson!); + if (dependentDataList.isNotEmpty) { + // Access the first map in the list + Map firstDependentListData = dependentDataList.first; + // Get the value of topUpSiPremiumValue + addOnDependentPremiumValue = + firstDependentListData['addOnDependentPremiumValue']; + addOnsDependentPremiumGst = + firstDependentListData['addOnsDependentPremiumGst']; + addOnsDependentTotalAmt = + firstDependentListData['addOnsDependentTotalAmt']; + } + } + if (prefs.containsKey('siData') && + prefs.containsKey('siParentData') && + prefs.containsKey('dependentData')) { + activePremiumSummary = 0; + } else { + activePremiumSummary = 1; + } + // Calculate the sum, skipping any missing values + + if (topUpSiTotalAmt != null) totalPayableAmt += topUpSiTotalAmt; + if (topUpParentSiTotalAmt != null) totalPayableAmt += topUpParentSiTotalAmt; + if (addOnsDependentTotalAmt != null) + totalPayableAmt += addOnsDependentTotalAmt; + + // Print or use the totalAmtSum value + print('Sum of Total Amounts: $totalPayableAmt'); + } + + Future getClientLogoAndDetails() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getClientLogoAndDetailsToApi( + client_id!, empCodeString!, empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + dynamic clientDetails = response['data']; + print(clientDetails); + clientName = clientDetails['client']['client_name']; + print(clientName); + clientLogo = clientDetails['client']['client_logo']; + print(clientLogo); + } else { + // Handle other status messages if needed + print('API request failed with status: ${response['status']}'); + } + } else { + // Handle other status codes + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGpaEmpPolicyDetails(empPrimaryId) async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGpaEmpPolicyDetailsToApi( + empPrimaryId, empCodeString!, client_id!, 'GPA', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + gpaPolicies = response['data']; + print(gpaPolicies); + // Assuming data is a List + print(gpaPolicies); + if (gpaPolicies.isNotEmpty) { + setState(() { + // You can use gpaPolicies as needed + print('GPA Policies found: $gpaPolicies'); + gpaPolicyName = gpaPolicies['Policy_Name']; + print(gpaPolicyName); + gpasumInsured = gpaPolicies['mapped_family_floaters']['data'] + ['basic_cover_si']; + print(gpasumInsured); + gpaMappedFamilyFloaters = + gpaPolicies['mapped_family_floaters']['data']; + print(gpaMappedFamilyFloaters); + gpaSelfName = gpaMappedFamilyFloaters['name']; + // gpaSelfMobileNo = gpaMappedFamilyFloaters['mobile']; + gpaSelfDob = gpaMappedFamilyFloaters['dob']; + gpaSelfRelationship = gpaMappedFamilyFloaters['relationship']; + + gpaSelfDetails = gpaSelfName + + ' ~ ' + + gpaSelfRelationship + + ' ~ ' + + ' DOB : ' + + formatDate(gpaSelfDob); + // gpaGridMaster = await gpaPolicies[0]['GridMaster']; + // gpaSlabRates = await gpaPolicies[0]['SlabRates']; + + gpaClintPolicyId = gpaPolicies['ClientPolicyId']; + + gpaECardDownload = gpaPolicies['eCardDownload']; + + // gpaSelectedSI = + // gpaMappedFamilyFloaters['basic_cover_si'].toString(); + }); + } else { + setState(() { + gpaDataIsEmpty = 0; + }); + ToastHelper.showWarningToast(context, 'No data found'); + print('No data found in the response'); + } + } else { + // Handle other status messages if needed + ToastHelper.showWarningToast(context, 'Something went wrong'); + print('API request failed with status: ${response['status']}'); + } + } else { + setState(() { + gpaDataIsEmpty = 0; + }); + // Handle other status codes + ToastHelper.showErrorToast(context, 'Something went wrong'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcEmpPolicyDetails(empPrimaryId) async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcEmpPolicyDetailsToApi( + empPrimaryId, empCodeString!, client_id!, 'GMC', empClientBranchId!); + if (response['status'] == 'success') { + setState(() { + gmcPolicies = response['data']; + print('gmcPolicies'); + }); + // Assuming data is a List + print(gmcPolicies); + } else { + setState(() { + gmcDataIsEmpty = 0; + }); + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcSiTopUp() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcSiTopUpToApi( + client_id!, empCodeString!, 'GMC-SI-TOPUP', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + dynamic topUpSiPolicies = response['data']; + print(topUpSiPolicies); + if (topUpSiPolicies.isNotEmpty) { + // setState(() { + topUpClientPolicyId = + topUpSiPolicies['gmc_si_topup']['client_policy_id']; + + topUpSumInsured = topUpSiPolicies['gmc_si_topup'] + ['family_floaters_of_only_si_value']; + print(topUpSumInsured); + + if (topUpSumInsured == 0) { + showHideTopUpCard = 0; + } else { + showHideTopUpCard = 1; + } + + topUpPolicyName = + await topUpSiPolicies['gmc_si_topup']['policy_name']; + + topUpMappedFamilyFloatersSiArray = topUpSiPolicies['gmc_si_topup'] + ['family_floaters_of_only_si_array']; + print('topUpMappedFamilyFloatersSiArray'); + print(topUpMappedFamilyFloatersSiArray); + + topUpTypeName = topUpSiPolicies['gmc_si_topup']['type']; + + topUpFloaterTextHeading = + topUpSiPolicies['gmc_si_topup']['floter_text_heading']; + + topUpECardDownload = + topUpSiPolicies['gmc_si_topup']['eCardDownload']; + // }); + } else { + // ToastHelper.showErrorToast( + // context, 'No data found in the response'); + print('No data found in the response'); + } + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcSiParentTopUp() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcSiParentTopUpToApi(client_id!, + empCodeString!, 'GMC-SI-PARENT-TOPUP', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + setState(() { + topUpSiParentPolicies = response['data']; + print('topUpSiParentPolicies'); + print(topUpSiParentPolicies); + }); + if (topUpSiParentPolicies.isNotEmpty) { + // setState(() { + topUpParentClientPolicyId = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['client_policy_id']; + + topUpParentSlabRates = + await topUpSiParentPolicies['gmc_si_parent_topup']['SlabRates']; + print('topUpParentSlabRates'); + print(topUpParentSlabRates); + + topUpParentPolicyName = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['policy_name']; + + topUpParentFamilyFloater = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['policy_terms']['family_floater']; + print('topUpParentFamilyFloater'); + print(topUpParentFamilyFloater); + + topUpParentMappedFamilyFloatersSi = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['family_floaters_of_only_si_array']; + print('topUpParentMappedFamilyFloatersSi'); + print(topUpParentMappedFamilyFloatersSi); + + print('topUpECardDownload'); + topUpParentECardDownload = + topUpSiParentPolicies['gmc_si_parent_topup']['eCardDownload']; + print(topUpParentECardDownload); + String intOpenForEnrollment = + topUpSiParentPolicies['gmc_si_parent_topup'] + ['OpenForEnrollment']; + topUpParentOpenForEnrollment = int.parse(intOpenForEnrollment); + print(topUpParentOpenForEnrollment); + + topUpParentTypeName = + topUpSiParentPolicies['gmc_si_parent_topup']['type']; + + topUpParentFloterTextHeading = + topUpSiParentPolicies['gmc_si_parent_topup'] + ['floter_text_heading']; + + topUpParentSiValue = + await topUpSiParentPolicies['gmc_si_parent_topup'] + ['family_floaters_of_only_si_value']; + + if (topUpParentSiValue == 0) { + showHideTopUpParentCard = 0; + } else { + showHideTopUpParentCard = 1; + } + // }); + } else { + // ToastHelper.showErrorToast( + // context, 'No data found in the response'); + print('No data found in the response'); + } + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future getGmcDependentAddOns() async { + try { + if (client_id == null || + empCodeString == null || + empClientBranchId == null) { + return; + } + final response = await apiService.getGmcDependentAddOnsToApi(client_id!, + empCodeString!, 'GMC-DEPENDENT-ADDON', empClientBranchId!); + if (response['status'] == 'success') { + if (response.containsKey('data')) { + dynamic addOnsDependentPolicies = response['data']; + print('addOnsDependentPolicies'); + print(addOnsDependentPolicies); + if (addOnsDependentPolicies.isNotEmpty) { + // setState(() { + addOnsDependentClientPolicyId = + addOnsDependentPolicies['gmc_dependent_addon'] + ['client_policy_id']; + print(addOnsDependentClientPolicyId); + + addOnsDependentSumInsured = + addOnsDependentPolicies['gmc_dependent_addon'] + ['family_floaters_of_dependent_and_si_value']; + print(addOnsDependentSumInsured); + + if (addOnsDependentSumInsured == 0) { + showHideAddOnsCard = 0; + } else { + showHideAddOnsCard = 1; + } + + addOnsDependentPolicyName = + addOnsDependentPolicies['gmc_dependent_addon']['policy_name']; + print(addOnsDependentPolicyName); + + addOnsDependentMappedFamilyFloatersArray = + await addOnsDependentPolicies['gmc_dependent_addon'] + ['family_floaters_of_dependent_and_si_array']; + print('addOnsDependentMappedFamilyFloatersArray'); + print(addOnsDependentMappedFamilyFloatersArray); + + addOnsFloaterTextHeading = + addOnsDependentPolicies['gmc_dependent_addon'] + ['floter_text_heading']; + + addOnsDependentECardDownload = + addOnsDependentPolicies['gmc_dependent_addon']['eCardDownload']; + } else { + // ToastHelper.showErrorToast( + // context, 'No data found in the response'); + print('No data found in the response'); + } + } 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 { + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + Future sendAddOnAPI() async { + if (addOnsDependentMappedFamilyFloatersArray != null) { + dynamic getDependentTrueObjects = addOnsDependentMappedFamilyFloatersArray + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getDependentTrueObjects); + + if (getDependentTrueObjects.isNotEmpty) { + iAgreeForAddOn.add(int.parse(addOnsDependentClientPolicyId)); + } + } + + if (topUpMappedFamilyFloatersSiArray != null) { + dynamic getSiTrueObjects = topUpMappedFamilyFloatersSiArray + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getSiTrueObjects); + + if (getSiTrueObjects.isNotEmpty) { + iAgreeForAddOn.add(int.parse(topUpClientPolicyId)); + } + } + + if (topUpParentMappedFamilyFloatersSi != null) { + dynamic getSiTrueObjects = topUpParentMappedFamilyFloatersSi + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getSiTrueObjects); + + if (getSiTrueObjects.isNotEmpty) { + iAgreeForAddOn.add(int.parse(topUpParentClientPolicyId)); + } + } + + print('gpaPolicies'); + print(gpaPolicies); + print('gmcPolicies'); + print(gmcPolicies); + + if (gpaDataIsEmpty != 0) { + iAgreeForAddOn.add(int.parse(gpaClintPolicyId)); + } + + if (gmcDataIsEmpty != 0) { + for (var item in gmcPolicies) { + // Extract ClientPolicyId value from each object + String clientPolicyId = item['ClientPolicyId']; + // Convert to integer and add to iAgreeForAddOn list + iAgreeForAddOn.add(int.parse(clientPolicyId)); + } + } + print('iAgreeForAddOn'); + iAgreeForAddOn = iAgreeForAddOn.toSet().toList(); + print(iAgreeForAddOn); // Output: [90, 92, 88, 89] + + Map apiParams = { + 'emp_code': empCodeString, + 'client_policy_id': iAgreeForAddOn, + 'client_id': client_id, + }; + print(apiParams); + + // Convert the list of objects to JSON + String formDataJson = jsonEncode(apiParams); + + try { + final response = await apiService.sendAddOnToAPI(apiParams); + + if (response['status'] == 'success') { + print('response.statusCode == 200'); + ToastHelper.showSuccessToast(context, 'Saved Successfully...'); + } else { + // Handle other status codes + ToastHelper.showErrorToast(context, 'Failed to Save'); + print('Request failed with status: ${response['code']}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + @override + Widget build(BuildContext context) { + if ((gpaMappedFamilyFloaters == [] && gpaMappedFamilyFloaters == null) && + (gmcMappedFamilyFloaters == [] && gmcMappedFamilyFloaters == null)) { + return Scaffold( + appBar: CustomAppBar(), + body: SingleChildScrollView( + child: Container( + color: Color(0xFFEFF3F6), + child: Column( + children: [ + Center( + child: Text('No Data Available', + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.bold, + )), + ) + ], + ), + ), + )); + } else { + return Scaffold( + appBar: CustomAppBar(), + body: 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: Color(0xFFEFF3F6), + child: Column( + children: [ + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 12, + bottom: 12, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerLeft, + child: Image.network( + clientLogo ?? '', + width: 80, // Set the width here + height: 80, // Set the height here + loadingBuilder: (BuildContext context, + Widget child, + ImageChunkEvent? loadingProgress) { + if (loadingProgress == null) return child; + return Center( + child: CircularProgressIndicator( + value: loadingProgress.expectedTotalBytes != + null + ? loadingProgress + .cumulativeBytesLoaded / + loadingProgress.expectedTotalBytes! + : null, + ), + ); + }, + errorBuilder: (BuildContext context, Object error, + StackTrace? stackTrace) { + return Image.asset( + 'assets/Solid_gray.png', // Replace 'default_image.png' with your default image asset path + width: 80, + height: 80, + fit: BoxFit.cover, + ); + }, + ), + ), + ), + Expanded( + flex: 9, + child: Text( + clientName ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 20 : 18, + fontWeight: FontWeight.w600, + ), + ), + ) + ], + ), + ), + ), + SizedBox(height: 16), + Card( + elevation: 0, + color: Colors.white, + child: Container( + width: double.infinity, + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), // Add padding to the container + child: Column(children: [ + Row( + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Review', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 20 + : 18, + color: Color(0xFF181818), + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + Row( + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Total Payable', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + color: Color(0xFF181818), + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + '₹$totalPayableAmt/Year ', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 22 + : 18, + color: Color(0xFFE26728), + fontWeight: FontWeight.w500, + ), + ), + ], + ))), + ], + ), + ])), + ), + SizedBox(height: 16), + if (gpaPolicies != null && gpaPolicies.length > 0) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + gpaPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + 'Group Personal Accident Coverage', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + if (gpaECardDownload != null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = Uri.parse( + gpaECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl( + uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $gpaECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors + .click, + child: Icon( + Icons.file_download, + color: + Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + 'Sum Insured', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${gpasumInsured != null ? gpasumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: + Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + gpaSelfDetails ?? '', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ), + ], + ), + ), + ], + ), + )), + SizedBox(height: 16), + if (gmcPolicies != null && gmcPolicies.length > 0) + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + ...generateGmcCards(gmcPolicies), + ], + ), + SizedBox(height: 16), + if (showHideTopUpCard == 1) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Add Ons', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 16, + color: Color(0xFF181818), + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + topUpPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + 'Group Medical Coverage - Top Up', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + if (topUpECardDownload != + null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = Uri.parse( + topUpECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl( + uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $topUpECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors + .click, + child: Icon( + Icons.file_download, + color: + Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + topUpFloaterTextHeading ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${topUpSumInsured != null ? topUpSumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: topUpMappedFamilyFloatersSiArray + .where((item) => + item['is_value_exist'] == true) + .map((item) { + Map data = item['data']; + String formattedDate = + formatDate(data['dob']); + return Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: + Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ), + ], + ), + )), + SizedBox(height: showHideTopUpCard == 1 ? 16 : 0), + if (showHideTopUpParentCard == 1) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Add Ons', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 16, + color: Color(0xFF181818), + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + topUpParentPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + topUpParentTypeName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + if (topUpParentECardDownload != + null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = Uri.parse( + topUpParentECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl( + uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $topUpParentECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors + .click, + child: Icon( + Icons.file_download, + color: + Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + topUpParentFloterTextHeading ?? + '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${topUpParentSiValue != null ? topUpParentSiValue : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: topUpParentMappedFamilyFloatersSi + .where((item) => + item['is_value_exist'] == true) + .map((item) { + Map data = item['data']; + String formattedDate = + formatDate(data['dob']); + return Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: + Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ), + ], + ), + )), + SizedBox(height: showHideTopUpCard == 1 ? 16 : 0), + if (showHideAddOnsCard == 1) + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Add Ons', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 16, + color: Color(0xFF181818), + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: + Responsive.isDesktop(context) ? 9 : 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + addOnsDependentPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + 'Group Medical Coverage - Dependent AddOns', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: + FontWeight.w600, + ), + ), + if (addOnsDependentECardDownload != + null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = Uri.parse( + addOnsDependentECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl( + uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $addOnsDependentECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors + .click, + child: Icon( + Icons.file_download, + color: + Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: + Responsive.isDesktop(context) ? 3 : 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + addOnsFloaterTextHeading ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${addOnsDependentSumInsured != null ? addOnsDependentSumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: + addOnsDependentMappedFamilyFloatersArray + .where((item) => + item['is_value_exist'] == true) + .map((item) { + Map data = item['data']; + return Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: + Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} - ${data['relationship']} - ${data['dob']}', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ), + ], + ), + )), + SizedBox(height: showHideAddOnsCard == 1 ? 16 : 0), + Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Premium Summary', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop( + context) + ? 18 + : 16, + color: Color(0xFF181818), + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment + .centerLeft, // Adjust padding as needed + child: Table( + columnWidths: { + 0: FlexColumnWidth( + 2), // Adjust column width as needed + 1: FlexColumnWidth(2), + 2: FlexColumnWidth( + 2), // Adjust column width as needed + 3: FlexColumnWidth(2), + }, + children: [ + TableRow( + children: [ + TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: Text( + 'Policy ', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 16 + : 14, + fontWeight: + FontWeight.bold), + ), + ), + ), + TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: Text( + 'Additional Premium', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 16 + : 14, + fontWeight: + FontWeight.bold), + ), + ), + ), + TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: Text( + 'GST', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 16 + : 14, + fontWeight: + FontWeight.bold), + ), + ), + ), + TableCell( + child: Padding( + padding: EdgeInsets.all(8.0), + child: Text( + 'Total', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 16 + : 14, + fontWeight: + FontWeight.bold), + ), + ), + ), + ], + ), + if (activeSiData == 1) + TableRow( + children: [ + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + Responsive.isDesktop( + context) + ? topUpTypeName + : 'GMC - Top Up', + textAlign: + TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$topUpSiPremiumValue/Year', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$topUpSiPremiumGst/-', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$topUpSiTotalAmt/Year', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + ], + ), + if (activeSiParentData == 1) + TableRow( + children: [ + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + Responsive.isDesktop( + context) + ? topUpParentTypeName + : 'GMC - Parents Top Up', + textAlign: + TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$topUpParentSiPremiumValue/Year', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$topUpParentSiPremiumGst/-', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$topUpParentSiTotalAmt/Year', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + ], + ), + if (activeDependentData == 1) + TableRow( + children: [ + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + Responsive.isDesktop( + context) + ? 'Group Medical Coverage - Add Dependent' + : 'GMC - Dependent ', + textAlign: + TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$addOnDependentPremiumValue/Year', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$addOnsDependentPremiumGst/-', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + TableCell( + child: Padding( + padding: + EdgeInsets.all(8.0), + child: Text( + '₹$addOnsDependentTotalAmt/Year', + textAlign: + Responsive.isDesktop( + context) + ? TextAlign.start + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 14 + : 12), + ), + ), + ), + ], + ), + ], + ), + )) + ], + ), + ), + SizedBox(height: 10), + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'Total Payable', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop( + context) + ? 20 + : 16, + color: Color(0xFF181818), + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + '₹$totalPayableAmt/Year', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop( + context) + ? 18 + : 16, + color: Color(0xFFE26728), + fontWeight: FontWeight.w500, + ), + ), + ], + ))) + ], + ), + ), + SizedBox(height: 15), + Container( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 1, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Checkbox( + value: isChecked, + onChanged: (bool? value) { + setState(() { + isChecked = value!; + }); + }, + activeColor: Color(0xFFE26728), + ), + ], + ))), + Expanded( + flex: 11, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: + MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Text( + 'I declare that the information I have provided is true and accurate to the best of my knowledge', + textAlign: + Responsive.isDesktop(context) + ? TextAlign.left + : TextAlign.start, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop( + context) + ? 18 + : 15, + color: Color(0xFF292929), + ), + ), + ], + ))), + ], + ), + ), + SizedBox( + height: Responsive.isDesktop(context) ? 15 : 0), + Container( + child: Row( + children: [ + Expanded( + flex: 6, + child: Container( + width: 150, + height: Responsive.isDesktop(context) + ? 150 + : 100, + alignment: Alignment.centerLeft, + child: ElevatedButton( + onPressed: () async { + // Remove siData, siParentData, and dependentData from local storage + final SharedPreferences prefs = + await SharedPreferences + .getInstance(); + prefs.remove('siData'); + prefs.remove('siParentData'); + prefs.remove('dependentData'); + Navigator.pushNamed( + context, 'addOnsDetails'); + }, + child: Text( + 'Back', + style: GoogleFonts.poppins( + color: Color(0xFFE26728)), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + side: BorderSide( + color: Color(0xFFE26728)), + ), + ), + ), + )), + Expanded( + flex: 6, + child: Container( + width: 150, + height: 150, + alignment: Alignment.centerRight, + child: ElevatedButton( + onPressed: + isChecked ? sendAddOnAPI : null, + child: Text( + 'Submit', + style: GoogleFonts.poppins( + color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ), + ], + ), + )), + ], + ), + ), + ), + ); + } + } + + List generateGmcCards(List data) { + List cards = []; + + for (var item in data) { + setState(() { + gmcPolicyName = item['Policy_Name']; + gmcFloaterTextHeading = item['floter_text_heading']; + gmcFloaterTextDescription = item['floter_text_description']; + gmcNotes = item['notes']; + gmcECardDownload = item['eCardDownload']; + // gmcSumInsured = item['Policy_Terms']['sum_insured']; + gmcMappedFamilyFloaters = item['mapped_family_floaters']; + dynamic getTrueObjects = gmcMappedFamilyFloaters + .where((element) => element['is_value_exist'] == true) + .toList(); + print('getTrueObjects'); + print(getTrueObjects); + if (getTrueObjects.length > 0) { + print('true'); + gmcSumInsured = gmcMappedFamilyFloaters[0]["data"]["basic_cover_si"]; + } else { + print('false'); + gmcSumInsured = item['Policy_Terms']['sum_insured']; + } + gmcTypeName = item['type']; + }); + print('forEach Card'); + print(gmcMappedFamilyFloaters); + dynamic getTrueObjects = gmcMappedFamilyFloaters + .where((element) => element['is_value_exist'] == true) + .toList(); + + print(getTrueObjects); + + Widget card = getTrueObjects.length > 0 + ? Card( + elevation: 0, + color: Colors.white, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(30) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + gmcPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Row( + children: [ + Text( + gmcTypeName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + if (gmcECardDownload != null) + GestureDetector( + onTap: () async { + // Convert the URL string to a Uri object + Uri uri = + Uri.parse(gmcECardDownload); + + // Check if the URL is valid + if (await canLaunchUrl(uri)) { + // Open the URL in the default browser + await launchUrl(uri); + } else { + // Handle the case where the URL cannot be launched + print( + 'Could not launch $gmcECardDownload'); + } + }, + child: MouseRegion( + cursor: + SystemMouseCursors.click, + child: Icon( + Icons.file_download, + color: Color(0xFFE26728), + size: 25, + ), + ), + ), + ], + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + gmcFloaterTextHeading ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${gmcSumInsured != null ? gmcSumInsured : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only( + top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: gmcMappedFamilyFloaters + .where((item) => item['is_value_exist'] == true) + .map((item) { + Map data = item['data']; + String formattedDate = formatDate(data['dob']); + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 18 : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ), + ], + ), + )) + : SizedBox(height: 0); + + cards.add(card); + } + + return cards; + } +} diff --git a/lib/pages/enrollment/oldPolicy.dart b/lib/pages/enrollment/oldPolicy.dart new file mode 100644 index 0000000..787bd4f --- /dev/null +++ b/lib/pages/enrollment/oldPolicy.dart @@ -0,0 +1,388 @@ +import 'dart:convert'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.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/enrollmentAppBar.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:http/http.dart' as http; + +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/toastHelper.dart'; +import '../../models/environment.dart'; + +class oldPolicy extends StatefulWidget { + const oldPolicy({Key? key}) : super(key: key); + + @override + State createState() => _oldPolicyState(); +} + +class _oldPolicyState extends State { + dynamic _token; + dynamic empCodeString; + dynamic empPrimaryId; + dynamic client_id; + dynamic gpaEmpName; + dynamic oldPolicyList; + dynamic oldPolicyName; + dynamic oldPolicyClientId; + dynamic oldPolicyClientPolicyId; + dynamic oldPolicySiGstValue; + dynamic oldPolicySiPremiumValue; + dynamic oldPolicySiValue; + dynamic oldPolicyType; + dynamic oldPolicyEmployeePolicy; + dynamic oldPolicyDataIsEmpty = 1; + dynamic oldPolicyTypeHeading; + dynamic oldPolicyFloaterTextHeading; + dynamic oldPolicyStartDate; + dynamic oldPolicyEndDate; + dynamic empClientBranchId; + + @override + void initState() { + super.initState(); + _loadToken(); + } + + @override + void dispose() { + super.dispose(); + } + + Future _loadToken() async { + print('_loadToken'); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + if (token != null && token.isNotEmpty) { + setState(() { + _token = token; + }); + // Decode the JWT token received from the API response + Map? decodedToken = Jwt.parseJwt(token); + print(decodedToken); + empClientBranchId = prefs.getString('empClientBranchId'); + empCodeString = prefs.getString('empCode'); + print(empCodeString); // Check if emp_code is correct + empPrimaryId = prefs.getString('empPrimaryId'); + gpaEmpName = prefs.getString('gpaEmpName'); + client_id = prefs.getString('client_id'); + print(client_id); + getOldPolicyDetails(); + } 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, 'phone'); + } + } + + Future getOldPolicyDetails() async { + var url = Uri.parse(Environment.apiUrl + + 'getEmployeeActiveOrInactivePolicy?client_id=$client_id&emp_code=$empCodeString&type=Inactive&client_branch_id=$empClientBranchId'); + try { + var response = await http.get( + url, + headers: { + 'Authorization': + 'Bearer $_token', // Add token to the Authorization header + }, + ); + if (response.statusCode == 200) { + Map data = json.decode(response.body); + if (data['status'] == 'success') { + setState(() { + oldPolicyList = data['data']; + print('gmcPolicies'); + }); + // Assuming data is a List + print(oldPolicyList); + } else { + setState(() { + oldPolicyDataIsEmpty = 0; + }); + // Handle other status messages if needed + // ToastHelper.showErrorToast( + // context, 'API request failed with status: ${data['status']}'); + print('API request failed with status: ${data['status']}'); + } + } else { + setState(() { + oldPolicyDataIsEmpty = 0; + }); + // Handle other status codes + // ToastHelper.showErrorToast( + // context, 'Request failed with status: ${response.statusCode}'); + print('Request failed with status: ${response.statusCode}'); + } + } catch (e) { + // Handle exceptions + print('Exception occurred: $e'); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: CustomAppBar(), + body: _buildBody(), + ); + } + + Widget _buildBody() { + if (oldPolicyList == null) { + return Center(child: _buildNoDataWidget()); + } else if (oldPolicyList!.isEmpty) { + return Center(child: _buildNoDataWidget()); + } else { + return _buildPolicyListWidget(); + } + } + + Widget _buildNoDataWidget() { + return SingleChildScrollView( + child: Container( + color: Color(0xFFEFF3F6), + child: Column( + children: [ + Center( + child: Text('No Data Available'), + ) + ], + ), + ), + ); + } + + Widget _buildPolicyListWidget() { + return 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: Color(0xFFEFF3F6), + child: Column( + children: [ + if (oldPolicyDataIsEmpty == 1) + ...generateGmcCards(oldPolicyList), + ], + ), + ), + ) + ], + ); + } + + List generateGmcCards(List data) { + List cards = []; + + print('data'); + print(data); + + for (var item in data) { + setState(() { + oldPolicyName = item['policy_name']; + oldPolicyTypeHeading = item['heading']; + oldPolicyFloaterTextHeading = item['floter_text_heading']; + oldPolicyClientId = item['client_id']; + oldPolicyClientPolicyId = item['client_policy_id']; + oldPolicySiGstValue = item['si_gst_value']; + oldPolicySiPremiumValue = item['si_premium_value']; + oldPolicySiValue = item['si_value']; + oldPolicyType = item['policy_type']; + oldPolicyStartDate = item['policy_start_date']; + oldPolicyEndDate = item['policy_end_date']; + oldPolicyEmployeePolicy = item['EmployeePolicy']; + }); + + Widget card = Card( + elevation: 0, + child: Padding( + padding: Responsive.isDesktop(context) + ? EdgeInsets.all(20) + : EdgeInsets.all(10), + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFF1DD), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 8, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + oldPolicyName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Text( + oldPolicyTypeHeading ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + Expanded( + flex: 4, + child: Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + oldPolicyFloaterTextHeading ?? '', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 14, + ), + ), + Text( + '₹ ${oldPolicySiValue != null ? oldPolicySiValue : 'NA'}', + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + ), + ), + ], + ))), + ], + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 0, bottom: 0, left: 15, right: 15) + : EdgeInsets.only(top: 0, bottom: 0, left: 5, right: 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: oldPolicyEmployeePolicy.map((data) { + String formattedDate = formatDate(data['dob']); + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Icons.arrow_right, + color: Color(0xFFE26728)), // Arrow icon + SizedBox( + width: Responsive.isDesktop(context) + ? 10 + : 5), // Space between icon and text + Expanded( + child: Text( + '${data['name']} ~ ${data['relationship']} ~ DOB : $formattedDate', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 18 : 16, + color: Color(0xFF232526), + ), + ), + ), + ], + ); + }).toList(), + ), + ), + SizedBox(height: 15), + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 0, bottom: 0, left: 25, right: 25) + : EdgeInsets.only(top: 0, bottom: 0, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + RichText( + text: TextSpan( + text: 'Policy Period : ', + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Color(0xFF232526), + ), + children: [ + TextSpan( + text: + '$oldPolicyStartDate To $oldPolicyEndDate', + style: GoogleFonts.poppins( + fontSize: 14, + color: Color(0xFF232526), + ), + ), + ], + ), + ), + ], + ), + ), + ), + ], + ), + ), + ], + ), + )); + + cards.add(card); + cards.add(SizedBox(height: 10)); + } + + return cards; + } + + String formatDate(String inputDate) { + // Parse the input date string + DateTime dateTime = DateTime.parse(inputDate); + + // Format the date to 'dd MMMM yyyy' + String formattedDate = DateFormat('dd MMMM yyyy').format(dateTime); + + return formattedDate; + } +} diff --git a/lib/pages/enrollment/service/api_service.dart b/lib/pages/enrollment/service/api_service.dart new file mode 100644 index 0000000..76db60b --- /dev/null +++ b/lib/pages/enrollment/service/api_service.dart @@ -0,0 +1,502 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'package:shared_preferences/shared_preferences.dart'; +import 'dart:convert'; + +import '../../../customAppBar/toastHelper.dart'; +import '../../../models/environment.dart'; + +class ApiService { + final BuildContext context; + String? _token; + String? _hrtoken; + bool _isSessionOutToastShown = false; // Flag to track toast message + + ApiService(this.context) { + _initializeToken(); + } + + Future _initializeToken() async { + final prefs = await SharedPreferences.getInstance(); + _token = prefs.getString('token') ?? ''; + final hrprefs = await SharedPreferences.getInstance(); + _hrtoken = hrprefs.getString('hrtoken') ?? ''; + } + + Future> getClientLogoAndDetailsToApi( + String clientId, String empCode, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getClientDetails?client_id=$clientId&emp_code=$empCode&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getSelfEmployeeProfileToApi( + String clientId, String empCode, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getEmployeeProfile?emp_code=$empCode&client_id=$clientId&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> fetchRelationshipListToApi() async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse('${Environment.apiUrl}relationshipList'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getGpaEmpPolicyDetailsToApi(String empPrimaryId, + String empCode, String clientId, String policy, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getEmployeePolicy?id=$empPrimaryId&emp_code=$empCode&client_id=$clientId&policy=$policy&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getGmcEmpPolicyDetailsToApi(String empPrimaryId, + String empCode, String clientId, String policy, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getEmployeePolicy?id=$empPrimaryId&emp_code=$empCode&client_id=$clientId&policy=$policy&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getGmcSiTopUpToApi( + String client_id, String emp_code, String policy, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getAddOnPolicy?client_id=$client_id&emp_code=$emp_code&policy=$policy&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getGmcSiParentTopUpToApi( + String client_id, String emp_code, String policy, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getAddOnPolicy?client_id=$client_id&emp_code=$emp_code&policy=$policy&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getGmcDependentAddOnsToApi( + String client_id, String emp_code, String policy, String branchID) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getAddOnPolicy?client_id=$client_id&emp_code=$emp_code&policy=$policy&client_branch_id=$branchID'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> removeAddonsGmcDependentToAPI( + String empCodeString, String addOnsDependentClientPolicyId) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}removeEmpAndEmpPolicyData?emp_code=$empCodeString&client_policy_id=$addOnsDependentClientPolicyId'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> removeAddonsGmcSiToAPI( + String empCodeString, String topUpClientPolicyId) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}removeEmpAndEmpPolicyData?emp_code=$empCodeString&client_policy_id=$topUpClientPolicyId'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> removeAddonsGmcParentSiToAPI( + String empCodeString, String topUpParentClientPolicyId) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}removeEmpAndEmpPolicyData?emp_code=$empCodeString&client_policy_id=$topUpParentClientPolicyId'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> deleteItemToApi(id) async { + print(_token); + if (_token == null) { + await _initializeToken(); + } + final url = Uri.parse('${Environment.apiUrl}deleteDependence?id=$id'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> saveFamilyMemberDetailsToApi( + List> formDataList) async { + print('saveFamilyMemberDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = Uri.parse('${Environment.apiUrl}addEmployeeAndDependence'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> saveAddOnsDetailsToApi( + List> formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = Uri.parse('${Environment.apiUrl}addEmployeeAndDependence'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> sendAddonsGmcDependentToAPI( + List> formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = + Uri.parse('${Environment.apiUrl}createOrUpdateEmployeePolicySiAmount'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> sendAddonsGmcSiToAPI( + List> formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = + Uri.parse('${Environment.apiUrl}createOrUpdateEmployeePolicySiAmount'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> sendAddonsGmcParentSiToAPI( + List> formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = + Uri.parse('${Environment.apiUrl}createOrUpdateEmployeePolicySiAmount'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> sendAddOnToAPI( + Map formData) async { + print('sendAddOnToAPI API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = Uri.parse('${Environment.apiUrl}iAgreeForAddOn'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formData); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> topUpSiCalculationToAPI(formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = Uri.parse('${Environment.apiUrl}calculatePremium'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> topUpParentSiCalculationToAPI( + formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = Uri.parse('${Environment.apiUrl}calculatePremium'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + Future> addOnsDependentCalculationToAPI( + formDataList) async { + print('saveAddOnsDetailsToApi API SERVICE'); + if (_token == null) { + await _initializeToken(); + } + + final url = Uri.parse('${Environment.apiUrl}calculatePremium'); + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + 'Content-Type': 'application/json', // Ensure content type is JSON + }; + + // Convert formDataList to JSON string + final formDataJson = jsonEncode(formDataList); + + // Send formDataJson as the body + final response = await _makePostRequest(url, formDataJson, headers); + return response; + } + + //HR API STARTS + + Future> getCashDepositDetailsToApi( + String clintID, String empRefId) async { + print(_hrtoken); + if (_hrtoken == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getCashDepositData?client_id=$clintID&client_branch_id=$empRefId'); + final headers = { + 'Authorization': 'Bearer $_hrtoken' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + Future> getEmployeeAndDependenceToApi( + String clintID, String getPolicyNo, String empRefId) async { + print(_hrtoken); + if (_hrtoken == null) { + await _initializeToken(); + } + final url = Uri.parse( + '${Environment.apiUrl}getEmployeeAndDependenceByClientId?client_id=$clintID&client_policy_id=$getPolicyNo&client_branch_id=$empRefId'); + final headers = { + 'Authorization': 'Bearer $_hrtoken' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } + + // Future> getTrackClaimsList( + // String empMobileNo, String empCode) async { + // final url = Uri.parse( + // '${Environment.apiUrlTicket}/ticket/get_ticket_data?emp_code=$empCode&mobile_number=$empMobileNo'); + // final response = await _makeGetRequest(url, { + // 'Token': Environment.ticketToken, + // }); + // return response; + // } + // + // Future> fetchDepartmentList() async { + // final url = Uri.parse('${Environment.apiUrlTicket}/departments'); + // final response = await _makeGetRequest(url, { + // 'Token': Environment.ticketToken, + // }); + // return response; + // } + // + // Future> sendFormDataToApi( + // Map formData) async { + // final url = Uri.parse('${Environment.apiUrlTicket}/tickets/create'); + // // Convert formData to Map + // Map stringFormData = + // formData.map((key, value) => MapEntry(key, value.toString())); + // final response = await _makePostRequest(url, stringFormData, { + // 'Content-Type': 'application/x-www-form-urlencoded', + // 'Token': Environment.ticketToken, + // }); + // return response; + // } + // + // Future> sendClaimsMessageToApi( + // Map formData) async { + // final url = Uri.parse('${Environment.apiUrlTicket}/messages/create'); + // // Convert formData to Map + // Map stringFormData = + // formData.map((key, value) => MapEntry(key, value.toString())); + // final response = await _makePostRequest(url, stringFormData, { + // 'Content-Type': 'application/x-www-form-urlencoded', + // 'Token': Environment.ticketToken, + // }); + // return response; + // } + + Future> _makeGetRequest( + Uri url, Map headers) async { + final response = await http.get(url, headers: headers); + return _handleResponse(response); + } + + Future> _makePostRequest( + Uri url, String body, Map headers) async { + final response = await http.post(url, headers: headers, body: body); + return _handleResponse(response); + } + + Future> _handleResponse(http.Response response) async { + if (response.statusCode == 200) { + return jsonDecode(response.body); + } else if (response.statusCode == 401) { + if (!_isSessionOutToastShown) { + _isSessionOutToastShown = true; + await _clearLocalStorageAndRedirect(); + } + return {}; + } else { + throw Exception('Failed to load data'); + } + } + + Future _clearLocalStorageAndRedirect() async { + final prefs = await SharedPreferences.getInstance(); + await prefs.clear(); + // Assuming you have access to the context + ToastHelper.showErrorToast(context, 'Session Out'); + Navigator.pushNamed(context, 'phone'); + } +} diff --git a/lib/pages/help.dart b/lib/pages/help.dart deleted file mode 100644 index 87f7611..0000000 --- a/lib/pages/help.dart +++ /dev/null @@ -1,460 +0,0 @@ -import 'dart:convert'; -import 'package:flutter/material.dart'; -import 'package:google_fonts/google_fonts.dart'; -import 'package:jwt_decode/jwt_decode.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; -import 'package:http/http.dart' as http; - -import '../service/api_service.dart'; - -class help extends StatefulWidget { - const help({Key? key}) : super(key: key); - - @override - State createState() => _helpState(); -} - -class _helpState extends State { - late ApiService apiService; - 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> employeeDetails = []; - dynamic argumentsData; - dynamic accountManagerDetails; - dynamic accountManagerMobileNo; - dynamic accountManagerEmail; - - 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 _loadToken() async { - print('_loadToken'); - final SharedPreferences prefs = await SharedPreferences.getInstance(); - final String? token = prefs.getString('token'); - if (token != null && token.isNotEmpty) { - setState(() { - _token = token; - }); - // Decode the JWT token received from the API response - Map? decodedToken = Jwt.parseJwt(token); - print(decodedToken); - 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'); - } - } - - Future getSelfEmployeeProfile() async { - print(getSelfEmployeeProfile); - if (client_id == null || empCodeString == null) { - return; - } - print('check 1'); - final response = await apiService.getSelfEmployeeProfileDetails( - client_id!, empCodeString!); - print('check 1'); - if (response['status'] == 'success') { - print(response); - setState(() { - accountManagerDetails = response['AccountManagerDetails']; - print('accountManagerDetails'); - print(accountManagerDetails); - accountManagerEmail = accountManagerDetails['email']; - print(accountManagerEmail); - accountManagerMobileNo = accountManagerDetails['mobile']; - print(accountManagerMobileNo); - }); - } else { - print('API request failed with status: ${response['status']}'); - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - 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: [ - Container( - padding: Responsive.isDesktop(context) - ? EdgeInsets.only(top: 15, bottom: 15, left: 25, right: 25) - : EdgeInsets.only(top: 0, bottom: 0, left: 0, right: 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - if (!Responsive.isDesktop(context)) - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - flex: 12, - 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, - ), - ], - ), - ), - ), - ], - ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - flex: 12, - child: Container( - alignment: Alignment.center, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Image.asset( - 'assets/help.png', - width: 300, - height: 300, - ), - ], - ))), - ], - ), - // Add more rows as needed - ], - ), - ), - SizedBox(height: 15), - Card( - elevation: 0, - shape: RoundedRectangleBorder( - side: BorderSide( - color: Color(0xFFD9D9D9), // Set the border color here - width: 1.0, // Set the border width here - ), - borderRadius: - BorderRadius.circular(8.0), // Set the border radius here - ), - child: Column(children: [ - Container( - decoration: BoxDecoration( - color: Colors - .white, // Set background color for the container - ), - padding: Responsive.isDesktop(context) - ? EdgeInsets.only( - top: 10, bottom: 10, left: 10, right: 10) - : EdgeInsets.only( - top: 10, bottom: 10, left: 10, right: 10), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded( - flex: 11, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Image.asset( - 'assets/tickets.png', - width: 60, - height: 60, - ), - SizedBox( - width: - 10), // Adjust space between icon and text - Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - 'No service request yet!', - textAlign: TextAlign.left, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 18 - : 16, - fontWeight: FontWeight.w600, - color: Color(0xFF000000), - ), - ), - Container( - constraints: BoxConstraints( - maxWidth: Responsive.isDesktop( - context) - ? 800 - : 250), // Adjust the maximum width as needed - child: Text( - 'Please raise a service request, if you have any concerns with your policy.', - textAlign: TextAlign.left, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) - ? 14 - : 12, - fontWeight: FontWeight.w400, - color: Color(0xFF777777), - ), - softWrap: - true, // Ensure text automatically wraps - ), - ), - ], - )) - ], - ), - ), - ], - ), - ), - ])), - SizedBox(height: 15), - Container( - width: double.infinity, - height: 75, - padding: Responsive.isDesktop(context) - ? EdgeInsets.only(top: 20, bottom: 20, left: 30, right: 30) - : EdgeInsets.only( - top: 10, - bottom: 10, - left: 10, - right: 10), // Add padding to the container - child: Row( - children: [ - Expanded( - flex: 8, - child: Container( - width: 300, - height: 150, - alignment: Alignment.center, - child: ElevatedButton( - onPressed: () { - var details = { - 'claimsDetails': '', - 'fromClaimPage': 1 - }; - Navigator.pushNamed(context, 'planclaimsform', - arguments: details); - }, - child: Text( - 'Raise a request', - style: GoogleFonts.poppins(color: Colors.white), - ), - style: ElevatedButton.styleFrom( - backgroundColor: Color(0xFFE26728), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(5), - ), - ), - ), - )), - ], - ), - ), - SizedBox(height: 15), - if (accountManagerDetails != null) - Container( - decoration: BoxDecoration( - color: Colors.white, // Set background color for the container - ), - padding: Responsive.isDesktop(context) - ? EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10) - : EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Padding( - padding: EdgeInsets.only(bottom: 10), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - 'Nhance Account Manager Contact', - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) ? 16 : 12, - fontWeight: FontWeight.w400, - color: Color(0xFF777777), - ), - ), - ], - ), - ), - Padding( - padding: EdgeInsets.only(bottom: 10), - child: Center( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment - .center, // Center align the row - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon( - Icons.email, - size: 20, - color: Color(0xFFE26728), - ), - SizedBox( - width: 10), // Space between icon and text - Text( - accountManagerEmail ?? '', - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) - ? 16 - : 14, - fontWeight: FontWeight.w400, - color: Color(0xFF000000), - ), - ), - ], - ), - SizedBox( - height: - 10), // Space between email and mobile rows - Row( - mainAxisAlignment: MainAxisAlignment - .center, // Center align the row - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon( - Icons.smartphone, - size: 20, - color: Color(0xFFE26728), - ), - SizedBox( - width: 10), // Space between icon and text - Text( - accountManagerMobileNo ?? '', - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) - ? 16 - : 14, - fontWeight: FontWeight.w400, - color: Color(0xFF000000), - ), - ), - ], - ), - ], - ), - ), - ) - ]), - ), - SizedBox(height: Responsive.isDesktop(context) ? 40 : 10), - ]), - )), - 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: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), - floatingActionButtonLocation: Responsive.isDesktop(context) - ? null - : FloatingActionButtonLocation.centerDocked, - bottomNavigationBar: Responsive.isDesktop(context) - ? null - : CustomBottomNavigationBar( - onTabChanged: (index) { - // Add your navigation logic here - // For example: - 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'); - } - }, - icons: [ - Icons.home_outlined, - Icons.sticky_note_2_outlined, - Icons.person_outline_outlined, - Icons.headset_mic_outlined, - ], - labels: [ - "Home", - "Claim", - "Profile", - "Help", - ], - initialIndex: 3, // Initial index of the bottom navigation bar - ), - ); - } -} diff --git a/lib/pages/postEnrollment/chatbot.dart b/lib/pages/postEnrollment/chatbot.dart new file mode 100644 index 0000000..75c7110 --- /dev/null +++ b/lib/pages/postEnrollment/chatbot.dart @@ -0,0 +1,235 @@ +import 'package:dash_chat_2/dash_chat_2.dart'; +import 'package:flutter/material.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/service/api_service.dart'; +import 'package:webview_flutter/webview_flutter.dart'; + +import '../../customAppBar/customAppBar.dart'; +import 'data.dart'; + +class chatbot extends StatefulWidget { + @override + _chatbotState createState() => _chatbotState(); +} + +class _chatbotState extends State { + late ApiService apiService; + List messages = []; + Map firstApiOptions = {}; + dynamic isOptionStatus; + dynamic requestStatus; + dynamic returnMessage; + dynamic mobileNo; + dynamic policyID; + + @override + void initState() { + super.initState(); + apiService = ApiService(context); // Initialize ApiService here + quickReplyOptions(); + } + + @override + void dispose() { + super.dispose(); + } + + void quickReplyOptions() async { + final response = + await apiService.getBotDetails('Start', '1', '0', '', '', ''); + print(response); + if (response['status'] == 'success') { + print('check 2'); + dynamic data = response['data']; + print('data: $data'); + dynamic optionsData = data['options']; + print('optionsData: $optionsData'); + isOptionStatus = data['is_option']; + print('isOptionStatus: $isOptionStatus'); + requestStatus = data['request_for']; + print('requestStatus: $requestStatus'); + setState(() { + firstApiOptions = Map.from(optionsData); + print('firstApiOptions: $firstApiOptions'); + addInitialMessage(); + }); + } else { + // Handle the error accordingly + print('Failed to load quick reply options'); + } + } + + void addInitialMessage() { + List quickReplies = firstApiOptions.entries + .map((entry) => QuickReply(title: entry.value, value: entry.key)) + .toList(); + + final ChatMessage initialMessage = ChatMessage( + text: 'Welcome to our service. How can we assist you today?', + user: user4, + createdAt: DateTime.now(), + quickReplies: quickReplies, + ); + + setState(() { + messages.add(initialMessage); + }); + } + + void handleQuickReply(QuickReply quickReply) async { + print('QuickReply value: ${quickReply.value}'); + print('QuickReply title: ${quickReply.title}'); + + final ChatMessage replyMessage = ChatMessage( + user: user, + text: quickReply.title, + createdAt: DateTime.now(), + ); + + setState(() { + messages.insert(0, replyMessage); + }); + + await processMessage(quickReply.value ?? quickReply.title); + } + + Future processMessage(String messageText) async { + print('Processing message: $messageText'); + + // Add a placeholder loading message with an animated loader + final ChatMessage loadingMessage = ChatMessage( + user: user4, + text: 'Loading...', + createdAt: DateTime.now(), + customProperties: { + 'isLoading': true, + }, + ); + + setState(() { + messages.insert(0, loadingMessage); + }); + + // Simulate API call with a delay of 2 seconds + await Future.delayed(Duration(seconds: 2)); + final response = await apiService.getBotDetails(requestStatus, + isOptionStatus, messageText, returnMessage, mobileNo, policyID); + + if (response['status'] == 'success') { + dynamic chatApiData = response['data']; + print('chatApiData : $chatApiData'); + dynamic optionsData = chatApiData['options']; + returnMessage = chatApiData['text']; + isOptionStatus = chatApiData['is_option']; + requestStatus = chatApiData['request_for']; + + if (chatApiData.containsKey('mobile_no')) { + mobileNo = chatApiData['mobile_no']; + } + if (chatApiData.containsKey('policy_id')) { + policyID = chatApiData['policy_id']; + } + + setState(() { + // Split and format the returnMessage + String formattedMessage = ''; + if (returnMessage != null) { + if (returnMessage.contains('%')) { + try { + List messageParts = returnMessage + .split('%') + .map((part) => part.trim()) + .cast() + .toList(); + formattedMessage = messageParts + .asMap() + .map((index, part) => MapEntry(index, '${index + 1}. $part')) + .values + .join('\n'); + } catch (e) { + print('Error splitting returnMessage: $e'); + formattedMessage = returnMessage; // Fallback to original message + } + } else { + formattedMessage = returnMessage; + } + } else { + print('returnMessage is null'); + } + print('formattedMessage: $formattedMessage'); + + firstApiOptions = + optionsData != null ? Map.from(optionsData) : {}; + + final ChatMessage apiResponseMessage = ChatMessage( + user: user4, + text: formattedMessage ?? '', + createdAt: DateTime.now(), + customProperties: { + 'isLoading': false, + }, + quickReplies: firstApiOptions.entries + .map((entry) => QuickReply(title: entry.value, value: entry.key)) + .toList(), + ); + + // Remove the loading message and add the actual response + messages.removeAt(0); + messages.insert(0, apiResponseMessage); + }); + } else { + setState(() { + // Remove the loading message and add an error message + messages.removeAt(0); + messages.insert( + 0, + ChatMessage( + user: user4, + text: 'Failed to load data from API', + createdAt: DateTime.now(), + customProperties: { + 'isLoading': false, + }, + ), + ); + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: CustomAppBar(), + body: DashChat( + currentUser: user, + onSend: (ChatMessage m) { + setState(() { + messages.insert(0, m); + }); + processMessage(m.text); + }, + quickReplyOptions: QuickReplyOptions(onTapQuickReply: handleQuickReply), + messages: messages, + ), + ); + } + + // late WebViewController _controller; + // + // @override + // void initState() { + // super.initState(); + // _controller = WebViewController() + // ..setJavaScriptMode(JavaScriptMode.unrestricted) + // ..loadRequest(Uri.parse( + // 'https://mediafiles.botpress.cloud/0439df41-8f0c-4bfd-ad85-340462deebc0/webchat/bot.html')); + // } + + // @override + // Widget build(BuildContext context) { + // return Scaffold( + // backgroundColor: Colors.white, + // appBar: CustomAppBar(), + // body: WebViewWidget(controller: _controller), + // ); + // } +} diff --git a/lib/pages/claimprocess.dart b/lib/pages/postEnrollment/claimprocess.dart similarity index 98% rename from lib/pages/claimprocess.dart rename to lib/pages/postEnrollment/claimprocess.dart index a7ff625..b9929f4 100644 --- a/lib/pages/claimprocess.dart +++ b/lib/pages/postEnrollment/claimprocess.dart @@ -2,16 +2,15 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.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:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; import 'package:http/http.dart' as http; -import '../service/api_service.dart'; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; class claimprocess extends StatefulWidget { const claimprocess({Key? key}) : super(key: key); @@ -125,6 +124,7 @@ class _claimprocessState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack( children: [ @@ -783,9 +783,17 @@ class _claimprocessState extends State { ), ], ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () { + Navigator.pushNamed(context, 'chatbot'); + }, + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.centerDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( diff --git a/lib/pages/claims.dart b/lib/pages/postEnrollment/claims.dart similarity index 82% rename from lib/pages/claims.dart rename to lib/pages/postEnrollment/claims.dart index d71bc4e..182257b 100644 --- a/lib/pages/claims.dart +++ b/lib/pages/postEnrollment/claims.dart @@ -6,16 +6,15 @@ import 'package:flutter_svg/svg.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:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; import 'package:http/http.dart' as http; -import '../service/api_service.dart'; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; class claims extends StatefulWidget { const claims({Key? key}) : super(key: key); @@ -43,7 +42,8 @@ class _claimsState extends State { List> employeeDetails = []; dynamic argumentsData; dynamic empMobileNo; - dynamic trackClaimsList; + List reversedClaimsList = []; + List trackClaimsList = []; int trackClaimsActive = 1; int yourPlanActive = 0; int? serviceId; @@ -135,7 +135,11 @@ class _claimsState extends State { print('check 1'); if (response['success'] == true) { setState(() { - trackClaimsList = response['data']; + trackClaimsList = response['data'] + .where((item) => item['department_name'] == 'Claims') + .toList(); + reversedClaimsList = List>.from(trackClaimsList); + trackClaimsList = reversedClaimsList.reversed.toList(); }); print(trackClaimsList); } else { @@ -173,6 +177,7 @@ class _claimsState extends State { print("Arguments are null or not in the expected format"); } return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack(children: [ SingleChildScrollView( @@ -188,103 +193,61 @@ class _claimsState extends State { color: Colors.white, child: Column(children: [ Container( - padding: Responsive.isDesktop(context) - ? EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10) - : EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - if (!Responsive.isDesktop(context)) - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - flex: 12, - 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, - ), - SizedBox( - width: - 5), // Adjust space between icon and text - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Claim assistance', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Color(0xFF000000), - ), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + flex: 12, + 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, + ), + SizedBox( + width: + 5), // Adjust space between icon and text + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Claim assistance', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), ), - Text( - 'Manage your claims', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: - 12, // Adjust the font size as needed - fontWeight: FontWeight.w400, - color: Color(0xFF000000), - ), + ), + Text( + 'Manage your claims', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: + 12, // Adjust the font size as needed + fontWeight: FontWeight.w400, + color: Color(0xFF000000), ), - ], - ), - ], - ), + ), + ], + ), + ], ), ), - ], - ), - if (Responsive.isDesktop(context)) - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 12, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Claim assistance', - textAlign: TextAlign.left, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) - ? 18 - : 16, - fontWeight: FontWeight.w500, - color: Color(0xFF000000), - ), - ), - Text( - 'Manage your claims', - textAlign: TextAlign.left, - style: GoogleFonts.poppins( - fontSize: Responsive.isDesktop(context) - ? 12 - : 10, - fontWeight: FontWeight.w400, - color: Color(0xFF7A7A7A), - ), - ), - ], - ))), - ], - ), + ), + ], + ), // Add more rows as needed ], ), @@ -649,17 +612,17 @@ class _claimsState extends State { ), ), ]), - // floatingActionButton: Responsive.isDesktop(context) - // ? null - // : FloatingActionButton( - // onPressed: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () { + Navigator.pushNamed(context, 'chatbot'); + }, + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.centerDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( @@ -830,6 +793,7 @@ class _claimsState extends State { var item = data[index]; String claimsName = item['user_name']; String claimsSubject = item['subject']; + String claimsDate = item['date']; String claimsReplies = item['replies']; String claimStatus = item['status_value']; String claimsDepartmentName = item['department_name']; @@ -867,97 +831,103 @@ class _claimsState extends State { color: Colors.white, borderRadius: BorderRadius.circular(15.0), ), - padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15), + padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10), child: Row( - mainAxisAlignment: MainAxisAlignment - .spaceBetween, // Center content horizontally - crossAxisAlignment: - CrossAxisAlignment.center, // Center content vertically + crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( - flex: 4, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Service', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) ? 16 : 12, - fontWeight: FontWeight.w400, - color: Color(0xFF979797), - ), - ), - Text( - claimsDepartmentName, - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) ? 18 : 16, - fontWeight: FontWeight.w600, - color: Color(0xFF000000), - ), - ), - ], - ), + flex: 6, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // Adjust space between icon and text + Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + claimsDepartmentName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 18 + : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ), + SizedBox(height: 5), + Text( + claimsSubject, + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), // Ensure text automatically wraps + ), + ], + )) + ], ), ), Expanded( - flex: 4, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Subject', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) ? 16 : 12, - fontWeight: FontWeight.w400, - color: Color(0xFF979797), - ), - ), - Text( - claimsSubject ?? '', - textAlign: TextAlign.start, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) ? 18 : 16, - fontWeight: FontWeight.w600, - color: Color(0xFF000000), - ), - ), - ], - ), - ), - ), - Expanded( - flex: 3, - child: Container( - alignment: Alignment.centerLeft, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - claimStatus ?? '', - textAlign: TextAlign.center, - style: GoogleFonts.poppins( - fontSize: - Responsive.isDesktop(context) ? 16 : 12, - fontWeight: FontWeight.w400, - color: statusColor, - ), - ), - ], - ), + flex: 5, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + // Adjust space between icon and text + Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Container( + width: 100, + decoration: BoxDecoration( + color: statusColor, + borderRadius: BorderRadius.circular( + 50), // Border radius set to 50 + ), + child: Padding( + padding: const EdgeInsets.all(5.0), + child: Text( + claimStatus, + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 12 + : 10, + fontWeight: FontWeight.w400, + color: Colors + .white, // Text color against the background + ), + ), + ), + ), + SizedBox(height: 5), + Text( + formatDateWithTime(claimsDate), + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), // Ensure text automatically wraps + ), + ], + )) + ], ), ), Expanded( @@ -981,4 +951,17 @@ class _claimsState extends State { ), ]; } + + String formatDateWithTime(String timestamp) { + // Convert the timestamp string to milliseconds + int milliseconds = int.parse(timestamp) * 1000; + + // Create a DateTime object from milliseconds + DateTime date = DateTime.fromMillisecondsSinceEpoch(milliseconds); + + // Format the DateTime object with date and time + String formattedDate = DateFormat('d MMM, y HH:mm a').format(date); + + return formattedDate; + } } diff --git a/lib/pages/postEnrollment/claimtracklist.dart b/lib/pages/postEnrollment/claimtracklist.dart new file mode 100644 index 0000000..7e0df50 --- /dev/null +++ b/lib/pages/postEnrollment/claimtracklist.dart @@ -0,0 +1,631 @@ +import 'dart:convert'; +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:shared_preferences/shared_preferences.dart'; + +import 'package:http/http.dart' as http; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; + +class claimtracklist extends StatefulWidget { + const claimtracklist({Key? key}) : super(key: key); + + @override + State createState() => _claimtracklistformState(); +} + +class _claimtracklistformState extends State { + late ApiService apiService; + dynamic _token; + dynamic empCodeString; + dynamic empPrimaryId; + dynamic client_id; + dynamic policyList; + dynamic policyDataIsEmpty = 1; + dynamic policyHeading; + dynamic policyName; + dynamic policyDate; + dynamic policyStatus; + dynamic policySubject; + dynamic policyNo; + dynamic EmployeePolicy; + List> employeeDetails = []; + dynamic argumentsData; + dynamic decodedToken; + dynamic claimTrackMsgList; + dynamic empName; + dynamic ticketID; + late TextEditingController messageController; + final Map statusColors = { + 'Open': Colors.green, + 'Answered': Colors.blue, + 'Awaiting Reply': Colors.orange, + 'Inprogress': Colors.yellow, + 'Closed': Colors.red, + }; + + // Create a unique form key for each accordion section + final GlobalKey formKey = GlobalKey(); + + @override + void initState() { + super.initState(); + apiService = ApiService(context); // Initialize ApiService here + _loadToken(); + messageController = TextEditingController(); + } + + @override + void dispose() { + super.dispose(); + messageController.dispose(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + dynamic arguments = ModalRoute.of(context)!.settings.arguments; + if (arguments != null && arguments is Map) { + argumentsData = arguments; + print('argumentsData'); + print(argumentsData); + ticketID = argumentsData['id']; + claimTrackMsgList = argumentsData['message_list']; + policyName = argumentsData['policy_name']; + policyStatus = argumentsData['status_value']; + policyNo = argumentsData['policy_no']; + policySubject = argumentsData['subject']; + policyDate = formatDateWithTime(argumentsData['date']); + print(claimTrackMsgList); + } + } + + Future _loadToken() async { + print('_loadToken'); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + if (token != null && token.isNotEmpty) { + setState(() { + _token = token; + }); + // Decode the JWT token received from the API response + decodedToken = Jwt.parseJwt(token); + print(decodedToken); + empName = decodedToken['name']; + 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); + } 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'); + } + } + + void sendClaimsMessage(Map formData) async { + try { + formData = formData.map((key, value) => MapEntry(key, value.toString())); + + final response = await apiService.sendClaimsMessageToApi(formData); + + if (response['success'] == 1) { + messageController.clear(); + ToastHelper.showSuccessToast(context, 'Saved Successfully...'); + messageController.clear(); + Navigator.pushNamed(context, 'claims', arguments: 0); + print('Form data sent successfully.'); + } else { + print('Failed to submit form data: ${response['status']}'); + } + } catch (e) { + print('Error submitting form data: $e'); + } + } + + Color getStatusColor(String? policyStatus) { + if (policyStatus != null && statusColors.containsKey(policyStatus)) { + return statusColors[policyStatus]!; + } else { + return Color(0xFF000000); // Default color for policyStatus text + } + } + + @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: [ + Card( + elevation: 5, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(15.0), // Set border radius here + ), + child: Container( + decoration: BoxDecoration( + color: Colors.white, // Set background color to white + borderRadius: BorderRadius.circular( + 15.0), // Set border radius for Container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 15, bottom: 15, left: 15, right: 15) + : EdgeInsets.only( + top: 10, + bottom: 10, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFFCE5), // Set background color for the container + borderRadius: BorderRadius.circular( + 10), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 20, + bottom: 20, + left: 10, + right: 10) + : EdgeInsets.only( + top: 10, + bottom: 10, + left: 10, + right: 10), + child: Column( + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.start, + children: [ + Expanded( + flex: 1, + child: InkWell( + onTap: () { + Navigator.pushNamed( + context, 'claims'); + }, + child: Icon( + Icons + .chevron_left, // Replace with your desired icon + color: Color(0xFF000000), + size: 30, + ), + ), + ), + Expanded( + flex: 11, + child: Row( + mainAxisAlignment: + Responsive.isDesktop(context) + ? MainAxisAlignment.center + : MainAxisAlignment.start, + children: [ + Text( + policyName ?? '', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ) + ], + ), + ) + ], + ), + SizedBox( + height: Responsive.isDesktop(context) + ? 20 + : 20), // Space between rows + Column( + children: [ + Responsive.isDesktop(context) + ? buildDesktopLayout(context) + : buildMobileLayout(context) + ], + ), // Space between rows + // Add more rows as needed + ], + ), + ), + SizedBox(height: 15), + Container( + child: SingleChildScrollView( + child: Column(children: [ + ...claimTrackMsgList + .map((message) { + bool isUserMessage = + message['staff_name'] == null; + String messageContent = + message['message']; + String messageDate = message['date']; + dynamic messagername; + if (isUserMessage) { + messagername = empName; + } else { + messagername = message['staff_name']; + } + + return Padding( + padding: const EdgeInsets.symmetric( + vertical: 4.0), + child: Align( + alignment: isUserMessage + ? Alignment.centerLeft + : Alignment.centerLeft, + child: Container( + constraints: + BoxConstraints(maxWidth: 800), + padding: EdgeInsets.all(10), + decoration: BoxDecoration( + color: isUserMessage + ? Colors.blue[100] + : Colors.green[100], + borderRadius: + BorderRadius.circular(10), + ), + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + messageContent, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 14 + : 12, + fontWeight: + FontWeight.w400, + color: Color(0xFF000000), + ), + ), + SizedBox(height: 5), + Row( + mainAxisAlignment: + MainAxisAlignment + .spaceBetween, + children: [ + Row( + children: [ + Icon( + Icons.person, + color: Color( + 0xFFE26728), + size: 15, + ), + SizedBox(width: 5), + Text( + messagername, + style: GoogleFonts + .poppins( + fontSize: Responsive + .isDesktop( + context) + ? 16 + : 14, + fontWeight: + FontWeight + .w500, + color: Color( + 0xFF000000), + ), + ), + ], + ), + Text( + formatDateWithTime( + messageDate), + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 12 + : 10, + fontWeight: + FontWeight.w400, + color: + Color(0xFF636363), + ), + ), + ], + ), + ], + ), + ), + ), + ); + }).toList(), + Padding( + padding: const EdgeInsets.symmetric( + vertical: 8.0), + child: Row( + children: [ + Expanded( + flex: Responsive.isDesktop( + context) + ? 10 + : 9, + child: TextFormField( + controller: messageController, + onChanged: (value) => null, + decoration: InputDecoration( + border: + OutlineInputBorder(), + hintText: 'Message', + labelText: 'Message', + contentPadding: + EdgeInsets.symmetric( + vertical: 10, + horizontal: 15), + ), + validator: (value) { + if (value == null || + value.isEmpty) { + return 'Message is required'; + } + return null; + }, + ), + ), + Expanded( + flex: Responsive.isDesktop( + context) + ? 2 + : 3, + child: Container( + alignment: + Alignment.centerRight, + child: ElevatedButton( + onPressed: () { + // Check if any of the fields are empty + if (messageController + .text.isEmpty) { + ToastHelper + .showWarningToast( + context, + 'All fields are required'); + } else { + // Create a map to hold the form data + Map + formData = { + 'ticket_id': ticketID, + 'replier': 'user', + 'message': + messageController + .text, + // Add more form fields as needed + }; + + // Call the function to send form data to API + sendClaimsMessage( + formData); + } + }, + child: Text( + 'Reply', + style: + GoogleFonts.poppins( + color: + Colors.white), + ), + style: ElevatedButton + .styleFrom( + backgroundColor: + Color(0xFFE26728), + shape: + RoundedRectangleBorder( + borderRadius: + BorderRadius + .circular(5), + ), + ), + ), + ), + ), + ], + ) + // ElevatedButton( + // onPressed: () { + // + // }, + // child: Text('Reply'), + // ), + ), + ]), + ), + ), + ], + ))), + ], + ), + ), + ), + SizedBox(height: Responsive.isDesktop(context) ? 40 : 10), + ]), + )), + 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) { + // Add your navigation logic here + // For example: + 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'); + } + }, + icons: [ + Icons.home_outlined, + Icons.sticky_note_2_outlined, + Icons.person_outline_outlined, + Icons.headset_mic_outlined, + ], + labels: [ + "Home", + "Claim", + "Profile", + "Help", + ], // Initial index of the bottom navigation bar + ), + ); + } + + String formatDateWithTime(String timestamp) { + // Convert the timestamp string to milliseconds + int milliseconds = int.parse(timestamp) * 1000; + + // Create a DateTime object from milliseconds + DateTime date = DateTime.fromMillisecondsSinceEpoch(milliseconds); + + // Format the DateTime object with date and time + String formattedDate = DateFormat('d MMM, y HH:mm a').format(date); + + return formattedDate; + } + + Widget buildDesktopLayout(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + buildExpandedColumn(context, 'Policy No', policyNo), + buildExpandedColumn(context, 'Status', policyStatus), + buildExpandedColumn(context, 'Subject', policySubject), + ], + ); + } + + Widget buildMobileLayout(BuildContext context) { + return Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + buildExpandedColumn(context, 'Policy No', policyNo), + buildExpandedColumn(context, 'Status', policyStatus), + ], + ), + SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + buildExpandedColumn(context, 'Subject', policySubject), + buildExpandedColumn(context, '', ''), + ], + ), + ], + ); + } + + Widget buildExpandedColumn( + BuildContext context, String title, String? value) { + return Expanded( + flex: 3, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + title, + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 18 : 14, + fontWeight: FontWeight.w400, + color: Color(0xFF000000), + ), + ), + SizedBox(height: Responsive.isDesktop(context) ? 10 : 4), + title == 'Status' + ? Text( + value ?? '', // Null check for value + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 18 : 16, + fontWeight: FontWeight.w600, + color: getStatusColor(policyStatus), + ), + ) + : Text( + value ?? '', // Null check for value + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) ? 18 : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/pages/postEnrollment/data.dart b/lib/pages/postEnrollment/data.dart new file mode 100755 index 0000000..578cb46 --- /dev/null +++ b/lib/pages/postEnrollment/data.dart @@ -0,0 +1,192 @@ +import 'package:dash_chat_2/dash_chat_2.dart'; + +String profileImage = + 'https://e7.pngegg.com/pngimages/811/700/png-clipart-chatbot-internet-bot-business-natural-language-processing-facebook-messenger-business-people-logo-thumbnail.png'; + +// We have all the possibilities for users +ChatUser user = ChatUser(id: '0'); +ChatUser user1 = ChatUser(id: '1'); +ChatUser user2 = ChatUser(id: '2', firstName: 'Niki Lauda'); +ChatUser user3 = ChatUser(id: '3', lastName: 'Clark'); +ChatUser user4 = ChatUser(id: '4', profileImage: profileImage); +ChatUser user5 = ChatUser(id: '5', firstName: 'Charles', lastName: 'Leclerc'); +ChatUser user6 = + ChatUser(id: '6', firstName: 'Max', profileImage: profileImage); +ChatUser user7 = + ChatUser(id: '7', lastName: 'Toto', profileImage: profileImage); +ChatUser user8 = ChatUser( + id: '8', firstName: 'Toto', lastName: 'Clark', profileImage: profileImage); + +List allUsersSample = [ + ChatMessage( + text: 'Test', + user: user1, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user2, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user3, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user4, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user5, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user6, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user7, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'Test', + user: user8, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), +]; + +List basicSample = [ + ChatMessage( + text: 'google.com hello you @Marc is it &you okay?', + user: user2, + createdAt: DateTime(2021, 01, 31, 16, 45), + mentions: [ + Mention(title: '@Marc'), + Mention(title: '&you'), + ], + ), + ChatMessage( + text: 'google.com', + user: user2, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: "Oh what's up guys?", + user: user2, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), + ChatMessage( + text: 'How you doin?', + user: user8, + createdAt: DateTime(2021, 01, 30, 16, 34), + ), + ChatMessage( + isMarkdown: true, + text: + "```dart\nvoid main() {\n print('Hello World');\n}\n```\nThe above code will print \"Hello World\" to the console when run.\n\nHere's a breakdown of the code:\n\n* The `main()` function is the entry point of the program. It's where execution begins.\n* `print('Hello World')` prints \"Hello World\" to the console. The `print()` function is a built-in function in Dart that outputs data to the console.\n\nYou can run this code by creating a new Dart file (e.g., `hello_world.dart`) and pasting the code into it. Then, open a terminal window, navigate to the directory where the file is saved, and run the following command:\n\n```\ndart hello_world.dart\n```\n\nThis will compile and run the Dart program, and you should see \"Hello World\" printed to the console. Know more: www.google.com ", + user: user2, + createdAt: DateTime(2021, 01, 30, 15, 50), + ), + ChatMessage( + text: 'Hey!', + user: user, + createdAt: DateTime(2021, 01, 30, 15, 50), + ), + ChatMessage( + text: 'Hey!', + user: user, + createdAt: DateTime(2021, 01, 28, 15, 50), + ), + ChatMessage( + text: 'Hey!', + user: user, + createdAt: DateTime(2021, 01, 28, 15, 50), + ), +]; + +List media = [ + ChatMessage( + medias: [ + ChatMedia( + url: + 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', + type: MediaType.image, + fileName: 'image.png', + isUploading: true, + ), + ChatMedia( + url: + 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', + type: MediaType.image, + fileName: 'image.png', + ), + ChatMedia( + url: + 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/chat_medias%2F2GFlPkj94hKCqonpEdf1%2F20210526_162318.mp4?alt=media&token=01b814b9-d93a-4bf1-8be1-cf9a49058f97', + type: MediaType.video, + fileName: 'video.mp4', + isUploading: false, + ), + ChatMedia( + url: + 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/chat_medias%2F2GFlPkj94hKCqonpEdf1%2F20210526_162318.mp4?alt=media&token=01b814b9-d93a-4bf1-8be1-cf9a49058f97', + type: MediaType.video, + fileName: 'video.mp4', + isUploading: false, + ), + ChatMedia( + url: + 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', + type: MediaType.file, + fileName: 'image.png', + ), + ChatMedia( + url: + 'https://firebasestorage.googleapis.com/v0/b/molteo-40978.appspot.com/o/memes%2F155512641_3864499247004975_4028017188079714246_n.jpg?alt=media&token=0b335455-93ed-4529-9055-9a2c741e0189', + type: MediaType.image, + fileName: 'image.png', + ) + ], + user: user3, + createdAt: DateTime(2021, 01, 30, 16, 34), + ), +]; + +List quickReplies = [ + ChatMessage( + text: 'How you doin?', + user: user3, + createdAt: DateTime.now(), + quickReplies: [ + QuickReply(title: 'Great!'), + QuickReply(title: 'Awesome'), + QuickReply(title: 'Hello'), + QuickReply(title: 'Hava a nice day'), + QuickReply(title: 'Hello @Niki, you should check #channel'), + ], + ), +]; + +List mentionSample = [ + ChatMessage( + text: 'Hello @Niki, you should check #channel', + user: user2, + createdAt: DateTime(2021, 01, 31, 16, 45), + mentions: [ + Mention(title: '@Niki', customProperties: {'userId': user5.id}), + Mention(title: '#channel'), + ], + ), + ChatMessage( + text: "Oh what's up guys?", + user: user5, + createdAt: DateTime(2021, 01, 30, 16, 45), + ), +]; + +List d = []; diff --git a/lib/pages/generalexclusionsdeductibles.dart b/lib/pages/postEnrollment/generalexclusionsdeductibles.dart similarity index 98% rename from lib/pages/generalexclusionsdeductibles.dart rename to lib/pages/postEnrollment/generalexclusionsdeductibles.dart index cc751f5..1d40bf1 100644 --- a/lib/pages/generalexclusionsdeductibles.dart +++ b/lib/pages/postEnrollment/generalexclusionsdeductibles.dart @@ -2,16 +2,15 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.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:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; -import 'package:http/http.dart' as http; -import '../service/api_service.dart'; +import 'package:http/http.dart' as http; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; class generalExclusionsDeductibles extends StatefulWidget { const generalExclusionsDeductibles({Key? key}) : super(key: key); @@ -173,6 +172,7 @@ class _generalExclusionsDeductiblesState @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack( children: [ @@ -828,9 +828,17 @@ class _generalExclusionsDeductiblesState ), ], ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () { + Navigator.pushNamed(context, 'chatbot'); + }, + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.centerDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( diff --git a/lib/pages/postEnrollment/help.dart b/lib/pages/postEnrollment/help.dart new file mode 100644 index 0000000..39e77e9 --- /dev/null +++ b/lib/pages/postEnrollment/help.dart @@ -0,0 +1,1070 @@ +import 'dart:convert'; +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:shared_preferences/shared_preferences.dart'; +import 'package:http/http.dart' as http; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; + +class help extends StatefulWidget { + const help({Key? key}) : super(key: key); + + @override + State createState() => _helpState(); +} + +class _helpState extends State { + late ApiService apiService; + int _currentIndex = 0; + bool isActive = true; + int closedTrackActive = 1; + int allClaimsActive = 0; + dynamic _token; + dynamic empCodeString; + dynamic empPrimaryId; + dynamic client_id; + dynamic policyList; + dynamic policyDataIsEmpty = 1; + dynamic policyHeading; + dynamic policyName; + dynamic EmployeePolicy; + List> employeeDetails = []; + dynamic argumentsData; + dynamic accountManagerDetails; + dynamic accountManagerMobileNo; + dynamic accountManagerEmail; + dynamic client_branch_id; + dynamic empMobileNo; + List reversedClaimsList = []; + List trackClaimsList = []; + List reversedClaimsClosedList = []; + List trackClaimsClosedList = []; + final Map statusColors = { + 'Open': Colors.green, + 'Answered': Colors.blue, + 'Awaiting Reply': Colors.orange, + 'Inprogress': Colors.yellow, + 'Closed': Colors.red, + }; + + 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 _loadToken() async { + print('_loadToken'); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + final String? token = prefs.getString('token'); + if (token != null && token.isNotEmpty) { + setState(() { + _token = token; + }); + // Decode the JWT token received from the API response + Map? decodedToken = Jwt.parseJwt(token); + print(decodedToken); + empMobileNo = decodedToken['mobile']; + 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(); + getTrackClaimsList(); + } 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'); + } + } + + Future getSelfEmployeeProfile() async { + print(getSelfEmployeeProfile); + if (client_id == null || empCodeString == null) { + return; + } + print('check 1'); + final response = await apiService.getSelfEmployeeProfileDetails( + client_id!, empCodeString!, client_branch_id!); + print('check 1'); + if (response['status'] == 'success') { + print(response); + setState(() { + accountManagerDetails = response['AccountManagerDetails']; + print('accountManagerDetails'); + print(accountManagerDetails); + accountManagerEmail = accountManagerDetails['email']; + print(accountManagerEmail); + accountManagerMobileNo = accountManagerDetails['mobile']; + print(accountManagerMobileNo); + }); + } else { + print('API request failed with status: ${response['status']}'); + } + } + + Future getTrackClaimsList() async { + if (client_id == null || empCodeString == null) { + return; + } + print('check 1'); + final response = + await apiService.getTrackClaimsList(empMobileNo!, empCodeString!); + print('check 1'); + if (response['success'] == true) { + setState(() { + trackClaimsList = response['data'] + .where((item) => item['status_value'] != 'Closed') + .toList(); + reversedClaimsList = List>.from(trackClaimsList); + trackClaimsList = reversedClaimsList.reversed.toList(); + + trackClaimsClosedList = response['data'] + .where((item) => item['status_value'] == 'Closed') + .toList(); + reversedClaimsClosedList = + List>.from(trackClaimsClosedList); + trackClaimsClosedList = reversedClaimsClosedList.reversed.toList(); + }); + print(trackClaimsList); + } else { + // setState(() { + // trackClaimsIsEmpty = 0; + // }); + print('API request failed with status: ${response['status']}'); + } + } + + Color getStatusColor(String? policyStatus) { + if (policyStatus != null && statusColors.containsKey(policyStatus)) { + return statusColors[policyStatus]!; + } else { + return Color(0xFF000000); // Default color for policyStatus text + } + } + + @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: [ + Container( + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 15, bottom: 15, left: 25, right: 25) + : EdgeInsets.only(top: 0, bottom: 0, left: 0, right: 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + flex: 12, + 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, + ), + ], + ), + ), + ), + ], + ), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Image.asset( + 'assets/help.png', + width: 300, + height: 300, + ), + ], + ))), + ], + ), + // Add more rows as needed + ], + ), + ), + SizedBox(height: 10), + Container( + width: double.infinity, + height: 75, + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 20, bottom: 20, left: 30, right: 30) + : EdgeInsets.only( + top: 10, + bottom: 10, + left: 10, + right: 10), // Add padding to the container + child: Row( + children: [ + Expanded( + flex: 8, + child: Container( + width: 300, + height: 150, + alignment: Alignment.center, + child: ElevatedButton( + onPressed: () { + var details = { + 'claimsDetails': '', + 'fromClaimPage': 1 + }; + Navigator.pushNamed(context, 'planclaimsform', + arguments: details); + }, + child: Text( + 'Raise a request', + style: GoogleFonts.poppins(color: Colors.white), + ), + style: ElevatedButton.styleFrom( + backgroundColor: Color(0xFFE26728), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5), + ), + ), + ), + )), + ], + ), + ), + SizedBox(height: 15), + if (trackClaimsList == null) + Card( + elevation: 0, + shape: RoundedRectangleBorder( + side: BorderSide( + color: Color(0xFFD9D9D9), // Set the border color here + width: 1.0, // Set the border width here + ), + borderRadius: BorderRadius.circular( + 8.0), // Set the border radius here + ), + child: Column(children: [ + Container( + decoration: BoxDecoration( + color: Colors + .white, // Set background color for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10) + : EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 11, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Image.asset( + 'assets/tickets.png', + width: 60, + height: 60, + ), + SizedBox( + width: + 10), // Adjust space between icon and text + Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + 'No service request yet!', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ), + Container( + constraints: BoxConstraints( + maxWidth: Responsive.isDesktop( + context) + ? 800 + : 250), // Adjust the maximum width as needed + child: Text( + 'Please raise a service request, if you have any concerns with your policy.', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), + softWrap: + true, // Ensure text automatically wraps + ), + ), + ], + )) + ], + ), + ), + ], + ), + ), + ])), + SizedBox(height: 15), + Container( + decoration: BoxDecoration( + color: + Color(0xFFF6FAFF), // Set background color for the container + borderRadius: BorderRadius.circular( + 5), // Set border radius for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 10, bottom: 10, left: 25, right: 25) + : EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 12, + child: Container( + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + flex: 6, + child: Container( + alignment: Alignment.center, + child: GestureDetector( + onTap: () { + setState(() { + isActive = true; + // policyList.clear(); + allClaimsActive = 0; + closedTrackActive = 1; + }); + }, + child: isActive + ? Material( + elevation: 5, + borderRadius: + BorderRadius.circular(10), + color: Colors.white, + child: TextButton( + onPressed: () {}, + style: TextButton.styleFrom( + padding: EdgeInsets.symmetric( + horizontal: Responsive + .isDesktop( + context) + ? 120 + : 50, + vertical: Responsive + .isDesktop( + context) + ? 15 + : 7), + // primary: Color(0xFF000000), + ), + child: Text( + 'All Claims', + style: GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 14, + fontWeight: + FontWeight.w500, + color: Color( + 0xFF000000)), + ), + ), + ) + : Text( + 'All Claims', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + fontWeight: FontWeight.w400, + color: Color(0xFF636363), + ), + ), + ), + )), + Expanded( + flex: 6, + child: Container( + alignment: Alignment.center, + child: GestureDetector( + onTap: () { + setState(() { + isActive = false; + // trackClaimsList.clear(); + allClaimsActive = 1; + closedTrackActive = 0; + }); + getTrackClaimsList(); + }, + child: !isActive + ? Material( + elevation: 5, + borderRadius: + BorderRadius.circular(10), + color: Colors.white, + child: TextButton( + onPressed: () {}, + style: TextButton.styleFrom( + padding: EdgeInsets.symmetric( + horizontal: Responsive + .isDesktop( + context) + ? 120 + : 40, + vertical: Responsive + .isDesktop( + context) + ? 15 + : 7), + // primary: Color(0xFF000000), + ), + child: Text( + 'Closed claims', + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 14, + color: + Color(0xFF000000), + fontWeight: + FontWeight.w500, + ), + ), + ), + ) + : Text( + 'Closed claims', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 18 + : 14, + fontWeight: FontWeight.w400, + color: Color(0xFF636363), + ), + ), + ), + )) + ], + ) + ], + ))), + ], + ), + ), + if (trackClaimsList != null) + if (allClaimsActive == 0) + SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: generateClaimsList( + trackClaimsList), // Replace 'yourDataList' with your actual data list + ), + ), + SizedBox(height: 15), + if (trackClaimsClosedList != null) + if (closedTrackActive == 0) + SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: generateClaimsClosedList( + trackClaimsClosedList), // Replace 'yourDataList' with your actual data list + ), + ), + SizedBox(height: 15), + if (accountManagerDetails != null) + Container( + decoration: BoxDecoration( + color: Colors.white, // Set background color for the container + ), + padding: Responsive.isDesktop(context) + ? EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10) + : EdgeInsets.only(top: 10, bottom: 10, left: 10, right: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: EdgeInsets.only(bottom: 10), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + 'Nhance Account Manager Contact', + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) ? 16 : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), + ), + ], + ), + ), + Padding( + padding: EdgeInsets.only(bottom: 10), + child: Center( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment + .center, // Center align the row + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Icon( + Icons.email, + size: 20, + color: Color(0xFFE26728), + ), + SizedBox( + width: 10), // Space between icon and text + Text( + accountManagerEmail ?? '', + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 16 + : 14, + fontWeight: FontWeight.w400, + color: Color(0xFF000000), + ), + ), + ], + ), + SizedBox( + height: + 10), // Space between email and mobile rows + Row( + mainAxisAlignment: MainAxisAlignment + .center, // Center align the row + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Icon( + Icons.smartphone, + size: 20, + color: Color(0xFFE26728), + ), + SizedBox( + width: 10), // Space between icon and text + Text( + accountManagerMobileNo ?? '', + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop(context) + ? 16 + : 14, + fontWeight: FontWeight.w400, + color: Color(0xFF000000), + ), + ), + ], + ), + ], + ), + ), + ) + ]), + ), + SizedBox(height: Responsive.isDesktop(context) ? 40 : 10), + ]), + )), + 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) { + // Add your navigation logic here + // For example: + 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'); + } + }, + icons: [ + Icons.home_outlined, + Icons.sticky_note_2_outlined, + Icons.person_outline_outlined, + Icons.headset_mic_outlined, + ], + labels: [ + "Home", + "Claim", + "Profile", + "Help", + ], + initialIndex: 3, // Initial index of the bottom navigation bar + ), + ); + } + + List generateClaimsList(List data) { + return [ + ListView.builder( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemCount: data.length, + itemBuilder: (BuildContext context, int index) { + var item = data[index]; + String claimsName = item['user_name']; + String claimsDate = item['date']; + String claimsSubject = item['subject']; + String claimsReplies = item['replies']; + String claimStatus = item['status_value']; + String claimsDepartmentName = item['department_name']; + List messageList = item['message_list']; + + final Map statusColors = { + 'Open': Colors.green, + 'Answered': Colors.blue, + 'Awaiting Reply': Colors.orange, + 'Inprogress': Colors.yellow, + 'Closed': Colors.red, + }; + + // Determine the color based on the claimStatus + Color statusColor; + if (claimStatus != null) { + statusColor = statusColors[claimStatus!] ?? Color(0xFF979797); + } else { + statusColor = Color(0xFF979797); // Default color if status is null + } + + return GestureDetector( + onTap: () { + Navigator.pushNamed(context, 'claimtracklist', arguments: item); + }, + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: Card( + elevation: 0, + shape: RoundedRectangleBorder( + side: BorderSide( + color: Color(0xFFD9D9D9), // Set the border color here + width: 1.0, // Set the border width here + ), + borderRadius: BorderRadius.circular( + 8.0), // Set the border radius here + ), + child: Column(children: [ + Container( + decoration: BoxDecoration( + color: Colors + .white, // Set background color for the container + ), + padding: EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 7, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/tickets.png', + width: 40, + height: 40, + ), + SizedBox( + width: + 10), // Adjust space between icon and text + Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + claimsDepartmentName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ), + SizedBox(height: 5), + Text( + claimsSubject, + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), // Ensure text automatically wraps + ), + ], + )) + ], + ), + ), + Expanded( + flex: 5, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + // Adjust space between icon and text + Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Container( + width: 100, + decoration: BoxDecoration( + color: statusColor, + borderRadius: BorderRadius.circular( + 50), // Border radius set to 50 + ), + child: Padding( + padding: const EdgeInsets.all(5.0), + child: Text( + claimStatus, + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop( + context) + ? 12 + : 10, + fontWeight: FontWeight.w400, + color: Colors + .white, // Text color against the background + ), + ), + ), + ), + SizedBox(height: 5), + Text( + formatDateWithTime(claimsDate), + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), // Ensure text automatically wraps + ), + ], + )) + ], + ), + ), + ], + ), + ), + ])), + ), + ); + }, + ), + ]; + } + + List generateClaimsClosedList(List data) { + return [ + ListView.builder( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemCount: data.length, + itemBuilder: (BuildContext context, int index) { + var item = data[index]; + String claimsName = item['user_name']; + String claimsDate = item['date']; + String claimsSubject = item['subject']; + String claimsReplies = item['replies']; + String claimStatus = item['status_value']; + String claimsDepartmentName = item['department_name']; + List messageList = item['message_list']; + + final Map statusColors = { + 'Open': Colors.green, + 'Answered': Colors.blue, + 'Awaiting Reply': Colors.orange, + 'Inprogress': Colors.yellow, + 'Closed': Colors.red, + }; + + // Determine the color based on the claimStatus + Color statusColor; + if (claimStatus != null) { + statusColor = statusColors[claimStatus!] ?? Color(0xFF979797); + } else { + statusColor = Color(0xFF979797); // Default color if status is null + } + + return GestureDetector( + onTap: () { + Navigator.pushNamed(context, 'claimtracklist', arguments: item); + }, + child: MouseRegion( + cursor: SystemMouseCursors.click, + child: Card( + elevation: 0, + shape: RoundedRectangleBorder( + side: BorderSide( + color: Color(0xFFD9D9D9), // Set the border color here + width: 1.0, // Set the border width here + ), + borderRadius: BorderRadius.circular( + 8.0), // Set the border radius here + ), + child: Column(children: [ + Container( + decoration: BoxDecoration( + color: Colors + .white, // Set background color for the container + ), + padding: EdgeInsets.only( + top: 10, bottom: 10, left: 10, right: 10), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + flex: 7, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/tickets.png', + width: 40, + height: 40, + ), + SizedBox( + width: + 10), // Adjust space between icon and text + Container( + alignment: Alignment.centerLeft, + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Text( + claimsDepartmentName ?? '', + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 18 + : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ), + SizedBox(height: 5), + Text( + claimsSubject, + textAlign: TextAlign.left, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), // Ensure text automatically wraps + ), + ], + )) + ], + ), + ), + Expanded( + flex: 5, + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + // Adjust space between icon and text + Container( + alignment: Alignment.centerRight, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: + CrossAxisAlignment.end, + children: [ + Container( + width: 100, + decoration: BoxDecoration( + color: statusColor, + borderRadius: BorderRadius.circular( + 50), // Border radius set to 50 + ), + child: Padding( + padding: const EdgeInsets.all(5.0), + child: Text( + claimStatus, + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: Responsive.isDesktop( + context) + ? 12 + : 10, + fontWeight: FontWeight.w400, + color: Colors + .white, // Text color against the background + ), + ), + ), + ), + SizedBox(height: 5), + Text( + formatDateWithTime(claimsDate), + textAlign: TextAlign.right, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop(context) + ? 14 + : 12, + fontWeight: FontWeight.w400, + color: Color(0xFF777777), + ), // Ensure text automatically wraps + ), + ], + )) + ], + ), + ), + ], + ), + ), + ])), + ), + ); + }, + ), + ]; + } + + String formatDateWithTime(String timestamp) { + // Convert the timestamp string to milliseconds + int milliseconds = int.parse(timestamp) * 1000; + + // Create a DateTime object from milliseconds + DateTime date = DateTime.fromMillisecondsSinceEpoch(milliseconds); + + // Format the DateTime object with date and time + String formattedDate = DateFormat('d MMM, y HH:mm a').format(date); + + return formattedDate; + } +} diff --git a/lib/pages/home.dart b/lib/pages/postEnrollment/home.dart similarity index 90% rename from lib/pages/home.dart rename to lib/pages/postEnrollment/home.dart index fbb9444..81e709d 100644 --- a/lib/pages/home.dart +++ b/lib/pages/postEnrollment/home.dart @@ -5,16 +5,15 @@ import 'package:flutter_image_slideshow/flutter_image_slideshow.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:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; import 'package:http/http.dart' as http; - -import '../service/api_service.dart'; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; +import 'chatbot.dart'; class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @@ -154,6 +153,7 @@ class _MyAppState extends State { statusBarIconBrightness: Brightness.dark, // Light icons for status bar )); return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack(children: [ SingleChildScrollView( @@ -251,7 +251,11 @@ class _MyAppState extends State { width: double.infinity, /// Height of the [ImageSlideshow]. - height: 200, + height: + Responsive.isDesktop( + context) + ? 200 + : 150, /// The page to show when first creating the [ImageSlideshow]. initialPage: 0, @@ -397,24 +401,28 @@ class _MyAppState extends State { borderRadius: BorderRadius.circular(10), color: Colors.white, - child: TextButton( - onPressed: () {}, - style: TextButton.styleFrom( - padding: EdgeInsets.symmetric( - horizontal: Responsive - .isDesktop( - context) - ? 160 - : 60, + child: SizedBox( + width: Responsive.isDesktop( + context) + ? 400 + : 150, // Set the width here + child: TextButton( + onPressed: () {}, + style: + TextButton.styleFrom( + padding: EdgeInsets + .symmetric( vertical: Responsive .isDesktop( context) ? 12 - : 7), - ), - child: Text( - 'Active', - style: GoogleFonts.poppins( + : 7, + ), + ), + child: Text( + 'Active', + style: + GoogleFonts.poppins( fontSize: Responsive .isDesktop( context) @@ -422,8 +430,10 @@ class _MyAppState extends State { : 14, fontWeight: FontWeight.w500, - color: Color( - 0xFF593AFF)), + color: + Color(0xFF593AFF), + ), + ), ), ), ) @@ -460,35 +470,38 @@ class _MyAppState extends State { borderRadius: BorderRadius.circular(10), color: Colors.white, - child: TextButton( - onPressed: () {}, - style: TextButton.styleFrom( - padding: EdgeInsets.symmetric( - horizontal: Responsive - .isDesktop( - context) - ? 150 - : 60, + child: SizedBox( + width: Responsive.isDesktop( + context) + ? 400 + : 150, // Set the width here + child: TextButton( + onPressed: () {}, + style: + TextButton.styleFrom( + padding: EdgeInsets + .symmetric( vertical: Responsive .isDesktop( context) ? 12 - : 7), - // primary: Color(0xFF000000), - ), - child: Text( - 'Inactive', - style: - GoogleFonts.poppins( - fontSize: Responsive - .isDesktop( - context) - ? 18 - : 14, - color: - Color(0xFF593AFF), - fontWeight: - FontWeight.w500, + : 7, + ), + ), + child: Text( + 'Inactive', + style: + GoogleFonts.poppins( + fontSize: Responsive + .isDesktop( + context) + ? 18 + : 14, + fontWeight: + FontWeight.w500, + color: + Color(0xFF593AFF), + ), ), ), ), @@ -534,17 +547,15 @@ class _MyAppState extends State { ), ), ]), - // floatingActionButton: Responsive.isDesktop(context) - // ? null - // : FloatingActionButton( - // onPressed: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () => push(chatbot()), + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.miniCenterDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( @@ -599,7 +610,7 @@ class _MyAppState extends State { crossAxisCount: Responsive.isDesktop(context) ? 2 : 1, crossAxisSpacing: 20.0, mainAxisSpacing: 20.0, - childAspectRatio: Responsive.isDesktop(context) ? 3.2 : 3.6, + childAspectRatio: Responsive.isDesktop(context) ? 3.2 : 3.5, ), itemCount: data.length, itemBuilder: (BuildContext context, int index) { @@ -823,4 +834,14 @@ class _MyAppState extends State { ), ]; } + + void push(Widget page) { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return page; + }, + ), + ); + } } diff --git a/lib/pages/planclaimsform.dart b/lib/pages/postEnrollment/planclaimsform.dart similarity index 59% rename from lib/pages/planclaimsform.dart rename to lib/pages/postEnrollment/planclaimsform.dart index 3d2e1c0..5a22754 100644 --- a/lib/pages/planclaimsform.dart +++ b/lib/pages/postEnrollment/planclaimsform.dart @@ -2,18 +2,15 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:jwt_decode/jwt_decode.dart'; -import 'package:nhance_app_pwa/pages/policies.dart'; +import 'package:nhance_app_pwa/customAppBar/customAppBar.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/service/api_service.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.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 '../service/api_service.dart'; - class planclaimsform extends StatefulWidget { const planclaimsform({Key? key}) : super(key: key); @@ -225,6 +222,7 @@ class _planclaimsformState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack(children: [ SingleChildScrollView( @@ -269,14 +267,23 @@ class _planclaimsformState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( + decoration: BoxDecoration( + color: Color( + 0xFFFFFCE5), // Set background color for the container + borderRadius: BorderRadius.circular( + 10), // Set border radius for the container + ), padding: Responsive.isDesktop(context) ? EdgeInsets.only( - top: 15, - bottom: 15, - left: 25, - right: 25) + top: 20, + bottom: 20, + left: 0, + right: 0) : EdgeInsets.only( - top: 0, bottom: 0, left: 0, right: 0), + top: 10, + bottom: 10, + left: 10, + right: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.center, @@ -286,63 +293,52 @@ class _planclaimsformState extends State { MainAxisAlignment.start, children: [ Expanded( - flex: 12, + flex: 1, child: InkWell( onTap: () { Navigator.pushNamed( - context, 'claims'); + context, + fromClaimsPage == 0 + ? 'claims' + : 'help'); }, - child: Row( - mainAxisAlignment: - MainAxisAlignment.start, - children: [ - if (!Responsive.isDesktop( - context)) - Icon( - Icons.chevron_left, - // Replace with your desired icon - color: Color(0xFF000000), - size: 30, - ), - if (!Responsive.isDesktop( - context)) - SizedBox( - width: Responsive - .isDesktop( - context) - ? 0 - : 5), - // Adjust space between icon and text - Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .start, - children: [ - Text( - claimsDetails[ - 'policy_name'], - textAlign: - TextAlign.start, - style: - GoogleFonts.poppins( - fontSize: 16, - fontWeight: - FontWeight.w600, - color: - Color(0xFF000000), - ), - ), - ], - ), - ], + child: Icon( + Icons + .chevron_left, // Replace with your desired icon + color: Color(0xFF000000), + size: 30, ), ), ), + Expanded( + flex: 11, + child: Row( + mainAxisAlignment: + Responsive.isDesktop(context) + ? MainAxisAlignment.center + : MainAxisAlignment.start, + children: [ + Text( + fromClaimsPage == 0 + ? claimsDetails[ + 'policy_name'] + : 'Raise a Request', + textAlign: TextAlign.start, + style: GoogleFonts.poppins( + fontSize: + Responsive.isDesktop( + context) + ? 20 + : 16, + fontWeight: FontWeight.w600, + color: Color(0xFF000000), + ), + ) + ], + ), + ) ], - ), + ), // Space between rows // Add more rows as needed ], ), @@ -368,107 +364,41 @@ class _planclaimsformState extends State { key: formKey, child: Column( children: [ - !Responsive.isDesktop( - context) - ? Column( - children: [ - if (fromClaimsPage != - 0) - buildDropdownField( - 'Select Policy', - (value) { - setState( - () { - policyNumberId = - value; - }); - }, - fromClaimsPage == - 0, - policyNumberList, - 'policyName'), - buildDropdownField( - 'Service', - (value) { - setState(() { - serviceId = - value; - }); - }, - fromClaimsPage == - 0, - departmentList, - 'name'), - buildTextField( - 'Subject', - subjectController), - ], - ) - : Row( - children: [ - if (fromClaimsPage != - 0) ...[ - Expanded( - child: buildDropdownField( - 'Select Policy', - (value) { - setState( - () { - policyNumberId = - value; - }); - }, - fromClaimsPage == - 0, - policyNumberList, - 'policyName'), - ), - ], - if (fromClaimsPage != - 0) - SizedBox( - width: - 12), - Expanded( - child: buildDropdownField( - 'Service', - (value) { - setState( - () { - serviceId = - value; - }); - }, - fromClaimsPage == - 0, - departmentList, - 'name'), - ), - SizedBox( - width: 12), - Expanded( - child: buildTextField( - 'Subject', - subjectController)), - ], - ), - !Responsive.isDesktop( - context) - ? Column( - children: [ - buildTextAreaField( - 'Message', - messageController), - ], - ) - : Row( - children: [ - Expanded( - child: buildTextAreaField( - 'Message', - messageController)), - ], - ), + // Only show Select Policy field when Service value is 'Claims' + + buildDropdownField( + 'Service', + (value) { + setState(() { + serviceId = value; + // Reset policyNumberId if Service is changed + policyNumberId = + null; + }); + }, + fromClaimsPage == 0, + departmentList, + 'name', + ), + if (serviceId == 2 && + fromClaimsPage == 1) + buildDropdownField( + 'Select Policy', + (value) { + setState(() { + policyNumberId = + value; + }); + }, + fromClaimsPage == 0, + policyNumberList, + 'policyName', + ), + buildTextField('Subject', + subjectController), + buildTextAreaField( + 'Message', + messageController), ], ), ), @@ -528,17 +458,17 @@ class _planclaimsformState extends State { ), ), ]), - // floatingActionButton: Responsive.isDesktop(context) - // ? null - // : FloatingActionButton( - // onPressed: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () { + Navigator.pushNamed(context, 'chatbot'); + }, + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.centerDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( diff --git a/lib/pages/policies.dart b/lib/pages/postEnrollment/policies.dart similarity index 97% rename from lib/pages/policies.dart rename to lib/pages/postEnrollment/policies.dart index e9079b3..63e7578 100644 --- a/lib/pages/policies.dart +++ b/lib/pages/postEnrollment/policies.dart @@ -7,20 +7,18 @@ import 'package:flutter_image_slideshow/flutter_image_slideshow.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:shared_preferences/shared_preferences.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.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 'package:accordion/accordion.dart'; import 'package:flutter_svg/flutter_svg.dart'; -import '../service/api_service.dart'; - class policies extends StatefulWidget { const policies({Key? key}) : super(key: key); @@ -138,6 +136,7 @@ class _policiesState extends State { print(employeeDetails); } return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack(children: [ SingleChildScrollView( @@ -169,23 +168,22 @@ class _policiesState extends State { Row( mainAxisAlignment: MainAxisAlignment.start, children: [ - if (!Responsive.isDesktop(context)) - Expanded( - flex: 1, - child: InkWell( - onTap: () { - Navigator.pushNamed(context, 'home'); - }, - child: Icon( - Icons - .chevron_left, // Replace with your desired icon - color: Color(0xFF000000), - size: 30, - ), + Expanded( + flex: 1, + child: InkWell( + onTap: () { + Navigator.pushNamed(context, 'home'); + }, + child: Icon( + Icons + .chevron_left, // Replace with your desired icon + color: Color(0xFF000000), + size: 30, ), ), + ), Expanded( - flex: !Responsive.isDesktop(context) ? 11 : 12, + flex: 11, child: Row( mainAxisAlignment: Responsive.isDesktop(context) ? MainAxisAlignment.center @@ -944,17 +942,17 @@ class _policiesState extends State { ), ), ]), - // floatingActionButton: Responsive.isDesktop(context) - // ? null - // : FloatingActionButton( - // onPressed: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () { + Navigator.pushNamed(context, 'chatbot'); + }, + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.centerDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( diff --git a/lib/pages/privacypolicy.dart b/lib/pages/postEnrollment/privacypolicy.dart similarity index 99% rename from lib/pages/privacypolicy.dart rename to lib/pages/postEnrollment/privacypolicy.dart index b20536f..90e2e9d 100644 --- a/lib/pages/privacypolicy.dart +++ b/lib/pages/postEnrollment/privacypolicy.dart @@ -3,12 +3,10 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:jwt_decode/jwt_decode.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; import 'package:http/http.dart' as http; class privacypolicy extends StatefulWidget { @@ -32,6 +30,7 @@ class _privacypolicyState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Colors.white, body: Stack( children: [ SingleChildScrollView( diff --git a/lib/pages/profile.dart b/lib/pages/postEnrollment/profile.dart similarity index 94% rename from lib/pages/profile.dart rename to lib/pages/postEnrollment/profile.dart index fdace53..081e60a 100644 --- a/lib/pages/profile.dart +++ b/lib/pages/postEnrollment/profile.dart @@ -3,17 +3,15 @@ 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:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.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 '../service/api_service.dart'; - class profile extends StatefulWidget { const profile({Key? key}) : super(key: key); @@ -48,6 +46,7 @@ class _profileState extends State { dynamic selfEmpCode; dynamic selfFamilyFloaterKey; dynamic selfEmpStatus; + dynamic client_branch_id; void _onTabChanged(int index) { setState(() { @@ -78,6 +77,7 @@ class _profileState extends State { // Decode the JWT token received from the API response Map? 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'); @@ -105,7 +105,7 @@ class _profileState extends State { } print('check 1'); final response = await apiService.getSelfEmployeeProfileDetails( - client_id!, empCodeString!); + client_id!, empCodeString!, client_branch_id!); print('check 1'); if (response['status'] == 'success') { if (response.containsKey('data')) { @@ -149,6 +149,7 @@ class _profileState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Colors.white, appBar: CustomAppBar(), body: Stack(children: [ SingleChildScrollView( @@ -171,21 +172,27 @@ class _profileState extends State { Row( mainAxisAlignment: MainAxisAlignment.start, children: [ - if (!Responsive.isDesktop(context)) - Expanded( - flex: 1, - child: Container( - alignment: Alignment.topLeft, - padding: EdgeInsets.only(top: 10, left: 10), - child: Icon( + 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: Responsive.isDesktop(context) ? 12 : 11, + flex: 11, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -213,13 +220,12 @@ class _profileState extends State { Row( mainAxisAlignment: MainAxisAlignment.start, children: [ - if (!Responsive.isDesktop(context)) - Expanded( - flex: 1, - child: Container( - alignment: Alignment.topLeft, - padding: EdgeInsets.only(top: 10, left: 10), - child: Text(''))), + 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( @@ -585,17 +591,17 @@ class _profileState extends State { ), ), ]), - // floatingActionButton: Responsive.isDesktop(context) - // ? null - // : FloatingActionButton( - // onPressed: () { - // // Add your onPressed logic here - // }, - // child: Icon(Icons.add), - // ), + floatingActionButton: Responsive.isDesktop(context) + ? null + : FloatingActionButton( + onPressed: () { + Navigator.pushNamed(context, 'chatbot'); + }, + child: Icon(Icons.chat), + ), floatingActionButtonLocation: Responsive.isDesktop(context) ? null - : FloatingActionButtonLocation.centerDocked, + : FloatingActionButtonLocation.miniEndFloat, bottomNavigationBar: Responsive.isDesktop(context) ? null : CustomBottomNavigationBar( diff --git a/lib/service/api_service.dart b/lib/pages/postEnrollment/service/api_service.dart similarity index 78% rename from lib/service/api_service.dart rename to lib/pages/postEnrollment/service/api_service.dart index db6e764..a9ba08b 100644 --- a/lib/service/api_service.dart +++ b/lib/pages/postEnrollment/service/api_service.dart @@ -27,7 +27,7 @@ class ApiService { final url = Uri.parse( '${Environment.apiUrl}getEmployeeActiveOrInactivePolicy?client_id=$clientId&emp_code=$empCode&type=$status&client_branch_id=$branchID'); final headers = { - 'Authorization': _token ?? '', + 'Authorization': 'Bearer $_token' ?? '', }; final response = await _makeGetRequest(url, headers); return response; @@ -40,7 +40,7 @@ class ApiService { } final url = Uri.parse('${Environment.apiUrl}getAdvertisementImage'); final headers = { - 'Authorization': _token ?? '', + 'Authorization': 'Bearer $_token' ?? '', }; final response = await _makeGetRequest(url, headers); return response; @@ -53,22 +53,22 @@ class ApiService { } final url = Uri.parse('${Environment.apiUrl}getFEContent'); final headers = { - 'Authorization': _token ?? '', + 'Authorization': 'Bearer $_token' ?? '', }; final response = await _makeGetRequest(url, headers); return response; } Future> getSelfEmployeeProfileDetails( - String clientId, String empCode) async { + String clientId, String empCode, String branchID) async { print(_token); if (_token == null) { await _initializeToken(); } final url = Uri.parse( - '${Environment.apiUrl}getEmployeeProfile?emp_code=$empCode&client_id=$clientId'); + '${Environment.apiUrl}getEmployeeProfile?emp_code=$empCode&client_id=$clientId&client_branch_id=$branchID'); final headers = { - 'Authorization': Environment.ticketToken ?? '', + 'Authorization': 'Bearer $_token' ?? '', }; final response = await _makeGetRequest(url, headers); return response; @@ -148,4 +148,32 @@ class ApiService { ToastHelper.showErrorToast(context, 'Session Out'); Navigator.pushNamed(context, 'login'); } + + Future> getBotDetails(String requestFor, is_option, + option, returnMessage, mobileNo, policyID) async { + print('requestFor: $requestFor'); + print('is_option: $is_option'); + print('option: $option'); + print('returnMessage: $returnMessage'); + print('mobileNo: $mobileNo'); + print('policyID: $policyID'); + if (_token == null) { + await _initializeToken(); + } + final url; + if (is_option != '0') { + url = Uri.parse( + '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&option=$option&mobile_no=$mobileNo&policy_id=$policyID'); + } else { + url = Uri.parse( + '${Environment.apiUrl}getChatResponse?request_for=$requestFor&is_option=$is_option&text=$returnMessage&value=$option&mobile_no=$mobileNo&policy_id=$policyID'); + } + print(url); + + final headers = { + 'Authorization': 'Bearer $_token' ?? '', + }; + final response = await _makeGetRequest(url, headers); + return response; + } } diff --git a/lib/pages/termsofuse.dart b/lib/pages/postEnrollment/termsofuse.dart similarity index 99% rename from lib/pages/termsofuse.dart rename to lib/pages/postEnrollment/termsofuse.dart index 19a0e9c..3ad121a 100644 --- a/lib/pages/termsofuse.dart +++ b/lib/pages/postEnrollment/termsofuse.dart @@ -3,12 +3,10 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:jwt_decode/jwt_decode.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '../customAppBar/customAppBar.dart'; -import '../customAppBar/customFooter.dart'; -import '../customAppBar/tabs.dart'; -import '../customAppBar/responsive.dart'; -import '../customAppBar/toastHelper.dart'; -import '../models/environment.dart'; +import '../../customAppBar/customFooter.dart'; +import '../../customAppBar/responsive.dart'; +import '../../customAppBar/tabs.dart'; +import '../../customAppBar/toastHelper.dart'; import 'package:http/http.dart' as http; class termsofuse extends StatefulWidget { @@ -32,6 +30,7 @@ class _termsofuseState extends State { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Colors.white, body: Stack( children: [ SingleChildScrollView( diff --git a/lib/pages/verify.dart b/lib/pages/verify.dart index 630b203..691d5d6 100644 --- a/lib/pages/verify.dart +++ b/lib/pages/verify.dart @@ -27,12 +27,14 @@ class _MyVerifyState extends State { int _secondsRemaining = 30; bool _isTimerRunning = false; dynamic empCodeString; + dynamic empClientBranchId; dynamic empPrimaryId; dynamic gpaEmpName; dynamic client_id; dynamic _token; dynamic clientName; dynamic clientLogo; + dynamic emp_status; @override void initState() { @@ -65,10 +67,15 @@ class _MyVerifyState extends State { Future checkTokenAvailability() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); final String? token = prefs.getString('token'); + final String? emp_status = prefs.getString('emp_status'); if (token != null && token.isNotEmpty) { // Token available, navigate to home page - Navigator.pushReplacementNamed(context, 'home'); + if (emp_status == 'enrolled') { + Navigator.pushReplacementNamed(context, 'home'); + } else { + Navigator.pushReplacementNamed(context, 'empDetails'); + } } } @@ -120,7 +127,7 @@ class _MyVerifyState extends State { if (response.statusCode == 200) { Map data = json.decode(response.body); - print(data); + print('data: $data'); _token = data['data']; String status = data['status']; print(status); @@ -130,7 +137,9 @@ class _MyVerifyState extends State { // Decode the JWT token received from the API response Map? decodedToken = Jwt.parseJwt(data['data']); - print(decodedToken); + print('decodedToken : $decodedToken'); + empClientBranchId = decodedToken['client_branch_id']; + prefs.setString('empClientBranchId', empClientBranchId); empCodeString = decodedToken['emp_code'].toString(); prefs.setString('empCode', empCodeString); empPrimaryId = decodedToken['id']; @@ -139,6 +148,8 @@ class _MyVerifyState extends State { prefs.setString('gpaEmpName', gpaEmpName); client_id = decodedToken['client_id']; prefs.setString('client_id', client_id); + emp_status = decodedToken['emp_status']; + prefs.setString('emp_status', emp_status); getClientLogoAndDetails(); print('Successfully Login'); @@ -147,13 +158,16 @@ class _MyVerifyState extends State { final token = prefs.getString('token'); if (token != null && token.isNotEmpty) { ToastHelper.showSuccessToast(context, 'Successfully Login'); - Navigator.pushReplacementNamed(context, 'home', - arguments: {'mobile': ''}); + if (emp_status == 'enrolled') { + Navigator.pushReplacementNamed(context, 'home'); + } else { + Navigator.pushReplacementNamed(context, 'empDetails'); + } } 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, 'phone'); + Navigator.pushReplacementNamed(context, 'login'); } } else { ToastHelper.showErrorToast(context, 'Invalid OTP. Please try again'); @@ -462,7 +476,7 @@ class _MyVerifyState extends State { ..onTap = () { // Navigate to the page where the user can change the phone number Navigator.pushNamed( - context, 'phone'); + context, 'login'); }, ), ], diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 48b0136..224c0fd 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,11 +8,15 @@ import Foundation import path_provider_foundation import shared_preferences_foundation import smart_auth +import sqflite import url_launcher_macos +import video_player_avfoundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SmartAuthPlugin.register(with: registry.registrar(forPlugin: "SmartAuthPlugin")) + SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) + FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin")) } diff --git a/pubspec.yaml b/pubspec.yaml index 55ead05..4f8f286 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,6 +52,10 @@ dependencies: accordion: ^2.6.0 url_launcher: ^6.2.6 flutter_svg: ^2.0.10+1 + webview_flutter: ^4.8.0 + webview_flutter_android: ^3.16.4 + path_provider: ^2.1.3 + dash_chat_2: ^0.0.21 dev_dependencies: flutter_test: diff --git a/test/widget_test.dart b/test/widget_test.dart index c15ecc2..73164d4 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -9,7 +9,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:nhance_app_pwa/main.dart'; -import 'package:nhance_app_pwa/pages/home.dart'; +import 'package:nhance_app_pwa/pages/postEnrollment/home.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { diff --git a/web/index.html b/web/index.html index f2925a2..65eedfa 100644 --- a/web/index.html +++ b/web/index.html @@ -63,7 +63,7 @@ @@ -96,5 +96,6 @@ } },5000); }; +