enrollment-app/lib/addons.dart
2026-03-26 09:45:12 +05:30

4747 lines
254 KiB
Dart
Executable File

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/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';
import 'customAppBar/customFooter.dart';
import 'package:nhancepolicy/logger.dart';
class addOnsDetails extends StatefulWidget {
const addOnsDetails({Key? key}) : super(key: key);
@override
State<addOnsDetails> createState() => _addOnsDetailsState();
}
class _addOnsDetailsState extends State<addOnsDetails> {
late ApiService apiService;
bool isLoading = true;
bool isChecked = false;
bool login_by_hr = 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 gmcPolicyType;
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 topUpPolicyType;
dynamic topUpSiPremiumValue;
dynamic topUpSiValue;
dynamic topUpSiSelectedSI;
dynamic topUpSiPolicies = [];
dynamic topUpTypeName;
int topUpOpenForEnrollment = 0;
dynamic topUpSiParentPolicies = [];
dynamic topUpParentClientPolicyId;
dynamic topUpParentSlabRates;
dynamic topUpParentPolicyName;
dynamic topUpParentPolicyType;
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 addOnsDependentPolicyType;
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<Map<String, String>> relationshipOptions = [];
List<Map<String, String>> selectedRelationships = [];
List<Map<String, dynamic>> formDataList = [];
late DateTime _selectedDate = DateTime.now(); // Define _selectedDate here
dynamic iAgreeForAddOn = [];
dynamic gmcDataIsEmpty = 1;
dynamic gpaDataIsEmpty = 1;
dynamic empRefId;
dynamic empClientBranchId;
dynamic selfEmpStatus;
@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();
}
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<void> _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<String, dynamic>? decodedToken = Jwt.parseJwt(token);
logDebug(decodedToken);
selfEmpStatus = prefs.getString('selfEmpStatus');
empClientBranchId = prefs.getString('empClientBranchId');
empCodeString = prefs.getString('empCode');
logDebug(empCodeString); // Check if emp_code is correct
empPrimaryId = prefs.getString('empPrimaryId');
gpaEmpName = prefs.getString('gpaEmpName');
client_id = prefs.getString('client_id');
logDebug(client_id);
// logDebug(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<void> getClientLogoAndDetails() async {
try {
if (client_id == null ||
empCodeString == null ||
empClientBranchId == null) {
return;
}
final response = await apiService.getClientLogoAndDetailsToApi(
client_id!, empCodeString!, empClientBranchId!);
logDebug('check 1');
if (response['status'] == 'success') {
if (response.containsKey('data')) {
dynamic clientDetails = response['data'];
logDebug(clientDetails);
clientName = clientDetails['client']['client_name'];
logDebug(clientName);
clientLogo = clientDetails['client']['client_logo'];
logDebug(clientLogo);
} else {
// Handle other status messages if needed
// ToastHelper.showErrorToast(
// context, 'API request failed with status: ${data['status']}');
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGpaEmpPolicyDetails(empPrimaryId) async {
try {
if (client_id == null ||
empCodeString == null ||
empClientBranchId == null) {
return;
}
final SharedPreferences prefs = await SharedPreferences.getInstance();
if (prefs.containsKey('hrtoken')) {
setState(() {
login_by_hr = true;
});
}
final response = await apiService.getGpaEmpPolicyDetailsToApi(
empPrimaryId,
empCodeString!,
client_id!,
'GPA',
empClientBranchId!,
login_by_hr);
if (response['status'] == 'success') {
setState(() {
gpaPolicies = response['data'];
logDebug('gpaPolicies');
});
} else {
setState(() {
gpaDataIsEmpty = 0;
});
// Handle other status codes
ToastHelper.showWarningToast(context, 'Something went wrong');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGmcEmpPolicyDetails(empPrimaryId) async {
try {
if (client_id == null ||
empCodeString == null ||
empClientBranchId == null) {
return;
}
final SharedPreferences prefs = await SharedPreferences.getInstance();
if (prefs.containsKey('hrtoken')) {
setState(() {
login_by_hr = true;
});
}
final response = await apiService.getGmcEmpPolicyDetailsToApi(
empPrimaryId,
empCodeString!,
client_id!,
'GMC',
empClientBranchId!,
login_by_hr);
if (response['status'] == 'success') {
// setState(() {
gmcPolicies = response['data'];
logDebug('gmcPolicies');
// });
// Assuming data is a List
logDebug(gmcPolicies);
} else {
setState(() {
gmcDataIsEmpty = 0;
});
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> 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'];
logDebug('topUpSiPolicies');
logDebug(topUpSiPolicies);
});
if (topUpSiPolicies.isNotEmpty) {
// setState(() {
topUpClientPolicyId =
await topUpSiPolicies['gmc_si_topup']['client_policy_id'];
topUpSlabRates = await topUpSiPolicies['gmc_si_topup']['SlabRates'];
logDebug('topUpSlabRates');
logDebug(topUpSlabRates);
topUpPolicyName =
await topUpSiPolicies['gmc_si_topup']['policy_name'];
topUpPolicyType = await topUpSiPolicies['gmc_si_topup']['type'];
topUpFamilyFloater = await topUpSiPolicies['gmc_si_topup']
['policy_terms']['family_floater'];
logDebug('topUpFamilyFloater');
logDebug(topUpFamilyFloater);
topUpMappedFamilyFloatersSi = await topUpSiPolicies['gmc_si_topup']
['family_floaters_of_only_si_array'];
logDebug('topUpMappedFamilyFloatersSi');
logDebug(topUpMappedFamilyFloatersSi);
logDebug('topUpECardDownload');
topUpECardDownload =
topUpSiPolicies['gmc_si_topup']['eCardDownload'];
logDebug(topUpECardDownload);
String intOpenForEnrollment =
topUpSiPolicies['gmc_si_topup']['OpenForEnrollment'];
topUpOpenForEnrollment = int.parse(intOpenForEnrollment);
logDebug(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) {
logDebug('topUpSiSelectedSI');
setState(() {
_topUpSiSwitcher = true;
topUpSiPremiumValue = (topUpSiPolicies['gmc_si_topup']
['family_floaters_of_only_si_premium_value'] as double)
.toInt();
topUpSiPremiumGst = (topUpSiPolicies['gmc_si_topup']
['family_floaters_of_only_si_gst_value'] as double)
.toInt();
topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst;
});
}
// });
} else {
// ToastHelper.showErrorToast(
// context, 'No data found in the response');
logDebug('No data found in the response');
}
} else {
// Handle other status messages if needed
// ToastHelper.showErrorToast(
// context, 'API request failed with status: ${data['status']}');
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> 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'];
logDebug('topUpSiParentPolicies');
logDebug(topUpSiParentPolicies);
});
if (topUpSiParentPolicies.isNotEmpty) {
// setState(() {
topUpParentClientPolicyId =
await topUpSiParentPolicies['gmc_si_parent_topup']
['client_policy_id'];
topUpParentSlabRates =
await topUpSiParentPolicies['gmc_si_parent_topup']['SlabRates'];
logDebug('topUpParentSlabRates');
logDebug(topUpParentSlabRates);
topUpParentPolicyName =
await topUpSiParentPolicies['gmc_si_parent_topup']
['policy_name'];
topUpParentPolicyType =
await topUpSiParentPolicies['gmc_si_parent_topup']['type'];
topUpParentFamilyFloater =
await topUpSiParentPolicies['gmc_si_parent_topup']
['policy_terms']['family_floater'];
logDebug('topUpParentFamilyFloater');
logDebug(topUpParentFamilyFloater);
topUpParentMappedFamilyFloatersSi =
await topUpSiParentPolicies['gmc_si_parent_topup']
['family_floaters_of_only_si_array'];
logDebug('topUpParentMappedFamilyFloatersSi');
logDebug(topUpParentMappedFamilyFloatersSi);
logDebug('topUpECardDownload');
topUpParentECardDownload =
topUpSiParentPolicies['gmc_si_parent_topup']['eCardDownload'];
logDebug(topUpParentECardDownload);
String intOpenForEnrollment =
topUpSiParentPolicies['gmc_si_parent_topup']
['OpenForEnrollment'];
topUpParentOpenForEnrollment = int.parse(intOpenForEnrollment);
logDebug(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) {
logDebug('topUpParentSiSelectedSI');
setState(() {
_topUpParentSiSwitcher = true;
topUpParentSiPremiumValue =
(topUpSiParentPolicies['gmc_si_parent_topup']
['family_floaters_of_only_si_premium_value']
as double)
.toInt();
topUpParentSiPremiumGst =
(topUpSiParentPolicies['gmc_si_parent_topup']
['family_floaters_of_only_si_gst_value'] as double)
.toInt();
topUpParentSiTotalAmt =
topUpParentSiPremiumValue + topUpParentSiPremiumGst;
});
}
// });
} else {
// ToastHelper.showErrorToast(
// context, 'No data found in the response');
logDebug('No data found in the response');
}
} else {
// Handle other status messages if needed
// ToastHelper.showErrorToast(
// context, 'API request failed with status: ${data['status']}');
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> 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'];
logDebug('addOnsDependentPolicies');
logDebug(addOnsDependentPolicies);
});
if (addOnsDependentPolicies.isNotEmpty) {
// setState(() {
addOnsDependentClientPolicyId =
addOnsDependentPolicies['gmc_dependent_addon']
['client_policy_id'];
addOnsDependentSlabRates =
await addOnsDependentPolicies['gmc_dependent_addon']
['SlabRates'];
logDebug(addOnsDependentSlabRates);
addOnsDependentPolicyName =
await addOnsDependentPolicies['gmc_dependent_addon']
['policy_name'];
addOnsDependentPolicyType =
await addOnsDependentPolicies['gmc_dependent_addon']['type'];
addOnsDependentFamilyFloater =
await addOnsDependentPolicies['gmc_dependent_addon']
['policy_terms']['family_floater'];
logDebug('addOnsDependentFamilyFloater');
logDebug(addOnsDependentFamilyFloater);
setState(() {
addOnsDependentMappedFamilyFloatersDependent =
addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_si_array'];
logDebug('addOnsDependentMappedFamilyFloatersDependent');
logDebug(addOnsDependentMappedFamilyFloatersDependent);
});
addOnsdependentValue =
await addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_si_value'];
addOnsSelectedDependent = await addOnsdependentValue != 0
? addOnsdependentValue.toString()
: null;
if (addOnsSelectedDependent != null) {
setState(() {
_addOnsDependentSwitcher = true;
addOnDependentPremiumValue = (addOnsDependentPolicies[
'gmc_dependent_addon'][
'family_floaters_of_dependent_and_si_premium_value']
as double)
.toInt();
addOnsDependentPremiumGst =
(addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_gst_value']
as double)
.toInt();
addOnsDependentTotalAmt =
addOnDependentPremiumValue + addOnsDependentPremiumGst;
});
addOnsDependentECardDownload =
addOnsDependentPolicies['gmc_dependent_addon']
['eCardDownload'];
logDebug('addOnsDependentECardDownload');
logDebug(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');
logDebug('No data found in the response');
}
} else {
// Handle other status messages if needed
// ToastHelper.showErrorToast(
// context, 'API request failed with status: ${data['status']}');
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> 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<String> relationships =
// List<String>.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');
logDebug('Error fetching relationship list: $error');
// Handle error accordingly, e.g., show a snackbar with an error message
}
}
Future<void> _selectDate(BuildContext context, formType) async {
logDebug(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
logDebug(min);
logDebug(max);
late DateTime minDate;
late DateTime maxDate;
final DateTime now = DateTime.now();
maxDate = DateTime(now.year - min, now.month, now.day);
logDebug(maxDate);
minDate = DateTime(now.year - max, now.month, now.day);
logDebug(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<void> deleteItem(Map<String, dynamic> deletedItem) async {
logDebug(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');
logDebug('Item deleted successfully');
} else {
// Handle errors
ToastHelper.showErrorToast(context, 'Failed to delete item');
}
} catch (error) {
// Handle network errors
logDebug('Error deleting item: $error');
}
}
void saveAddOnsDetails(Map<String, dynamic> formData,
Map<String, dynamic> floatedData, action) async {
// Construct the array of objects
logDebug(formData);
logDebug(floatedData);
logDebug(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...');
logDebug('Form data sent successfully.');
} else {
// Request failed, handle error
ToastHelper.showErrorToast(context, 'Failed');
logDebug('Failed to send form data. Error: ${response}');
}
}
void cancelPopUp() {
formDataList.clear();
selectedRelationships.clear();
_relationShipController.clear();
_memberNameController.clear();
_dobController.clear();
}
void sendAddonsGmcDependentToAPI() async {
logDebug(_addOnsDependentSwitcher);
logDebug('continue');
logDebug(addOnsSelectedDependent);
if (_addOnsDependentSwitcher == true) {
if (addOnsSelectedDependent == null || addOnsSelectedDependent.isEmpty) {
return; // Return if addOnsSelectedDependent is null or empty
} else {
logDebug('createOrUpdateEmployeePolicySiAmount');
try {
dynamic getTrueObjects = addOnsDependentMappedFamilyFloatersDependent
.where((element) => element['is_value_exist'] == true)
.toList();
logDebug(getTrueObjects);
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
logDebug(getTrueDataObjects);
List<Map<String, String>> selectedValues = [];
// try {
logDebug('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<String, String> floaterData = {
'basic_cover_si': addOnsSelectedDependent,
'client_policy_id': client_policy_id,
'employee_id': employee_id,
'client_id': client_id,
'emp_code': empCodeString,
'client_branch_id': empClientBranchId,
};
// Add the map to the list
selectedValues.add(floaterData);
}
logDebug(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!');
logDebug('Saved successfully!');
} else {
// Failed to save member
// ToastHelper.showErrorToast(context, "Operation Failed!");
ToastHelper.showErrorToast(context, 'Failed to save');
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
// ToastHelper.showErrorToast(context, "Error saving family members");
}
}
} else {
// Navigator.pushNamed(context, 'empReviewDetails');
}
}
void sendAddonsGmcSiToAPI() async {
logDebug(_topUpSiSwitcher);
logDebug('continue');
logDebug(topUpSiSelectedSI);
if (_topUpSiSwitcher == true) {
if (topUpSiSelectedSI == null || topUpSiSelectedSI.isEmpty) {
logDebug('topUpSiSelectedSI');
return; // Return if addOnsSelectedDependent is null or empty
} else {
logDebug('createOrUpdateEmployeePolicySiAmount');
try {
dynamic getTrueObjects = topUpMappedFamilyFloatersSi
.where((element) => element['is_value_exist'] == true)
.toList();
logDebug(getTrueObjects);
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
logDebug(getTrueDataObjects);
List<Map<String, String>> selectedValues = [];
// try {
logDebug('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<String, String> floaterData = {
'basic_cover_si': topUpSiSelectedSI,
'client_policy_id': client_policy_id,
'employee_id': employee_id,
'client_id': client_id,
'emp_code': empCodeString,
'client_branch_id': empClientBranchId,
};
// Add the map to the list
selectedValues.add(floaterData);
}
logDebug(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!');
logDebug('Saved successfully!');
} else {
// Failed to save member
// ToastHelper.showErrorToast(context, "Operation Failed!");
// ToastHelper.showSuccessToast(context, 'Failed to Save...');
logDebug('Failed to Save...');
}
} catch (error) {
logDebug('Error saving family members');
// ToastHelper.showErrorToast(context, "Error saving family members");
}
}
} else {
// Navigator.pushNamed(context, 'empReviewDetails');
}
}
void sendAddonsGmcParentSiToAPI() async {
logDebug(_topUpParentSiSwitcher);
logDebug('continue');
logDebug(topUpParentSiSelectedSI);
if (_topUpParentSiSwitcher == true) {
if (topUpParentSiSelectedSI == null || topUpParentSiSelectedSI.isEmpty) {
logDebug('topUpSiSelectedSI');
return; // Return if addOnsSelectedDependent is null or empty
} else {
logDebug('createOrUpdateEmployeePolicySiAmount');
try {
dynamic getTrueObjects = topUpParentMappedFamilyFloatersSi
.where((element) => element['is_value_exist'] == true)
.toList();
logDebug(getTrueObjects);
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
logDebug(getTrueDataObjects);
List<Map<String, String>> selectedValues = [];
// try {
logDebug('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<String, String> floaterData = {
'basic_cover_si': topUpParentSiSelectedSI,
'client_policy_id': client_policy_id,
'employee_id': employee_id,
'client_id': client_id,
'emp_code': empCodeString,
'client_branch_id': empClientBranchId,
};
// Add the map to the list
selectedValues.add(floaterData);
}
logDebug(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!');
logDebug('Saved successfully!');
} else {
// Failed to save member
// ToastHelper.showErrorToast(context, "Operation Failed!");
// ToastHelper.showSuccessToast(context, 'Failed to Save...');
logDebug('Failed to Save...');
}
} catch (error) {
logDebug('Error saving family members');
// ToastHelper.showErrorToast(context, "Error saving family members");
}
}
} else {
// Navigator.pushNamed(context, 'empReviewDetails');
}
}
Future<void> removeAddonsGmcDependentToAPI() async {
try {
if (empCodeString == null || addOnsDependentClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcDependentToAPI(
empCodeString!, addOnsDependentClientPolicyId!);
if (response['status'] == 'success') {
logDebug(response['data']);
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> removeAddonsGmcSiToAPI() async {
try {
if (empCodeString == null || topUpClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcSiToAPI(
empCodeString!, topUpClientPolicyId!);
if (response['status'] == 'success') {
logDebug(response['data']);
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> removeAddonsGmcParentSiToAPI() async {
try {
if (empCodeString == null || topUpParentClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcParentSiToAPI(
empCodeString!, topUpParentClientPolicyId!);
if (response['status'] == 'success') {
logDebug(response['data']);
} else {
// Handle other status codes
// ToastHelper.showErrorToast(
// context, 'Request failed with status: ${response.statusCode}');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('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 {
logDebug(choosedSiValue);
var calculation = {
'client_policy_id': topUpClientPolicyId,
'emp_code': empCodeString,
'si': choosedSiValue,
'client_branch_id': empClientBranchId
};
logDebug(calculation);
// Iterate through familyMembers list and send each member's data to the API
final response = await apiService.topUpSiCalculationToAPI(calculation);
if (response['status'] == 'success') {
logDebug(response);
List<dynamic>? topUpEmpArray;
for (var item in response['data']) {
if (item.containsKey(empCodeString)) {
topUpEmpArray = item[empCodeString];
break;
}
}
if (topUpEmpArray != null) {
logDebug('Array for emp_code $empCodeString:');
logDebug(topUpEmpArray);
double topUpRataPremimumSum = 0;
for (var item in topUpEmpArray) {
var topUpRataPremimum = item['policy_details']['rata_premimum'];
if (topUpRataPremimum != null) {
topUpRataPremimumSum += topUpRataPremimum;
}
}
logDebug('Sum of rata_premimum: $topUpRataPremimumSum');
double topUpGstSum = 0;
for (var item in topUpEmpArray) {
var topUpGst = item['policy_details']['gst'];
if (topUpGst != null) {
topUpGstSum += topUpGst;
}
}
logDebug('Sum of gst: $topUpGstSum');
setState(() {
topUpSiPremiumValue = (topUpRataPremimumSum as double).toInt();
logDebug(topUpSiPremiumValue);
topUpSiPremiumGst = (topUpGstSum as double).toInt();
logDebug(topUpSiPremiumGst);
topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst;
logDebug(topUpSiTotalAmt);
});
sendAddonsGmcSiToAPI();
} else {
logDebug('Array not found for emp_code $empCodeString');
}
} else {
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
// ToastHelper.showErrorToast(context, "Error saving family members");
}
}
void topUpParentSiCalculation(choosedSiValue) async {
try {
logDebug(choosedSiValue);
var calculation = {
'client_policy_id': topUpParentClientPolicyId,
'emp_code': empCodeString,
'si': choosedSiValue,
'client_branch_id': empClientBranchId
};
logDebug(calculation);
// Iterate through familyMembers list and send each member's data to the API
final response =
await apiService.topUpParentSiCalculationToAPI(calculation);
if (response['status'] == 'success') {
logDebug(response['data']);
List<dynamic>? topUpEmpArray;
for (var item in response['data']) {
if (item.containsKey(empCodeString)) {
topUpEmpArray = item[empCodeString];
break;
}
}
if (topUpEmpArray != null) {
logDebug('Array for emp_code $empCodeString:');
logDebug(topUpEmpArray);
double topUpRataPremimumSum = 0;
for (var item in topUpEmpArray) {
var topUpRataPremimum = item['policy_details']['rata_premimum'];
if (topUpRataPremimum != null) {
topUpRataPremimumSum += topUpRataPremimum;
}
}
logDebug('Sum of rata_premimum: $topUpRataPremimumSum');
double topUpGstSum = 0;
for (var item in topUpEmpArray) {
var topUpGst = item['policy_details']['gst'];
if (topUpGst != null) {
topUpGstSum += topUpGst;
}
}
logDebug('Sum of gst: $topUpGstSum');
setState(() {
topUpParentSiPremiumValue =
(topUpRataPremimumSum as double).toInt();
logDebug(topUpParentSiPremiumValue);
topUpParentSiPremiumGst = (topUpGstSum as double).toInt();
logDebug(topUpSiPremiumGst);
topUpParentSiTotalAmt =
topUpParentSiPremiumValue + topUpParentSiPremiumGst;
logDebug(topUpParentSiTotalAmt);
});
sendAddonsGmcParentSiToAPI();
} else {
logDebug('Array not found for emp_code $empCodeString');
}
} else {
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
// ToastHelper.showErrorToast(context, "Error saving family members");
}
}
void addOnsDependentCalculation(choosedDependentValue) async {
try {
logDebug(choosedDependentValue);
var calculation = {
'client_policy_id': addOnsDependentClientPolicyId,
'emp_code': empCodeString,
'si': choosedDependentValue,
'client_branch_id': empClientBranchId
};
logDebug(calculation);
// Iterate through familyMembers list and send each member's data to the API
final response =
await apiService.addOnsDependentCalculationToAPI(calculation);
if (response['status'] == 'success') {
logDebug(response['data']);
List<dynamic>? addOnsEmpArray;
for (var item in response['data']) {
if (item.containsKey(empCodeString)) {
addOnsEmpArray = item[empCodeString];
break;
}
}
if (addOnsEmpArray != null) {
logDebug('Array for emp_code $empCodeString:');
logDebug(addOnsEmpArray);
double addOnsRataPremimumSum = 0;
for (var item in addOnsEmpArray) {
var addOnsRataPremimum = item['policy_details']['rata_premimum'];
if (addOnsRataPremimum != null) {
addOnsRataPremimumSum += addOnsRataPremimum;
}
}
logDebug('Sum of rata_premimum: $addOnsRataPremimumSum');
double addOnsGstSum = 0;
for (var item in addOnsEmpArray) {
var addOnsGst = item['policy_details']['gst'];
if (addOnsGst != null) {
addOnsGstSum += addOnsGst;
}
}
logDebug('Sum of gst: $addOnsGstSum');
setState(() {
addOnDependentPremiumValue =
(addOnsRataPremimumSum as double).toInt();
logDebug(addOnDependentPremiumValue);
addOnsDependentPremiumGst = (addOnsGstSum as double).toInt();
logDebug(addOnsDependentPremiumGst);
addOnsDependentTotalAmt =
addOnDependentPremiumValue + addOnsDependentPremiumGst;
logDebug(topUpSiTotalAmt);
});
} else {
logDebug('Array not found for emp_code $empCodeString');
}
} else {
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
// ToastHelper.showErrorToast(context, "Error saving family members");
}
}
Future<void> sendAddOnAPI() async {
setState(() {
isLoading = true;
});
logDebug('sendAddOnAPI');
if (gpaDataIsEmpty != 0) {
logDebug('gpaDataIsEmpty : $gpaDataIsEmpty');
for (var item in gpaPolicies) {
logDebug('ClientPolicyId');
// Extract ClientPolicyId value from each object
String clientPolicyId = item['ClientPolicyId'];
// Convert to integer and add to iAgreeForAddOn list
iAgreeForAddOn.add(int.parse(clientPolicyId));
}
}
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));
}
}
logDebug('iAgreeForAddOn');
iAgreeForAddOn = iAgreeForAddOn.toSet().toList();
logDebug(iAgreeForAddOn); // Output: [90, 92, 88, 89]
Map<String, dynamic> 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') {
setState(() {
isLoading = false;
isChecked = false;
});
logDebug('response.statusCode == 200');
ToastHelper.showSuccessToast(context, 'Saved Successfully...');
} else {
setState(() {
isLoading = false;
});
// Handle other status codes
ToastHelper.showErrorToast(context, 'failed to save');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
setState(() {
isLoading = false;
});
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> backFunction() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
if (prefs.containsKey('hrtoken')) {
String? mobileNo = prefs.getString('fromHrLoginMobileNo');
logDebug('mobileNo');
logDebug(mobileNo);
Navigator.pushNamed(context, 'empDetails',
arguments: {'mobile': mobileNo});
} else {
Navigator.pushNamed(context, 'empDetails');
}
}
void checkSiTopUp() async {
logDebug('checkSiTopUp');
List<Map<String, dynamic>> siData = [
{
'topUpSiPremiumValue': topUpSiPremiumValue,
'topUpSiPremiumGst': topUpSiPremiumGst,
'topUpSiTotalAmt': topUpSiTotalAmt,
}
];
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('siData', jsonEncode(siData));
}
void checkSiParentTopUp() async {
logDebug('checkSiParentTopUp');
List<Map<String, dynamic>> siParentData = [
{
'topUpParentSiPremiumValue': topUpParentSiPremiumValue,
'topUpParentSiPremiumGst': topUpParentSiPremiumGst,
'topUpParentSiTotalAmt': topUpParentSiTotalAmt,
}
];
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('siParentData', jsonEncode(siParentData));
}
void checkDependentTopUp() async {
logDebug('checkDependentTopUp');
List<Map<String, dynamic>> dependentData = [
{
'addOnDependentPremiumValue': addOnDependentPremiumValue,
'addOnsDependentPremiumGst': addOnsDependentPremiumGst,
'addOnsDependentTotalAmt': addOnsDependentTotalAmt,
}
];
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('dependentData', jsonEncode(dependentData));
}
@override
Widget build(BuildContext context) {
logDebug('CVC');
logDebug('Check1: $topUpSiPolicies');
logDebug('CVC');
logDebug('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<Widget> familyFloaterContainers = [];
if (addOnsDependentMappedFamilyFloatersDependent != null) {
for (var floater in addOnsDependentMappedFamilyFloatersDependent) {
bool isValueExist = floater['is_value_exist'];
Map<String, dynamic> 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: 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)
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
...generateGpaCards(gpaPolicies),
],
),
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)
? 20
: 16,
fontWeight:
FontWeight.w600,
),
),
Text(
'',
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: Colors
.green, // 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<Widget>((item) {
Map<String, dynamic> 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)
? 20
: 16,
fontWeight:
FontWeight.w600,
),
),
Text(
'',
textAlign:
TextAlign.left,
style: GoogleFonts
.poppins(
fontSize: Responsive
.isDesktop(
context)
? 18
: 14,
),
),
],
))),
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: Colors
.green, // 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<Widget>((item) {
Map<String, dynamic> 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(
'',
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: Colors
.green, // Color when the switch is ON
inactiveTrackColor:
Colors.grey),
],
))),
],
),
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 {
logDebug('checkSiTopUp');
checkSiTopUp();
}
if (_topUpParentSiSwitcher ==
false) {
removeAddonsGmcParentSiToAPI();
} else {
logDebug('checkSiParentTopUp');
checkSiParentTopUp();
}
if (_addOnsDependentSwitcher ==
false) {
removeAddonsGmcDependentToAPI();
} else {
logDebug('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),
),
),
),
)),
],
),
),
),
SizedBox(height: 30),
],
),
),
),
if (isLoading)
Container(
color: Color(0x98FFFCE5), // Semi-transparent background
child: Center(
child: // Your GIF loader widget
Image.asset(
height: 60,
width: 60,
'assets/nhance-loader.gif'), // Adjust path to your GIF loader
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity, // Make the footer full width
child: CustomFooter(),
),
),
]));
}
}
Future<void> _launchURL(String url) async {
final Uri uri = Uri.parse(url); // Parse the URL properly
logDebug('_launchURL $uri');
if (uri != null) {
logDebug('If $uri');
await launchUrl(uri, mode: LaunchMode.externalApplication);
} else {
logDebug('else $uri');
throw 'Could not launch $url';
}
}
void openForm(Map<String, dynamic> floaterData, action) {
logDebug(action);
logDebug(floaterData);
logDebug(relationshipOptions);
logDebug('test');
logDebug(_relationShipController);
logDebug(_memberNameController);
logDebug(_dobController);
dynamic popupName = floaterData['button_name'];
// Check if the action is 'Edit'
selectedRelationships = relationshipOptions
.where(
(option) => option['dependent'] == floaterData['form_type'],
)
.toList();
logDebug(selectedRelationships);
logDebug(addOnsDependentMappedFamilyFloatersDependent);
if (action == 'Add') {
if (floaterData['form_type'] == 'parent_in_law' ||
floaterData['form_type'] == 'parent') {
logDebug('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();
logDebug(getTrueObjects);
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
logDebug(getTrueDataObjects);
selectedRelationships.removeWhere((relationship) =>
getTrueDataObjects.any((dataObject) =>
dataObject['relationship'] ==
relationship['relationship_name']));
logDebug(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,
color: Colors.white,
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<String>(
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<String>(
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<String, dynamic> 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<Widget> generateGmcCards(List<dynamic> data) {
List<Widget> 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();
logDebug('getTrueObjects');
logDebug(getTrueObjects);
if (getTrueObjects.length > 0) {
logDebug('true');
gmcSumInsured = gmcMappedFamilyFloaters[0]["data"]["basic_cover_si"];
} else {
logDebug('false');
gmcSumInsured = item['Policy_Terms']['sum_insured'];
}
gmcTypeName = item['type'];
});
logDebug('forEach Card');
logDebug(gmcMappedFamilyFloaters);
dynamic getTrueObjects = gmcMappedFamilyFloaters
.where((element) => element['is_value_exist'] == true)
.toList();
logDebug(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: 9,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context)
? 18
: 13,
),
),
Row(
children: [
Text(
gmcPolicyName ?? '',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context)
? 20
: 14,
fontWeight: FontWeight.w600,
),
),
if (item['eCardDownload'] != null)
GestureDetector(
onTap: () async {
_launchURL(
item['eCardDownload']);
},
child: MouseRegion(
cursor:
SystemMouseCursors.click,
child: Icon(
Icons.file_download,
color: Color(0xFFE26728),
size: 25,
),
),
),
],
),
],
))),
Expanded(
flex: 3,
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
: 13,
),
),
Text(
'${gmcSumInsured != null ? gmcSumInsured : 'NA'}',
textAlign: TextAlign.right,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context)
? 20
: 14,
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<Widget>((item) {
Map<String, dynamic> 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;
}
List<Widget> generateGpaCards(List<dynamic> data) {
List<Widget> cards = [];
for (var item in data) {
logDebug('item');
logDebug(item);
String? gpaPolicyName = item['Policy_Name'];
String? gpaECardDownload = item['eCardDownload'];
String? gpaSumInsured = item['si_value'];
List<dynamic> gpaMappedFamilyFloaters = [];
if (item['mapped_family_floaters'] != null) {
gpaMappedFamilyFloaters = [item['mapped_family_floaters']];
}
dynamic getTrueObjects = gpaMappedFamilyFloaters
.where((element) => element['is_value_exist'] == true)
.toList();
// if (getTrueObjects.length > 0) {
// gpaSumInsured = getTrueObjects[0]["data"]["basic_cover_si"];
// } else {
// gpaSumInsured = item['Policy_Terms']['sumInsured2'];
// }
int gpaOpenForEnrollment = int.parse(item['OpenForEnrollment']);
List<Widget> familyFloaterContainers = [];
for (var floater in gpaMappedFamilyFloaters) {
bool isValueExist = floater['is_value_exist'];
Map<String, dynamic> floaterData = floater['data'];
gpaSelfDetails = floaterData['name'] +
' ~ ' +
floaterData['relationship'] +
' ~ ' +
' DOB : ' +
formatDate(floaterData['dob']);
if (isValueExist) {
familyFloaterContainers.add(
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),
),
),
),
],
),
],
),
),
);
}
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),
borderRadius: BorderRadius.circular(5),
),
padding: EdgeInsets.all(10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 9,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context) ? 18 : 13,
),
),
Row(
children: [
Text(
gpaPolicyName ?? 'NA',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context) ? 20 : 14,
fontWeight: FontWeight.w600,
),
),
if (item['eCardDownload'] != null)
GestureDetector(
onTap: () async {
_launchURL(item['eCardDownload']);
},
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Icon(
Icons.file_download,
color: Color(0xFFE26728),
size: 25,
),
),
),
],
),
],
),
),
),
Expanded(
flex: 3,
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 : 13,
),
),
Text(
'${gpaSumInsured != null ? gpaSumInsured : 'NA'}',
textAlign: TextAlign.right,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context) ? 20 : 14,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
],
),
),
SizedBox(height: 10),
Column(
children: familyFloaterContainers,
),
],
),
),
);
cards.add(card);
}
return cards;
}
}