import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:nhancepolicy/customAppBar/toastHelper.dart'; import 'package:nhancepolicy/models/environment.dart'; import 'package:nhancepolicy/responsive.dart'; import 'package:nhancepolicy/service/api_service.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'customAppBar/customAppBar.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, 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, 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, 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, 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, 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, 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; } }