post_enrollment_app/lib/pages/enrollment/addons.dart
2026-05-19 12:30:28 +05:30

7408 lines
383 KiB
Dart
Executable File

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:nhance_app_pwa/pages/enrollment/service/api_service.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../customAppBar/customFooter.dart';
import '../../customAppBar/enrollmentAppBar.dart';
import '../../customAppBar/responsive.dart';
import '../../customAppBar/tabs.dart';
import '../../customAppBar/toastHelper.dart';
import 'package:jwt_decode/jwt_decode.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/widgets.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import '../service/SessionManager.dart';
import '../service/TokenService.dart';
import 'package:nhance_app_pwa/logger.dart';
class addOnsDetails extends StatefulWidget {
const addOnsDetails({Key? key}) : super(key: key);
@override
State<addOnsDetails> createState() => _addOnsDetailsState();
}
class _addOnsDetailsState extends State<addOnsDetails> {
List<String> typeOrder = [
'GPA',
'GMC',
'OPD',
'GMC - Parents',
'GMC - Topup',
'GMC - Topup(Parents)'
];
late ApiService apiService;
bool isLoading = true;
bool isChecked = false;
bool disclaimeStatus = false;
bool _addOnsDependentSwitcher =
false;
// bool isPremiumSummery = false;
bool _topUpSiSwitcher = false;
bool _topUpParentSiSwitcher = false;
bool _opdSwitcher = false;
dynamic _token;
dynamic enrollmentEmpCodeString;
dynamic enrollmentEmpPrimaryId;
dynamic enrollmentGpaEmpName;
dynamic enrollmentClient_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 gmcClintPolicyId;
dynamic gmcSelfName;
dynamic gmcSelfDob;
dynamic gmcSelfRelationship;
dynamic gmcSelfDetails;
dynamic clientName;
dynamic clientLogo;
bool gpahasPremiumSummary = false;
bool gmchasPremiumSummary = false;
dynamic addon_subheading;
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 opdPolicies = [];
dynamic opdClientPolicyId;
dynamic opdSlabRates;
dynamic opdFamilyFloater;
dynamic opdPolicyName;
dynamic opdPolicyType;
dynamic opdMappedFamilyFloatersSi;
dynamic opdECardDownload;
int opdOpenForEnrollment = 0;
dynamic opdTypeName;
dynamic opdSiValue;
dynamic opdSiSelectedSI;
dynamic opdSiPremiumValue;
dynamic opdSiPremiumGst;
dynamic opdSiTotalAmt;
bool opdIsPremiumSummary = false;
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;
bool topUpParentIsPremiumSummary = false;
dynamic topUpParentTypeName;
int topUpParentOpenForEnrollment = 0;
dynamic addOnsDependentPolicies = [];
dynamic addOnsDependentMappedFamilyFloatersDependent;
dynamic addOnsDependentClientPolicyId;
dynamic addOnsDependentSlabRates;
dynamic addOnsSelectedDependent;
dynamic addOnsdependentValue;
dynamic addOnsDependentPolicyName;
dynamic addOnsDependentPolicyType;
dynamic addOnsDependentECardDownload;
bool addOnsDependentIsPremiumSummary = false;
dynamic addOnsDependentRelationShip;
int addOnsDependentOpenForEnrollment = 0;
dynamic siValue;
dynamic addOnDependentPremiumValue;
dynamic addOnsDependentFamilyFloater;
dynamic gmcAddOnSiPremiumValue;
dynamic addOnsDependentPremiumGst;
dynamic topUpSiPremiumGst;
dynamic addOnsDependentTotalAmt;
// dynamic topUpSiTotalAmt;
dynamic topUpSiTotalAmt;
bool topUpIsPremiumSummary = false;
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 enrollmentEmpClientBranchId;
dynamic selfEmpStatus;
dynamic gpaTotalAmt;
dynamic gmcTotalAmt;
List<Map<String, dynamic>> allDisclaimer =
[]; // Declare this to store all disclaimers
late List<bool> checkboxValues;
bool isTokenAvailable = false;
bool isEnrollCompletedStatus = false;
final session = SessionManager();
bool _hasValidECardDownload(dynamic eCardDownload) {
if (eCardDownload == null) return false;
final normalized = eCardDownload.toString().trim().toLowerCase();
return normalized.isNotEmpty && normalized != 'null';
}
@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;
});
});
checkboxValues = List<bool>.filled(allDisclaimer.length, false);
getTokenStatus();
}
@override
void dispose() {
_dobController.dispose();
_memberNameController.dispose();
_relationShipController.dispose();
super.dispose();
}
Future<void> getTokenStatus() async {
final token = await TokenService.getPostToken();
setState(() {
isTokenAvailable = token != null && token.isNotEmpty;
logDebug('isTokenAvailable $isTokenAvailable');
});
}
void _sortDisclaimerByTypeOrder() {
allDisclaimer.sort((a, b) {
int indexA = typeOrder.indexOf(a['type']);
int indexB = typeOrder.indexOf(b['type']);
return indexA.compareTo(indexB);
});
}
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 {
logDebug('_loadToken');
final SharedPreferences prefs = await SharedPreferences.getInstance();
final String? token = await TokenService.getPreToken();
if (token != null && token.isNotEmpty) {
Map<String, dynamic>? decodedToken = Jwt.parseJwt(token);
selfEmpStatus = prefs.getString('selfEmpStatus');
enrollmentEmpClientBranchId = session.enrollmentEmpClientBranchId;
enrollmentEmpCodeString = session.enrollmentEmpCodeString;
enrollmentEmpPrimaryId = session.enrollmentEmpPrimaryId;
enrollmentGpaEmpName = session.enrollmentGpaEmpName;
enrollmentClient_id = session.enrollmentClient_id;
// Call the API when the page enters
if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) {
clientLogo = prefs.getString('clientLogo');
clientName = prefs.getString('clientName');
addon_subheading = prefs.getString('addon_subheading');
} else {
getClientLogoAndDetails();
}
getGmcSiTopUp();
getGmcOPD();
getGmcSiParentTopUp();
getGmcDependentAddOns();
fetchRelationshipList();
getGpaEmpPolicyDetails(enrollmentEmpPrimaryId);
getGmcEmpPolicyDetails(enrollmentEmpPrimaryId);
}
}
bool isPremiumEnabled(dynamic value) {
if (value == null) return false;
if (value is bool) return value;
if (value is num) return value.toInt() != 0;
final normalized = value.toString().trim().toLowerCase();
if (normalized == 'true' || normalized == 'yes') return true;
final intValue = int.tryParse(normalized) ?? 0;
return intValue != 0;
}
bool shouldShowPremiumSummary({
required bool isPremiumSummary,
dynamic premiumValue,
dynamic gstValue,
dynamic totalValue,
}) {
return isPremiumSummary ||
premiumValue != null ||
gstValue != null ||
totalValue != null;
}
List<String> _extractUniqueSiValues(dynamic slabRates) {
if (slabRates is! List) return [];
final seen = <String>{};
final values = <String>[];
for (final addOn in slabRates) {
if (addOn is Map && addOn['si'] != null) {
final si = addOn['si'].toString().trim();
if (si.isNotEmpty && seen.add(si)) {
values.add(si);
}
}
}
return values;
}
String? _safeSelectedSi(String? selected, dynamic slabRates) {
if (selected == null) return null;
final options = _extractUniqueSiValues(slabRates);
return options.contains(selected) ? selected : null;
}
// Future<void> _loadToken() async {
// final SharedPreferences prefs = await SharedPreferences.getInstance();
// final String? token = prefs.getString('enrollToken');
// if (token != null && token.isNotEmpty) {
// setState(() {
// _token = token;
// });
// // Decode th e JWT token received from the API response
// Map<String, dynamic>? decodedToken = Jwt.parseJwt(token);
//
// selfEmpStatus = prefs.getString('selfEmpStatus');
// enrollmentEmpClientBranchId =
// prefs.getString('enrollmentEmpClientBranchId');
// enrollmentEmpCodeString = prefs.getString('enrollmentEmpCodeString');
// enrollmentEmpPrimaryId = prefs.getString('enrollmentEmpPrimaryId');
// enrollmentGpaEmpName = prefs.getString('enrollmentGpaEmpName');
// enrollmentClient_id = prefs.getString('enrollmentClient_id');
//
// // Call the API when the page enters
// if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) {
// clientLogo = prefs.getString('clientLogo');
// clientName = prefs.getString('clientName');
// addon_subheading = prefs.getString('addon_subheading');
// } else {
// getClientLogoAndDetails();
// }
// getGmcSiTopUp();
// getGmcSiParentTopUp();
// getGmcDependentAddOns();
// fetchRelationshipList();
// getGpaEmpPolicyDetails(enrollmentEmpPrimaryId);
// getGmcEmpPolicyDetails(enrollmentEmpPrimaryId);
// } else {
// // Token is empty or null, handle accordingly (e.g., navigate to login screen)
// ToastHelper.showErrorToast(context, 'Session Out');
// context.go('/login');
// // Navigator.pushReplacementNamed(context, 'login');
// }
// }
Future<void> getClientLogoAndDetails() async {
try {
// if (enrollmentClient_id == null ||
// enrollmentEmpCodeString == null ||
// enrollmentEmpClientBranchId == null) {
// return;
// }
final empClientId = await session.client_id;
final empClientBranchId = await session.empClientBranchId;
final response = await apiService.getClientLogoAndDetailsToApi(empClientId,empClientBranchId,
enrollmentClient_id!,
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
if (response.containsKey('data')) {
dynamic clientDetails = response['data'];
clientName = clientDetails['client']['client_name'];
clientLogo = clientDetails['client']['client_logo'];
} else {
// Handle other status messages if needed
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGpaEmpPolicyDetails(enrollmentEmpPrimaryId) async {
try {
if (enrollmentClient_id == null ||
enrollmentEmpCodeString == null ||
enrollmentEmpClientBranchId == null) {
return;
}
final response = await apiService.getGpaEmpPolicyDetailsToApi(
enrollmentEmpPrimaryId,
enrollmentEmpCodeString!,
enrollmentClient_id!,
'GPA',
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
setState(() {
gpaPolicies = response['data'];
for (var item in gpaPolicies) {
if (isPremiumEnabled(item['is_premium_summery'])) {
gpahasPremiumSummary = true;
logDebug('gpahasPremiumSummary $gpahasPremiumSummary');
break;
}
// Extract disclaimer value from each object
if (item['OpenForEnrollment'] == '1') {
dynamic disclaimer = item['disclaimer'];
if (disclaimer != null && disclaimer.isNotEmpty) {
// Temporary list to hold new entries
List<Map<String, dynamic>> newEntries = [];
if (disclaimer is String) {
// Wrap string in a map with id and checked
newEntries.add({
'id': allDisclaimer.length + 1, // Unique ID based on length
'text': disclaimer,
'checked': false,
'type': item['type']
});
} else if (disclaimer is List) {
// Convert each string in the list to a map with id and checked
newEntries.addAll(
List<Map<String, dynamic>>.from(
disclaimer.map((text) => {
'id': allDisclaimer.length + newEntries.length + 1,
'text': text,
'checked': false,
'type': item['type']
}),
),
);
} else {
logDebug('Unexpected type for disclaimer');
}
// Add new entries to the main list, ensuring no duplicate texts
newEntries.forEach((entry) {
if (!allDisclaimer
.any((item) => item['text'] == entry['text'])) {
allDisclaimer.add(entry);
}
});
// Sort disclaimers after adding
_sortDisclaimerByTypeOrder();
}
}
}
});
} else {
setState(() {
gpaDataIsEmpty = 0;
});
// Handle other status codes
ToastHelper.showWarningToast(context, 'Unable to process. Please try again later');
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGmcEmpPolicyDetails(enrollmentEmpPrimaryId) async {
try {
if (enrollmentClient_id == null ||
enrollmentEmpCodeString == null ||
enrollmentEmpClientBranchId == null) {
return;
}
final response = await apiService.getGmcEmpPolicyDetailsToApi(
enrollmentEmpPrimaryId,
enrollmentEmpCodeString!,
enrollmentClient_id!,
'GMC',
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
// setState(() {
gmcPolicies = response['data'];
for (var item in gmcPolicies) {
logDebug('checking is_premium_summery ${item['is_premium_summery']}');
if (isPremiumEnabled(item['is_premium_summery'])) {
gmchasPremiumSummary = true;
logDebug('gmchasPremiumSummary $gmchasPremiumSummary');
break;
}
if (item['OpenForEnrollment'] == '1') {
dynamic disclaimer = item['disclaimer'];
if (disclaimer != null && disclaimer.isNotEmpty) {
// Temporary list to hold new entries
List<Map<String, dynamic>> newEntries = [];
if (disclaimer is String) {
// Wrap string in a map with id and checked
newEntries.add({
'id': allDisclaimer.length + 1, // Unique ID based on length
'text': disclaimer,
'checked': false,
'type': item['type']
});
} else if (disclaimer is List) {
// Convert each string in the list to a map with id and checked
newEntries.addAll(
List<Map<String, dynamic>>.from(
disclaimer.map((text) => {
'id': allDisclaimer.length + newEntries.length + 1,
'text': text,
'checked': false,
'type': item['type']
}),
),
);
} else {
logDebug('Unexpected type for disclaimer');
}
// Add new entries to the main list, ensuring no duplicate texts
newEntries.forEach((entry) {
if (!allDisclaimer
.any((item) => item['text'] == entry['text'])) {
allDisclaimer.add(entry);
}
});
// Sort disclaimers after adding
_sortDisclaimerByTypeOrder();
}
}
}
// });
// Assuming data is a List
} else {
setState(() {
gmcDataIsEmpty = 0;
});
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGmcSiTopUp() async {
try {
if (enrollmentClient_id == null ||
enrollmentEmpCodeString == null ||
enrollmentEmpClientBranchId == null) {
return;
}
final response = await apiService.getGmcSiTopUpToApi(
enrollmentClient_id!,
enrollmentEmpCodeString!,
'GMC-SI-TOPUP',
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
if (response.containsKey('data')) {
setState(() {
topUpSiPolicies = response['data'];
});
if (topUpSiPolicies.isNotEmpty) {
// setState(() {
topUpClientPolicyId =
await topUpSiPolicies['gmc_si_topup']['client_policy_id'];
topUpSlabRates = await topUpSiPolicies['gmc_si_topup']['SlabRates'];
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'];
topUpMappedFamilyFloatersSi = await topUpSiPolicies['gmc_si_topup']
['family_floaters_of_only_si_array'];
topUpECardDownload =
topUpSiPolicies['gmc_si_topup']['eCardDownload'];
final dynamic openForEnrollmentRaw =
topUpSiPolicies['gmc_si_topup']['OpenForEnrollment'];
if (openForEnrollmentRaw is int) {
topUpOpenForEnrollment = openForEnrollmentRaw;
} else {
topUpOpenForEnrollment =
int.tryParse(openForEnrollmentRaw?.toString() ?? '0') ?? 0;
}
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) {
setState(() {
_topUpSiSwitcher = true;
topUpSiPremiumValue = toDoubleSafe(topUpSiPolicies['gmc_si_topup']
['family_floaters_of_only_si_premium_value']).toInt();
topUpSiPremiumGst = toDoubleSafe(topUpSiPolicies['gmc_si_topup']
['family_floaters_of_only_si_gst_value']).toInt();
topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst;
setState(() {
topUpIsPremiumSummary = isPremiumEnabled(topUpSiPolicies['gmc_si_topup']?['is_premium_summery']);
});
// topUpSiTotalAmt = (topUpSum as double).toInt();
});
}
// });
} else {
logDebug('No data found in the response');
}
} else {
// Handle other status messages if needed
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGmcOPD() async {
try {
if (enrollmentClient_id == null ||
enrollmentEmpCodeString == null ||
enrollmentEmpClientBranchId == null) {
return;
}
final response = await apiService.getGmcSiTopUpToApi(
enrollmentClient_id!,
enrollmentEmpCodeString!,
'GMC-OPD',
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
if (response.containsKey('data')) {
setState(() {
opdPolicies = response['data'];
});
if (opdPolicies.isNotEmpty) {
// setState(() {
opdClientPolicyId =
await opdPolicies['gmc_opd']['client_policy_id'];
opdSlabRates = await opdPolicies['gmc_opd']['SlabRates'];
opdPolicyName =
await opdPolicies['gmc_opd']['policy_name'];
opdPolicyType = await opdPolicies['gmc_opd']['type'];
opdFamilyFloater = await opdPolicies['gmc_opd']
['policy_terms']['family_floater'];
opdMappedFamilyFloatersSi = await opdPolicies['gmc_opd']
['family_floaters_of_only_si_array'];
opdECardDownload =
opdPolicies['gmc_opd']['eCardDownload'];
final dynamic openForEnrollmentRaw =
opdPolicies['gmc_opd']['OpenForEnrollment'];
if (openForEnrollmentRaw is int) {
opdOpenForEnrollment = openForEnrollmentRaw;
} else {
opdOpenForEnrollment =
int.tryParse(openForEnrollmentRaw?.toString() ?? '0') ?? 0;
}
opdTypeName = opdPolicies['gmc_opd']['type'];
final dynamic opdDisclaimer = opdPolicies['gmc_opd']['disclaimer'];
opdSiValue = await opdPolicies['gmc_opd']
['family_floaters_of_only_si_value'];
opdSiSelectedSI =
opdSiValue != 0 ? opdSiValue.toString() : null;
if (opdSiSelectedSI != null) {
setState(() {
_opdSwitcher = true;
opdSiPremiumValue = toDoubleSafe(opdPolicies['gmc_opd']
['family_floaters_of_only_si_premium_value']).toInt();
opdSiPremiumGst = toDoubleSafe(opdPolicies['gmc_opd']
['family_floaters_of_only_si_gst_value']).toInt();
opdSiTotalAmt = opdSiPremiumValue + opdSiPremiumGst;
setState(() {
opdIsPremiumSummary = isPremiumEnabled(opdPolicies['gmc_opd']?['is_premium_summery']);
});
// opdSiTotalAmt = (opdSum as double).toInt();
});
}
if (opdOpenForEnrollment == 1 &&
opdDisclaimer != null &&
opdDisclaimer.toString().isNotEmpty) {
List<Map<String, dynamic>> newEntries = [];
if (opdDisclaimer is String) {
newEntries.add({
'id': allDisclaimer.length + 1,
'text': opdDisclaimer,
'checked': false,
'type': opdTypeName
});
} else if (opdDisclaimer is List) {
newEntries.addAll(
List<Map<String, dynamic>>.from(
opdDisclaimer.map((text) => {
'id': allDisclaimer.length + newEntries.length + 1,
'text': text,
'checked': false,
'type': opdTypeName
}),
),
);
} else {
logDebug('Unexpected OPD disclaimer type');
}
newEntries.forEach((entry) {
if (!allDisclaimer.any((item) => item['text'] == entry['text'])) {
allDisclaimer.add(entry);
}
});
_sortDisclaimerByTypeOrder();
}
// });
} else {
logDebug('No data found in the response');
}
} else {
logDebug('API request failed with status: ${response['status']}');
}
} else {
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
logDebug('Exception occurred: $e');
}
}
Future<void> getGmcSiParentTopUp() async {
try {
if (enrollmentClient_id == null ||
enrollmentEmpCodeString == null ||
enrollmentEmpClientBranchId == null) {
return;
}
final response = await apiService.getGmcSiParentTopUpToApi(
enrollmentClient_id!,
enrollmentEmpCodeString!,
'GMC-SI-PARENT-TOPUP',
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
if (response.containsKey('data')) {
setState(() {
topUpSiParentPolicies = response['data'];
});
if (topUpSiParentPolicies.isNotEmpty) {
// setState(() {
topUpParentClientPolicyId =
await topUpSiParentPolicies['gmc_si_parent_topup']
['client_policy_id'];
topUpParentSlabRates =
await topUpSiParentPolicies['gmc_si_parent_topup']['SlabRates'];
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'];
topUpParentMappedFamilyFloatersSi =
await topUpSiParentPolicies['gmc_si_parent_topup']
['family_floaters_of_only_si_array'];
topUpParentECardDownload =
topUpSiParentPolicies['gmc_si_parent_topup']['eCardDownload'];
final dynamic parentOpenForEnrollmentRaw =
topUpSiParentPolicies['gmc_si_parent_topup']
['OpenForEnrollment'];
topUpParentOpenForEnrollment =
int.tryParse(parentOpenForEnrollmentRaw?.toString() ?? '0') ?? 0;
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) {
setState(() {
_topUpParentSiSwitcher = true;
topUpParentSiPremiumValue = toDoubleSafe(
topUpSiParentPolicies['gmc_si_parent_topup']
['family_floaters_of_only_si_premium_value']).toInt();
topUpParentSiPremiumGst = toDoubleSafe(
topUpSiParentPolicies['gmc_si_parent_topup']
['family_floaters_of_only_si_gst_value']).toInt();
topUpParentSiTotalAmt =
topUpParentSiPremiumValue + topUpParentSiPremiumGst;
setState(() {
topUpParentIsPremiumSummary = isPremiumEnabled(topUpSiParentPolicies['gmc_si_parent_topup']?['is_premium_summery']);
logDebug(topUpParentECardDownload);
});
});
}
// });
} else {
logDebug('No data found in the response');
}
} else {
// Handle other status messages if needed
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> getGmcDependentAddOns() async {
try {
if (enrollmentClient_id == null ||
enrollmentEmpCodeString == null ||
enrollmentEmpClientBranchId == null) {
return;
}
final response = await apiService.getGmcDependentAddOnsToApi(
enrollmentClient_id!,
enrollmentEmpCodeString!,
'GMC-DEPENDENT-ADDON',
enrollmentEmpClientBranchId!);
if (response['status'] == 'success') {
if (response.containsKey('data')) {
setState(() {
addOnsDependentPolicies = response['data'];
});
if (addOnsDependentPolicies.isNotEmpty) {
// setState(() {
addOnsDependentClientPolicyId =
addOnsDependentPolicies['gmc_dependent_addon']
['client_policy_id'];
logDebug('1 $addOnsDependentClientPolicyId');
addOnsDependentSlabRates =
await addOnsDependentPolicies['gmc_dependent_addon']
['SlabRates'];
logDebug('2 $addOnsDependentSlabRates');
addOnsDependentPolicyName =
await addOnsDependentPolicies['gmc_dependent_addon']
['policy_name'];
logDebug('3 $addOnsDependentPolicyName');
addOnsDependentPolicyType =
await addOnsDependentPolicies['gmc_dependent_addon']['type'];
logDebug('4 $addOnsDependentPolicyType');
addOnsDependentFamilyFloater =
await addOnsDependentPolicies['gmc_dependent_addon']
['policy_terms']['family_floater'];
logDebug('5 $addOnsDependentFamilyFloater');
setState(() {
addOnsDependentMappedFamilyFloatersDependent =
addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_si_array'];
logDebug('6 $addOnsDependentMappedFamilyFloatersDependent');
final dynamic dependentOpenForEnrollmentRaw =
addOnsDependentPolicies['gmc_dependent_addon']
['OpenForEnrollment'];
logDebug('7 $dependentOpenForEnrollmentRaw');
addOnsDependentOpenForEnrollment =
int.tryParse(dependentOpenForEnrollmentRaw?.toString() ?? '0') ?? 0;
logDebug('8 $addOnsDependentOpenForEnrollment');
addOnsdependentValue =
addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_si_value'];
logDebug('9 $addOnsdependentValue');
// final checkValue = addOnsdependentValue +
// addOnsDependentPolicies['gmc_dependent_addon']
// ['family_floaters_of_dependent_and_si_premium_value'];
final checkValue = int.parse(addOnsdependentValue.toString()) +
int.parse(addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_si_premium_value']
.toString());
logDebug('10 $checkValue');
if (checkValue == 0) {
logDebug('11');
addOnsSelectedDependent = null;
_addOnsDependentSwitcher = false;
} else {
logDebug('12 $addOnsdependentValue');
addOnsSelectedDependent = addOnsdependentValue.toString();
logDebug('13 $addOnsSelectedDependent');
}
// addOnsSelectedDependent = await addOnsdependentValue != 0
// ? addOnsdependentValue.toString()
// : null;
if (addOnsSelectedDependent != null) {
_addOnsDependentSwitcher = true;
}
addOnDependentPremiumValue = toDoubleSafe(addOnsDependentPolicies[
'gmc_dependent_addon']
['family_floaters_of_dependent_and_si_premium_value']).toInt();
;
addOnsDependentPremiumGst = toDoubleSafe(
addOnsDependentPolicies['gmc_dependent_addon']
['family_floaters_of_dependent_and_gst_value']).toInt();
addOnsDependentTotalAmt =
addOnDependentPremiumValue + addOnsDependentPremiumGst;
addOnsDependentECardDownload =
addOnsDependentPolicies['gmc_dependent_addon']
['eCardDownload'];
setState(() {
addOnsDependentIsPremiumSummary = isPremiumEnabled(addOnsDependentPolicies['gmc_dependent_addon']?['is_premium_summery']);
});
logDebug('addOnsDependentIsPremiumSummery $addOnsDependentIsPremiumSummary');
addOnsDependentRelationShip = addOnsDependentPolicies['gmc_dependent_addon']['relationship'];
// if(addOnsDependentIsPremiumSummery == 1){
// logDebug('isPremiumSummery true');
// isPremiumSummery = true;
// } else {
// logDebug('isPremiumSummery false');
// isPremiumSummery = false;
// }
});
} else {
logDebug('No data found in the response');
}
} else {
// Handle other status messages if needed
logDebug('API request failed with status: ${response['status']}');
}
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> fetchRelationshipList() async {
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,
});
}
} else {
throw Exception('Failed to fetch relationship list');
}
} catch (error) {
logDebug('Error fetching relationship list: $error');
}
}
Future<void> _selectDate(BuildContext context, formType) async {
logDebug(formType);
var ageValidation = formType['age_validation'];
logDebug(ageValidation);
if (ageValidation is Map<String, dynamic>) {
int min = ageValidation.containsKey('min')
? int.tryParse(ageValidation['min'].toString()) ?? 0
: 0;
int max = ageValidation.containsKey('max')
? int.tryParse(ageValidation['max'].toString()) ?? 100
: 100;
logDebug('Min age: $min');
logDebug('Max age: $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);
// 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)));
},
builder: (BuildContext context, Widget? child) {
return Theme(
data: ThemeData.light().copyWith(
primaryColor: Color(0xFFE26728), // Header background color
colorScheme: ColorScheme.light(
primary: Color(0xFFE26728), secondary: Color(0xFFE26728)),
buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary),
iconTheme: IconThemeData(color: Color(0xFFE26728)),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Color(0xFFE26728)), // Button color
),
),
child: child!,
);
},
);
if (picked != null && picked != _selectedDate) {
setState(() {
_selectedDate = picked;
_dobController.text = DateFormat('dd-MM-yyyy').format(_selectedDate);
});
}
} else {
logDebug('Invalid age validation data');
}
}
Future<void> deleteItem(Map<String, dynamic> deletedItem) async {
try {
var id = deletedItem['employee_id'];
final response = await apiService.deleteItemToApi(id,'','');
if (response['status'] == 'success') {
formDataList.clear();
selectedRelationships.clear();
_relationShipController.clear();
_memberNameController.clear();
_dobController.clear();
relationshipOptions.clear();
getGpaEmpPolicyDetails(enrollmentEmpPrimaryId);
getGmcEmpPolicyDetails(enrollmentEmpPrimaryId);
fetchRelationshipList();
getGmcSiTopUp();
getGmcOPD();
getGmcSiParentTopUp();
getGmcDependentAddOns();
ToastHelper.showSuccessToast(context, '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
formDataList.add({
'relationship': formData['relationship'],
'name': formData['memberName'],
'dob': formData['dateOfBirth'],
'emp_code': enrollmentEmpCodeString,
'client_id': enrollmentClient_id,
'client_policy_id': floatedData['client_policy_id'],
'is_addon_value': 1,
'basic_cover_si': addOnsSelectedDependent,
'created_by': enrollmentEmpPrimaryId,
'client_branch_id': enrollmentEmpClientBranchId,
// 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(enrollmentEmpPrimaryId);
getGmcEmpPolicyDetails(enrollmentEmpPrimaryId);
fetchRelationshipList();
getGmcSiTopUp();
getGmcOPD();
getGmcSiParentTopUp();
getGmcDependentAddOns();
ToastHelper.showSuccessToast(context, 'Saved Successfully...');
} else {
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 {
if (_addOnsDependentSwitcher == true) {
if (addOnsSelectedDependent == null || addOnsSelectedDependent.isEmpty) {
return; // Return if addOnsSelectedDependent is null or empty
} else {
try {
dynamic getTrueObjects = addOnsDependentMappedFamilyFloatersDependent
.where((element) => element['is_value_exist'] == true)
.toList();
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
List<Map<String, String>> selectedValues = [];
// try {
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': enrollmentClient_id,
'emp_code': enrollmentEmpCodeString,
'client_branch_id': enrollmentEmpClientBranchId,
};
// Add the map to the list
selectedValues.add(floaterData);
}
}
// 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();
} else {
// ToastHelper.showErrorToast(context, 'Failed to save');
}
} catch (error) {
logDebug('Error saving family members');
}
}
} else {
logDebug('');
}
}
void sendAddonsGmcSiToAPI() async {
if (_topUpSiSwitcher == true) {
if (topUpSiSelectedSI == null || topUpSiSelectedSI.isEmpty) {
return; // Return if addOnsSelectedDependent is null or empty
} else {
try {
dynamic getTrueObjects = topUpMappedFamilyFloatersSi
.where((element) => element['is_value_exist'] == true)
.toList();
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
List<Map<String, String>> selectedValues = [];
// try {
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': enrollmentClient_id,
'emp_code': enrollmentEmpCodeString,
'client_branch_id': enrollmentEmpClientBranchId,
};
// Add the map to the list
selectedValues.add(floaterData);
}
}
final response =
await apiService.sendAddonsGmcSiToAPI(selectedValues);
if (response['status'] == 'success') {
// Member saved successfully
formDataList.clear();
selectedRelationships.clear();
_relationShipController.clear();
_memberNameController.clear();
_dobController.clear();
} else {
logDebug('Failed to Save...');
}
} catch (error) {
logDebug('Error saving family members');
}
}
} else {
// Navigator.pushNamed(context, 'empReviewDetails');
}
}
void sendAddonsGmcParentSiToAPI() async {
if (_topUpParentSiSwitcher == true) {
if (topUpParentSiSelectedSI == null || topUpParentSiSelectedSI.isEmpty) {
return; // Return if addOnsSelectedDependent is null or empty
} else {
try {
dynamic getTrueObjects = topUpParentMappedFamilyFloatersSi
.where((element) => element['is_value_exist'] == true)
.toList();
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
List<Map<String, String>> selectedValues = [];
// try {
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': enrollmentClient_id,
'emp_code': enrollmentEmpCodeString,
'client_branch_id': enrollmentEmpClientBranchId,
};
// Add the map to the list
selectedValues.add(floaterData);
}
}
final response =
await apiService.sendAddonsGmcParentSiToAPI(selectedValues);
if (response['status'] == 'success') {
// Member saved successfully
formDataList.clear();
selectedRelationships.clear();
_relationShipController.clear();
_memberNameController.clear();
_dobController.clear();
} else {
logDebug('Failed to Save...');
}
} catch (error) {
logDebug('Error saving family members');
}
}
} else {
// Navigator.pushNamed(context, 'empReviewDetails');
}
}
void sendAddonsGmcOPDToAPI() async {
if (_opdSwitcher == true) {
if (opdSiSelectedSI == null || opdSiSelectedSI.isEmpty) {
return;
} else {
try {
dynamic getTrueObjects = opdMappedFamilyFloatersSi
.where((element) => element['is_value_exist'] == true)
.toList();
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
List<Map<String, String>> selectedValues = [];
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();
Map<String, String> floaterData = {
'basic_cover_si': opdSiSelectedSI,
'client_policy_id': client_policy_id,
'employee_id': employee_id,
'client_id': enrollmentClient_id,
'emp_code': enrollmentEmpCodeString,
'client_branch_id': enrollmentEmpClientBranchId,
};
selectedValues.add(floaterData);
}
}
final response = await apiService.sendAddonsGmcSiToAPI(selectedValues);
if (response['status'] != 'success') {
logDebug('Failed to Save OPD...');
}
} catch (error) {
logDebug('Error saving OPD family members');
}
}
}
}
Future<void> removeAddonsGmcDependentToAPI() async {
try {
if (enrollmentEmpCodeString == null ||
addOnsDependentClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcDependentToAPI(
enrollmentEmpCodeString!, addOnsDependentClientPolicyId!);
if (response['status'] == 'success') {
logDebug(response['data']);
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> removeAddonsGmcSiToAPI() async {
try {
if (enrollmentEmpCodeString == null || topUpClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcSiToAPI(
enrollmentEmpCodeString!, topUpClientPolicyId!);
if (response['status'] == 'success') {
logDebug(response['data']);
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> removeAddonsGmcParentSiToAPI() async {
try {
if (enrollmentEmpCodeString == null ||
topUpParentClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcParentSiToAPI(
enrollmentEmpCodeString!, topUpParentClientPolicyId!);
if (response['status'] == 'success') {
logDebug(response['data']);
} else {
// Handle other status codes
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
// Handle exceptions
logDebug('Exception occurred: $e');
}
}
Future<void> removeAddonsGmcOPDToAPI() async {
try {
if (enrollmentEmpCodeString == null || opdClientPolicyId == null) {
return;
}
final response = await apiService.removeAddonsGmcSiToAPI(
enrollmentEmpCodeString!, opdClientPolicyId!);
if (response['status'] != 'success') {
logDebug('Request failed with status: ${response['code']}');
}
} catch (e) {
logDebug('Exception occurred: $e');
}
}
void topUpSiCalculation(choosedSiValue) async {
try {
var calculation = {
'client_policy_id': topUpClientPolicyId,
'emp_code': enrollmentEmpCodeString,
'si': choosedSiValue,
'client_branch_id': enrollmentEmpClientBranchId
};
// Iterate through familyMembers list and send each member's data to the API
final response = await apiService.topUpSiCalculationToAPI(calculation);
if (response['status'] == 'success') {
List<dynamic>? topUpEmpArray;
for (var item in response['data']) {
if (item.containsKey(enrollmentEmpCodeString)) {
topUpEmpArray = item[enrollmentEmpCodeString];
break;
}
}
if (topUpEmpArray != null) {
double topUpRataPremimumSum = 0;
for (var item in topUpEmpArray) {
var topUpRataPremimum = item['policy_details']['rata_premimum'];
if (topUpRataPremimum != null) {
topUpRataPremimumSum += topUpRataPremimum;
}
}
double topUpGstSum = 0;
for (var item in topUpEmpArray) {
var topUpGst = item['policy_details']['gst'];
if (topUpGst != null) {
topUpGstSum += topUpGst;
}
}
setState(() {
topUpSiPremiumValue = topUpRataPremimumSum.toInt();
topUpSiPremiumGst = topUpGstSum.toInt();
topUpSiTotalAmt = topUpSiPremiumValue + topUpSiPremiumGst;
print('topUpSiPremiumValue $topUpSiPremiumValue');
print('topUpSiPremiumGst $topUpSiPremiumGst');
print('topUpSiTotalAmt $topUpSiTotalAmt');
topUpIsPremiumSummary = true;
// topUpSiTotalAmt = (topUpSum as double).toInt();
});
sendAddonsGmcSiToAPI();
} else {
logDebug('Array not found for emp_code $enrollmentEmpCodeString');
}
} else {
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
}
}
void topUpParentSiCalculation(choosedSiValue) async {
try {
var calculation = {
'client_policy_id': topUpParentClientPolicyId,
'emp_code': enrollmentEmpCodeString,
'si': choosedSiValue,
'client_branch_id': enrollmentEmpClientBranchId
};
// Iterate through familyMembers list and send each member's data to the API
final response =
await apiService.topUpParentSiCalculationToAPI(calculation);
if (response['status'] == 'success') {
List<dynamic>? topUpEmpArray;
for (var item in response['data']) {
if (item.containsKey(enrollmentEmpCodeString)) {
topUpEmpArray = item[enrollmentEmpCodeString];
break;
}
}
if (topUpEmpArray != null) {
double topUpRataPremimumSum = 0;
for (var item in topUpEmpArray) {
var topUpRataPremimum = item['policy_details']['rata_premimum'];
if (topUpRataPremimum != null) {
topUpRataPremimumSum += topUpRataPremimum;
}
}
double topUpGstSum = 0;
for (var item in topUpEmpArray) {
var topUpGst = item['policy_details']['gst'];
if (topUpGst != null) {
topUpGstSum += topUpGst;
}
}
setState(() {
topUpParentSiPremiumValue =
(topUpRataPremimumSum as double).toInt();
topUpParentSiPremiumGst = (topUpGstSum as double).toInt();
topUpParentSiTotalAmt =
topUpParentSiPremiumValue + topUpParentSiPremiumGst;
});
sendAddonsGmcParentSiToAPI();
} else {
logDebug('Array not found for emp_code $enrollmentEmpCodeString');
}
} else {
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
}
}
void opdSiCalculation(choosedSiValue) async {
try {
var calculation = {
'client_policy_id': opdClientPolicyId,
'emp_code': enrollmentEmpCodeString,
'si': choosedSiValue,
'client_branch_id': enrollmentEmpClientBranchId
};
final response = await apiService.topUpSiCalculationToAPI(calculation);
if (response['status'] == 'success') {
List<dynamic>? opdEmpArray;
final data = response['data'];
if (data is List) {
for (var item in data) {
if (item is Map) {
final targetKey = enrollmentEmpCodeString?.toString();
if (targetKey != null && item.containsKey(targetKey)) {
opdEmpArray = item[targetKey] as List<dynamic>?;
break;
}
// Fallback: take first entry when key name differs from local value.
if (item.isNotEmpty && opdEmpArray == null) {
final firstValue = item.values.first;
if (firstValue is List) {
opdEmpArray = firstValue.cast<dynamic>();
}
}
}
}
}
if (opdEmpArray != null) {
double opdRataPremimumSum = 0;
for (var item in opdEmpArray) {
final opdRataPremimum = toDoubleSafe(
item['policy_details']?['rata_premimum']);
if (opdRataPremimum != null) {
opdRataPremimumSum += opdRataPremimum;
}
}
double opdGstSum = 0;
for (var item in opdEmpArray) {
final opdGst = toDoubleSafe(item['policy_details']?['gst']);
if (opdGst != null) {
opdGstSum += opdGst;
}
}
setState(() {
opdSiPremiumValue = opdRataPremimumSum.toInt();
opdSiPremiumGst = opdGstSum.toInt();
opdSiTotalAmt = opdSiPremiumValue + opdSiPremiumGst;
print('opdSiPremiumValue $opdSiTotalAmt');
opdIsPremiumSummary = true;
});
sendAddonsGmcOPDToAPI();
}
}
} catch (error) {
logDebug('Error calculating OPD premium');
}
}
void addOnsDependentCalculation(choosedDependentValue) async {
try {
var calculation = {
'client_policy_id': addOnsDependentClientPolicyId,
'emp_code': enrollmentEmpCodeString,
'si': choosedDependentValue,
'client_branch_id': enrollmentEmpClientBranchId
};
// Iterate through familyMembers list and send each member's data to the API
final response =
await apiService.addOnsDependentCalculationToAPI(calculation);
if (response['status'] == 'success') {
List<dynamic>? addOnsEmpArray;
for (var item in response['data']) {
if (item.containsKey(enrollmentEmpCodeString)) {
addOnsEmpArray = item[enrollmentEmpCodeString];
break;
}
}
if (addOnsEmpArray != null) {
double addOnsRataPremimumSum = 0;
for (var item in addOnsEmpArray) {
var addOnsRataPremimum = item['policy_details']['rata_premimum'];
if (addOnsRataPremimum != null) {
addOnsRataPremimumSum += addOnsRataPremimum;
}
}
double addOnsGstSum = 0;
for (var item in addOnsEmpArray) {
var addOnsGst = item['policy_details']['gst'];
if (addOnsGst != null) {
addOnsGstSum += addOnsGst;
}
}
setState(() {
addOnDependentPremiumValue =
(addOnsRataPremimumSum as double).toInt();
addOnsDependentPremiumGst = (addOnsGstSum as double).toInt();
addOnsDependentTotalAmt =
addOnDependentPremiumValue + addOnsDependentPremiumGst;
});
} else {
logDebug('Array not found for emp_code $enrollmentEmpCodeString');
}
} else {
logDebug('Operation Failed!');
}
} catch (error) {
logDebug('Error saving family members');
}
}
Future<void> sendAddOnAPI() async {
setState(() {
isLoading = true;
});
if (gpaDataIsEmpty != 0) {
for (var item in gpaPolicies) {
// 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));
}
}
iAgreeForAddOn = iAgreeForAddOn.toSet().toList();
Map<String, dynamic> apiParams = {
'emp_code': enrollmentEmpCodeString,
'client_policy_id': iAgreeForAddOn,
'client_id': enrollmentClient_id,
};
try {
final response = await apiService.sendAddOnToAPI(apiParams);
if (response['status'] == 'success') {
setState(() {
isLoading = false;
isChecked = false;
});
ToastHelper.showSuccessToast(context, 'Saved Successfully...');
_showSuccessDialog();
} else {
setState(() {
isLoading = false;
});
// Handle other status codes
ToastHelper.showErrorToast(context, 'Failed to Save');
_showErrorDialog();
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');
Navigator.pushNamed(context, 'empDetails',
arguments: {'mobile': mobileNo});
} else {
context.pop();
// Navigator.pushNamed(context, 'empDetails');
} }
void checkSiTopUp() async {
List<Map<String, dynamic>> siData = [
{
'topUpSiPremiumValue': topUpSiPremiumValue,
'topUpSiPremiumGst': topUpSiPremiumGst,
'topUpSiTotalAmt': topUpSiTotalAmt,
}
];
print(siData);
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('siData', jsonEncode(siData));
}
void checkSiParentTopUp() async {
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 {
List<Map<String, dynamic>> dependentData = [
{
'addOnDependentPremiumValue': addOnDependentPremiumValue,
'addOnsDependentPremiumGst': addOnsDependentPremiumGst,
'addOnsDependentTotalAmt': addOnsDependentTotalAmt,
}
];
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('dependentData', jsonEncode(dependentData));
}
void checkOPDTopUp() async {
List<Map<String, dynamic>> opdData = [
{
'opdSiPremiumValue': opdSiPremiumValue,
'opdSiPremiumGst': opdSiPremiumGst,
'opdSiTotalAmt': opdSiTotalAmt,
}
];
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('opdData', jsonEncode(opdData));
}
void _showSuccessDialog() {
setState(() {
isEnrollCompletedStatus = true;
});
// Wait 3 seconds, then navigate to home page
Future.delayed(const Duration(seconds: 3), () {
if(isTokenAvailable) {
context.go('/home');
// Navigator.pushNamed(context, 'home');
} else {
context.go('/empDetails');
// Navigator.pushNamed(context, 'empDetails');
}
});
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return AlertDialog(
// backgroundColor: Colors.white,
// title: Text(
// 'Success',
// style: GoogleFonts.poppins(
// color: Colors.green,
// ),
// ),
// content: Text('Enrollment Completed'),
// actions: <Widget>[
// TextButton(
// child: Text(
// 'OK',
// style: GoogleFonts.poppins(
// color: Color(0xFFE26728),
// ),
// ),
// onPressed: () {
// Navigator.of(context).pop();
// setState(() {
// isEnrollCompletedStatus = true;
// });
//
// // Navigator.popAndPushNamed(context, 'home');
// },
// ),
// ],
// );
// },
// );
}
void _showErrorDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(
'Error',
style: GoogleFonts.poppins(
color: Colors.red,
),
),
content: Text('Unable to process. Please try again later. Enrollemnt not completed'),
actions: <Widget>[
TextButton(
child: Text(
'OK',
style: GoogleFonts.poppins(
color: Color(0xFFE26728),
),
),
onPressed: () {
context.pop();
},
),
],
);
},
);
}
bool isSubmitEnabled() {
// // Convert to integers and handle null values by defaulting to 0
// bool enrollmentConditionsMet =
// (int.tryParse(topUpOpenForEnrollment ?? '0') != 0) &&
// (int.tryParse(topUpParentOpenForEnrollment ?? '0') != 0) &&
// (int.tryParse(addOnsDependentOpenForEnrollment ?? '0') != 0);
//
// logDebug('enrollmentConditionsMet: $enrollmentConditionsMet');
// logDebug('gmcEnrollmentStatus: $gmcEnrollmentStatus');
// return isChecked &&
// enrollmentConditionsMet &&
// gmcEnrollmentStatus &&
// (activeSiData == 1 ? topUpSiIsChecked : true) &&
// (activeSiParentData == 1 ? topUpParentIsChecked : true) &&
// (activeDependentData == 1 ? addOnsDependentIsChecked : true);
disclaimeStatus = allDisclaimer.every((item) => item['checked'] == true);
// Combine the `disclaimeStatus` and `isChecked` conditions
return isChecked && disclaimeStatus;
}
double allTotalSum() {
double total = 0.0; // Initialize to avoid unwanted accumulation
if (gpaTotalAmt != null) total += gpaTotalAmt!;
if (gmcTotalAmt != null) total += gmcTotalAmt!;
return total;
}
void _showExitConfirmation(BuildContext context) {
double myheight = MediaQuery.of(context).size.height;
showDialog(
context: context,
barrierDismissible: false, // User must tap a button to dismiss dialog
builder: (dialogContext) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0), // Rounded corners
),
backgroundColor: Colors.white,
contentPadding: EdgeInsets.zero,
title: Text(
'Log Out Confirmation',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
content: Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
'Are you sure you want to log out?',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 18,
color: Color(0xFF898C81),
),
),
),
actions: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly, // Space buttons evenly
children: [
SizedBox(
width:
MediaQuery.of(context).size.width * 0.3, // Set button width
child: TextButton(
onPressed: () => Navigator.pop(dialogContext),
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
side: BorderSide(
color: Color(0xFFE26728), // Border color
width: 1,
),
),
child: Text(
'Cancel',
style: GoogleFonts.poppins(
color: Color(0xFFE26728),
fontSize: 16,
),
),
),
),
SizedBox(
width:
MediaQuery.of(context).size.width * 0.3, // Set button width
child: TextButton(
onPressed: () => TokenService().logout(context),
style: TextButton.styleFrom(
backgroundColor: Color(0xFFE26728), // Background color
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
child: FittedBox(
fit: BoxFit
.scaleDown, // Prevents wrapping while adjusting text size
child: Text(
'Log Out',
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16,
),
textAlign: TextAlign.center,
),
),
),
),
],
),
SizedBox(height: 10), // Add spacing below buttons
],
),
);
}
@override
Widget build(BuildContext context) {
if (gpaDataIsEmpty == 0 && gmcDataIsEmpty == 0) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
if (didPop) return;
context.go('/empDetails');
},
child: 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'];
final dobDate = floaterData['dob'] ?? '';
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']} - ${dobDate}',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context) ? 18 : 14,
),
),
],
),
),
),
if (addOnsDependentOpenForEnrollment != 0)...[
if (addOnsDependentECardDownload == null)
if (isValueExist && floaterData['relationship'] != 'Self')
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => deleteItem(floaterData),
child: Tooltip(
message: 'Delete',
child: Icon(
Icons.delete,
color: Color(0xFFE26728),
),
),
),
),
if (addOnsDependentECardDownload == null)
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
openAddFamilyMemberPopup('Edit',floaterData);
},
child: Tooltip(
message: 'Edit',
child: Icon(
Icons.edit,
color: Color(0xFFE26728),
),
),
),
),
]
],
),
),
);
} 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: 10));
}
}
return isEnrollCompletedStatus == true ? PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
if (didPop) return;
_showExitConfirmation(context);
},
child: Scaffold(
backgroundColor: const Color(0xFFF2F6FA), // Matches your light gray background
appBar: CustomAppBar(),
body: Center(
child: Container(
padding: Responsive.isDesktop(context)
? EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width *
0.2, // 30% of screen width as horizontal padding
vertical: MediaQuery.of(context).size.height *
0.03, // 5% of screen height as vertical padding
)
: EdgeInsets.all(10),
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min, // Shrink wrap to content
children: [
// ✅ Top logos
Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network(
clientLogo ?? '', // Nhance logo
height: 40,
errorBuilder: (BuildContext context, Object error,
StackTrace? stackTrace) {
return Image.asset(
'assets/Solid_gray.png',
height: 40,
fit: BoxFit.contain,
);
},
),
// Image.network(
// 'https://i.imgur.com/qOihOvk.png', // Prodapt logo
// height: 28,
// ),
],
),
const SizedBox(height: 32),
// ✅ Checkmark and message
const Icon(Icons.check_circle, size: 70, color: Color(0xFF1A73E8)),
const SizedBox(height: 24),
const Text(
'Congratulations!',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
color: Color(0xFF2D2A4A),
),
),
const SizedBox(height: 12),
const Text(
'You have completed your enrolment. You can now close this tab',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
color: Color(0xFF2D2A4A),
),
),
],
),
),
),
floatingActionButtonLocation: Responsive.isDesktop(context)
? null
: isTokenAvailable
? FloatingActionButtonLocation.miniEndFloat
: null,
bottomNavigationBar: Responsive.isDesktop(context)
? null
: CustomBottomNavigationBar(
onTabChanged: (index) {
// Add your navigation logic here
// repositionBotman();
if (index == 0) {
context.push('/home');
} else if (index == 1) {
context.push('/claims');
} else if (index == 2) {
context.push('/profile');
} else if (index == 3) {
context.push('/help');
}
// else if (index == 4) {
// // context.push('/wellness');
// // Wellness tab clicked → show popup
// if(!isRetailLoggedIn)
// PopupHelper.showRedirectPopup(
// context: context,
// apiService: apiService,
// empPrimaryId: session.empPrimaryId,
// );
// }
},
icons: [
Icons.home_outlined,
Icons.sticky_note_2_outlined,
Icons.person_outline_outlined,
Icons.headset_mic_outlined,
// Icons.health_and_safety_outlined,
],
labels: ["Home", "Claims", "Profile", "Help"],
initialIndex: 0, // Initial index of the bottom navigation bar
),
) ) : PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
if (didPop) return;
context.go('/empDetails');
},
child: 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: 80,
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: 200,
height: 200,
alignment: Alignment.centerLeft,
child: Image.network(
clientLogo ?? '',
// width: 200, // Set the width here
// height: 200, // 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 ||
opdMappedFamilyFloatersSi != 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-On Coverage',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(
context)
? 20
: 18,
fontWeight:
FontWeight.w600,
color: Color(0xFF181818)),
),
Text(
addon_subheading ?? '',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(
context)
? 18
: 15,
color: Color(0xFF181818),
),
),
],
))),
],
),
),
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(
Responsive.isDesktop(
context)
? addOnsDependentPolicyName
: addOnsDependentPolicyType,
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) &&
_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(
'${formatNullableAmount(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, // Color of the switch track when OFF
),
],
))),
],
),
if (_addOnsDependentSwitcher == true)
SizedBox(height: 10),
if (!Responsive.isDesktop(context) &&
_addOnsDependentSwitcher == true)
Row(
children: [
Expanded(
flex: 3,
child: Container(
width: 50,
alignment:
Alignment.center,
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
IgnorePointer(
ignoring: (addOnsDependentOpenForEnrollment ==
0 ||
(addOnsDependentOpenForEnrollment !=
0 &&
addOnsDependentECardDownload !=
null)),
child:
DropdownButtonFormField<
String>(
onChanged:
(value) {
setState(() {
addOnsSelectedDependent =
value;
});
addOnsDependentCalculation(
value);
// calculationForDependentSumValue(
// 'Edit');
},
decoration:
InputDecoration(
border:
OutlineInputBorder(),
hintText:
'Sum Insured',
labelText:
'Sum Insured',
contentPadding:
EdgeInsets.symmetric(
vertical:
5,
horizontal:
5),
),
value:
addOnsSelectedDependent,
items: (addOnsDependentSlabRates ??
[])
.map<DropdownMenuItem<String>>(
(addOn) {
return DropdownMenuItem<
String>(
value: addOn[
'si']
.toString(),
child: Text(
'${formatNullableAmount(addOn['si'])}'),
);
}).toList(),
),
)
],
))),
],
),
SizedBox(height: 20),
if (_addOnsDependentSwitcher == true)...[
Column(
children: familyFloaterContainers,
),
SizedBox(height: 10),
GestureDetector(
onTap: () {
dynamic getFalseObjects = addOnsDependentMappedFamilyFloatersDependent
.where((element) => element['is_value_exist'] == false)
.toList();
if (getFalseObjects.length == 0) {
ToastHelper.showWarningToast(context, "No family member to add");
return;
}
openAddFamilyMemberPopup("Add", null);
},
child: Container(
margin: EdgeInsets.only(top: 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.person_add, color: Colors.black),
SizedBox(width: 10),
Text(
"Add Family Member",
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 20 : 16,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
],
if (_addOnsDependentSwitcher)
SizedBox(height: 20),
if (Responsive.isDesktop(context) &&
_addOnsDependentSwitcher &&
shouldShowPremiumSummary(
isPremiumSummary: addOnsDependentIsPremiumSummary,
premiumValue: addOnDependentPremiumValue,
gstValue: addOnsDependentPremiumGst,
totalValue: addOnsDependentTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight
.w500,
),
),
Text(
addOnDependentPremiumValue !=
null
? '$addOnDependentPremiumValue/Year'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight
.w500,
),
),
Text(
addOnsDependentPremiumGst !=
null
? '$addOnsDependentPremiumGst/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight
.w500,
),
),
Text(
addOnsDependentTotalAmt !=
null
? '$addOnsDependentTotalAmt/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
if (!Responsive.isDesktop(context) &&
_addOnsDependentSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: addOnsDependentIsPremiumSummary,
premiumValue: addOnDependentPremiumValue,
gstValue: addOnsDependentPremiumGst,
totalValue: addOnsDependentTotalAmt,
))
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:
Responsive.isDesktop(context) ? 16 : 13,
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:
Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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:
Responsive.isDesktop(context) ? 16 : 13,
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:
Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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:
Responsive.isDesktop(context) ? 16 : 13,
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:
Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
]))
],
)),
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(
Responsive.isDesktop(
context)
? topUpPolicyName
: topUpPolicyType,
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 &&
_hasValidECardDownload(
topUpECardDownload))),
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(
'${formatNullableAmount(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 &&
_hasValidECardDownload(
topUpECardDownload)))
? 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 &&
_hasValidECardDownload(
topUpECardDownload))),
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(
'${formatNullableAmount(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 = 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
: 14,
color: Color(
0xFF232526),
),
),
),
],
);
}).toList(),
),
)
],
),
if (_topUpSiSwitcher == true)
SizedBox(height: 20),
if (Responsive.isDesktop(context) &&
_topUpSiSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: topUpIsPremiumSummary,
premiumValue: topUpSiPremiumValue,
gstValue: topUpSiPremiumGst,
totalValue: topUpSiTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
topUpSiPremiumValue !=
null
? '$topUpSiPremiumValue/Year'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
topUpSiPremiumGst !=
null
? '$topUpSiPremiumGst/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
topUpSiTotalAmt !=
null
? '$topUpSiTotalAmt/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
if (!Responsive.isDesktop(context) &&
_topUpSiSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: topUpIsPremiumSummary,
premiumValue: topUpSiPremiumValue,
gstValue: topUpSiPremiumGst,
totalValue: topUpSiTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
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: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
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: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
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: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
]))
],
),
),
SizedBox(height: 15),
if (opdMappedFamilyFloatersSi != 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(
Responsive.isDesktop(
context)
? opdPolicyName
: opdPolicyType,
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) &&
_opdSwitcher == true)
Expanded(
flex: 3,
child: Container(
width: 50,
alignment: Alignment.center,
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
IgnorePointer(
ignoring: (opdOpenForEnrollment ==
0 ||
(opdOpenForEnrollment !=
0 &&
_hasValidECardDownload(
opdECardDownload))),
child:
DropdownButtonFormField<
String>(
onChanged: (value) {
setState(() {
opdSiSelectedSI =
value;
});
opdSiCalculation(
value);
// calculationForopdSiSumValue(
// 'Edit');
},
decoration:
InputDecoration(
border:
OutlineInputBorder(),
hintText:
'Sum Insured',
labelText:
'Sum Insured',
contentPadding:
EdgeInsets.symmetric(
vertical:
5,
horizontal:
5),
),
value:
opdSiSelectedSI,
items: (opdSlabRates ??
[])
.map<
DropdownMenuItem<
String>>(
(addOn) {
return DropdownMenuItem<
String>(
value: addOn[
'si']
.toString(),
child: Text(
'${formatNullableAmount(addOn['si'])}'),
);
}).toList(),
),
)
],
))),
Expanded(
flex: 3,
child: Container(
alignment:
Alignment.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Switch(
value: _opdSwitcher,
onChanged: (opdOpenForEnrollment ==
0 ||
(opdOpenForEnrollment !=
0 &&
_hasValidECardDownload(
opdECardDownload)))
? null
: (value) {
setState(() {
_opdSwitcher =
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 (_opdSwitcher == true)
SizedBox(height: 10),
if (!Responsive.isDesktop(context) &&
_opdSwitcher == true)
Row(
children: [
Expanded(
flex: 12,
child: Container(
width: 50,
alignment: Alignment.center,
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
IgnorePointer(
ignoring: (opdOpenForEnrollment ==
0 ||
(opdOpenForEnrollment !=
0 &&
_hasValidECardDownload(
opdECardDownload))),
child:
DropdownButtonFormField<
String>(
onChanged: (value) {
setState(() {
opdSiSelectedSI =
value;
});
opdSiCalculation(
value);
// calculationForTopUpSiSumValue(
// 'Edit');
},
decoration:
InputDecoration(
border:
OutlineInputBorder(),
hintText:
'Sum Insured',
labelText:
'Sum Insured',
contentPadding:
EdgeInsets.symmetric(
vertical:
5,
horizontal:
5),
),
value:
opdSiSelectedSI,
items: (opdSlabRates ??
[])
.map<
DropdownMenuItem<
String>>(
(addOn) {
return DropdownMenuItem<
String>(
value: addOn[
'si']
.toString(),
child: Text(
'${formatNullableAmount(addOn['si'])}'),
);
}).toList(),
),
)
],
))),
],
),
if (_opdSwitcher == true)
SizedBox(height: 10),
if (_opdSwitcher ==
true) // Add space between rows
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Expanded(
flex: 12,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children:
opdMappedFamilyFloatersSi
.where((item) =>
item[
'is_value_exist'] ==
true)
.map<Widget>((item) {
Map<String, dynamic> data =
item['data'];
String formattedDate = 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
: 14,
color: Color(
0xFF232526),
),
),
),
],
);
}).toList(),
),
)
],
),
if (_opdSwitcher == true)
SizedBox(height: 20),
if (Responsive.isDesktop(context) &&
_opdSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: opdIsPremiumSummary,
premiumValue: opdSiPremiumValue,
gstValue: opdSiPremiumGst,
totalValue: opdSiTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
opdSiPremiumValue !=
null
? '$opdSiPremiumValue/Year'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
opdSiPremiumGst !=
null
? '$opdSiPremiumGst/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
opdSiTotalAmt !=
null
? '$opdSiTotalAmt/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
if (!Responsive.isDesktop(context) &&
_opdSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: opdIsPremiumSummary,
premiumValue: opdSiPremiumValue,
gstValue: opdSiPremiumGst,
totalValue: opdSiTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight
.w500,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment
.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
Text(
opdSiPremiumValue !=
null
? '$opdSiPremiumValue/Year'
: 'N/A',
textAlign:
TextAlign
.start,
style:
GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight
.w500,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment
.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
Text(
opdSiPremiumGst !=
null
? '$opdSiPremiumGst/-'
: 'N/A',
textAlign:
TextAlign
.start,
style:
GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight
.w500,
),
),
],
))),
Expanded(
flex: 5,
child: Container(
alignment: Alignment
.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment
.center,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
Text(
opdSiTotalAmt !=
null
? '$opdSiTotalAmt/-'
: 'N/A',
textAlign:
TextAlign
.start,
style:
GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
]))
],
),
),
SizedBox(height: (opdPolicyName != null || opdPolicyType != null) ? 15 : 0),
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(
Responsive.isDesktop(
context)
? topUpParentPolicyName
: topUpParentPolicyType,
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(
'${formatNullableAmount(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(
'${formatNullableAmount(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 = 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
: 14,
color: Color(
0xFF232526),
),
),
),
],
);
}).toList(),
),
)
],
),
if (_topUpParentSiSwitcher == true)
SizedBox(height: 20),
if (Responsive.isDesktop(context) &&
_topUpParentSiSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: topUpParentIsPremiumSummary,
premiumValue: topUpParentSiPremiumValue,
gstValue: topUpParentSiPremiumGst,
totalValue: topUpParentSiTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
topUpParentSiPremiumValue !=
null
? '$topUpParentSiPremiumValue/Year'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
topUpParentSiPremiumGst !=
null
? '$topUpParentSiPremiumGst/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight:
FontWeight.w500,
),
),
Text(
topUpParentSiTotalAmt !=
null
? '$topUpParentSiTotalAmt/-'
: 'N/A',
textAlign:
TextAlign.start,
style: GoogleFonts
.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
if (!Responsive.isDesktop(context) &&
_topUpParentSiSwitcher == true &&
shouldShowPremiumSummary(
isPremiumSummary: topUpParentIsPremiumSummary,
premiumValue: topUpParentSiPremiumValue,
gstValue: topUpParentSiPremiumGst,
totalValue: topUpParentSiTotalAmt,
))
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: Responsive.isDesktop(context) ? 16 : 13,
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: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
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: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
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: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
]))
],
),
),
],
),
)),
SizedBox(height: 16),
if (addOnsDependentMappedFamilyFloatersDependent == null &&
topUpMappedFamilyFloatersSi == null &&
topUpParentMappedFamilyFloatersSi == null && opdMappedFamilyFloatersSi == null)
Card(
elevation: 0,
color: Colors.white,
child: Padding(
padding: Responsive.isDesktop(context)
? EdgeInsets.all(30)
: EdgeInsets.all(10),
child: Column(
children: [
if(gpahasPremiumSummary == true || gmchasPremiumSummary == true)...[
Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 12,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Premium Summary',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(
context)
? 18
: 16,
color: Color(0xFF181818),
fontWeight: FontWeight.w600,
),
),
],
))),
],
),
),
SizedBox(height: 15),
if(gpahasPremiumSummary == true || gmchasPremiumSummary == true)
Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 12,
child: Container(
alignment: Alignment
.centerLeft, // Adjust padding as needed
child: Table(
columnWidths: {
0: FlexColumnWidth(
2), // Adjust column width as needed
1: FlexColumnWidth(2),
2: FlexColumnWidth(
2), // Adjust column width as needed
3: FlexColumnWidth(2),
},
children: [
TableRow(
children: [
TableCell(
child: Padding(
padding:
EdgeInsets.all(8.0),
child: Text(
'Policy',
textAlign:
TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive
.isDesktop(
context)
? 16
: 13,
fontWeight:
FontWeight
.bold),
),
),
),
TableCell(
child: Padding(
padding:
EdgeInsets.all(8.0),
child: Text(
'Additional Premium',
textAlign:
TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive
.isDesktop(
context)
? 16
: 13,
fontWeight:
FontWeight
.bold),
),
),
),
TableCell(
child: Padding(
padding:
EdgeInsets.all(8.0),
child: Text(
'GST',
textAlign:
TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive
.isDesktop(
context)
? 16
: 13,
fontWeight:
FontWeight
.bold),
),
),
),
TableCell(
child: Padding(
padding:
EdgeInsets.all(8.0),
child: Text(
'Total',
textAlign:
TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive
.isDesktop(
context)
? 16
: 13,
fontWeight:
FontWeight
.bold),
),
),
),
],
),
if (gpaPolicies != null &&
gpaPolicies.length > 0)
...gpaBuildPolicyRows(
gpaPolicies, context),
if (gmcPolicies != null &&
gmcPolicies.length > 0)
...gmcBuildPolicyRows(
gmcPolicies, context),
],
),
))
],
),
),
SizedBox(height: 10),
Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Total Payable',
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(
context)
? 20
: 16,
color: Color(0xFF181818),
fontWeight: FontWeight.w600,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Text(
'${formatAmount(allTotalSum())}/Year',
textAlign: TextAlign.right,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(
context)
? 18
: 16,
color: Color(0xFFE26728),
fontWeight: FontWeight.w500,
),
),
],
)))
],
),
),
SizedBox(height: 10),
],
Container(
alignment: Alignment.topLeft,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start , // Aligns top
children: [
Checkbox(
value: isChecked,
onChanged: (bool? value) {
setState(() {
isChecked = value!;
});
},
activeColor: const Color(0xFFE26728),
),
Expanded(
child: Text(
'I declare that the information I have provided is true and accurate to the best of my knowledge',
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 18 : 15,
color: const Color(0xFF292929),
),
),
),
],
),
),
SizedBox(
height:
Responsive.isDesktop(context) ? 15 : 10),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: allDisclaimer.isEmpty
? [] // If allDisclaimer is empty, show nothing
: allDisclaimer.map<Widget>((entry) {
int id = entry['id']; // ID of disclaimer
String disclaimer = entry['text']; // Disclaimer text
bool isChecked = entry['checked']; // Checked state
return Padding(
padding: const EdgeInsets.only(bottom: 12.0), // spacing between disclaimers
child: Row(
crossAxisAlignment: CrossAxisAlignment.start, // Align top
children: [
Checkbox(
value: isChecked, // Bind to the checked value
onChanged: (bool? value) {
setState(() {
// Update the checked status
allDisclaimer.firstWhere(
(item) => item['id'] == id,
)['checked'] = value!;
logDebug(allDisclaimer);
});
},
activeColor: const Color(0xFFE26728), // Custom color
),
Expanded(
child: Text(
disclaimer,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context) ? 18 : 15,
color: const Color(0xFF292929),
),
),
),
],
),
);
}).toList(),
),
),
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: () {
context.go('/empDetails');
// 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: isSubmitEnabled()
? 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();
context.go('/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:
addOnsDependentMappedFamilyFloatersDependent !=
null ||
topUpMappedFamilyFloatersSi !=
null ||
opdMappedFamilyFloatersSi !=
null ||
topUpParentMappedFamilyFloatersSi !=
null
? () async {
if (_topUpSiSwitcher == false) {
await removeAddonsGmcSiToAPI();
} else {
checkSiTopUp();
}
if (_opdSwitcher == false) {
await removeAddonsGmcOPDToAPI();
} else {
checkOPDTopUp();
sendAddonsGmcOPDToAPI();
}
if (_topUpParentSiSwitcher ==
false) {
await removeAddonsGmcParentSiToAPI();
} else {
checkSiParentTopUp();
}
if (_addOnsDependentSwitcher ==
false) {
await removeAddonsGmcDependentToAPI();
} else {
checkDependentTopUp();
sendAddonsGmcDependentToAPI();
}
context.push('/empReviewDetails'); // 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
),
),
if (Responsive.isDesktop(context) ||
(!Responsive.isDesktop(context) && !isTokenAvailable))
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity, // Make the footer full width
child: CustomFooter(),
),
),
]),
// floatingActionButton: Responsive.isDesktop(context)
// ? null
// : isTokenAvailable
// ? FloatingActionButton(
// onPressed: () => Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => chatbot()),
// ),
// child: Icon(Icons.chat),
// )
// : null,
floatingActionButtonLocation: Responsive.isDesktop(context)
? null
: isTokenAvailable
? FloatingActionButtonLocation.miniEndFloat
: null,
bottomNavigationBar: Responsive.isDesktop(context)
? null
: isTokenAvailable
? CustomBottomNavigationBar(
onTabChanged: (index) {
// Add your navigation logic here
// repositionBotman();
if (index == 0) {
context.push('/home');
} else if (index == 1) {
context.push('/claims');
} else if (index == 2) {
context.push('/faqs');
} else if (index == 3) {
context.push('/profile');
} else if (index == 4) {
context.push('/help');
}
// else if (index == 4) {
// // context.push('/wellness');
// // Wellness tab clicked → show popup
// if(!isRetailLoggedIn)
// PopupHelper.showRedirectPopup(
// context: context,
// apiService: apiService,
// empPrimaryId: session.empPrimaryId,
// );
// }
},
icons: [
Icons.home_outlined,
Icons.sticky_note_2_outlined,
Icons.question_answer_outlined,
Icons.person_outline_outlined,
Icons.headset_mic_outlined,
],
labels: ["Home", "Claims", "FAQs", "Profile","Help"],
initialIndex: 0, // Initial index of the bottom navigation bar
) : null,
) );
}
}
Future<void> _launchURL(String url) async {
final Uri uri = Uri.parse(url); // Parse the URL properly
if (uri != null) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch $url';
}
}
void openAddFamilyMemberPopup(String action, Map<String, dynamic>? floaterData) {
logDebug('gmcRelationShip : $addOnsDependentRelationShip');
logDebug('editGmcRelationShip : $floaterData');
Map<String, dynamic>? selectedFloaterData;
String? dropdownValue;
// ============================
// NORMALIZE RELATIONSHIP LIST
// ============================
List<Map<String, dynamic>> relationshipObjects = [];
// Case 1: List<String> → convert to full object
if (addOnsDependentRelationShip.isNotEmpty && addOnsDependentRelationShip.first is String) {
relationshipObjects = addOnsDependentRelationShip.map((r) {
return {
"relationship": r,
"client_policy_id":r,
"age_validation": r, // default fallback
};
}).toList();
}
// Case 2: List<Map<String,dynamic>>
else if (addOnsDependentRelationShip.isNotEmpty && addOnsDependentRelationShip.first is Map) {
relationshipObjects = List<Map<String, dynamic>>.from(addOnsDependentRelationShip);
}
logDebug("Normalized relationship list: $relationshipObjects");
Future<bool> showEditConfirmationDialog(
BuildContext dialogContext,
Map<String, dynamic> oldData,
Map<String, dynamic> newData,
bool relationshipEnabled,
) async {
final oldRelationship = (oldData["relationship"] ?? "").toString().trim();
final oldName = (oldData["name"] ?? "").toString().trim();
final oldDob = (oldData["dob"] ?? "").toString().trim();
final newRelationship = (newData["relationship"] ?? "").toString().trim();
final newName = (newData["memberName"] ?? "").toString().trim();
final newDob = (newData["dateOfBirth"] ?? "").toString().trim();
final List<Map<String, String>> changedFields = [];
if (oldRelationship != newRelationship) {
changedFields.add({
"label": "Relationship",
"old": oldRelationship,
"new": newRelationship,
});
}
if (oldName != newName) {
changedFields.add({
"label": "Member Name",
"old": oldName,
"new": newName,
});
}
if (oldDob != newDob) {
changedFields.add({
"label": "Date of Birth",
"old": oldDob,
"new": newDob,
});
}
if (changedFields.isEmpty) {
ToastHelper.showWarningToast(
dialogContext, "No changes detected to save");
return false;
}
final List<Map<String, String>> reviewFields = [];
if (relationshipEnabled || oldRelationship != newRelationship) {
reviewFields.add({
"label": "Relationship",
"old": oldRelationship,
"new": newRelationship,
});
}
reviewFields.add({
"label": "Member Name",
"old": oldName,
"new": newName,
});
reviewFields.add({
"label": "Date of Birth",
"old": oldDob,
"new": newDob,
});
final bool? confirmed = await showDialog<bool>(
context: dialogContext,
barrierDismissible: false,
builder: (confirmContext) {
return AlertDialog(
title: Text(
"Confirm Changes",
style: GoogleFonts.poppins(fontWeight: FontWeight.w600),
),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Please review old and new values before saving:",
style: GoogleFonts.poppins(fontSize: 13),
),
SizedBox(height: 12),
...reviewFields.map((field) {
final oldValue = (field["old"] ?? '').trim().isEmpty
? '-'
: (field["old"] ?? '');
final newValue = (field["new"] ?? '').trim().isEmpty
? '-'
: (field["new"] ?? '');
return Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xFFF9F9F9),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE0E0E0)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
field["label"] ?? '',
style: GoogleFonts.poppins(
fontSize: 14,
fontWeight: FontWeight.w700,
color: const Color(0xFFE26728),
),
),
const SizedBox(height: 8),
RichText(
text: TextSpan(
style: GoogleFonts.poppins(
fontSize: 13,
color: const Color(0xFF232526),
),
children: [
const TextSpan(
text: "OLD: ",
style: TextStyle(
fontWeight: FontWeight.w700,
color: Color(0xFFD32F2F),
),
),
TextSpan(text: oldValue),
],
),
),
const SizedBox(height: 4),
RichText(
text: TextSpan(
style: GoogleFonts.poppins(
fontSize: 13,
color: const Color(0xFF232526),
),
children: [
const TextSpan(
text: "NEW: ",
style: TextStyle(
fontWeight: FontWeight.w700,
color: Color(0xFF2E7D32),
),
),
TextSpan(text: newValue),
],
),
),
],
),
),
);
}).toList(),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(confirmContext, false),
child: Text("Cancel"),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFFE26728),
),
onPressed: () => Navigator.pop(confirmContext, true),
child: Text("Confirm", style: TextStyle(color: Colors.white)),
),
],
);
},
);
return confirmed == true;
}
// Reset UI Fields
_relationShipController.clear();
_memberNameController.clear();
_dobController.clear();
// ============================
// EDIT MODE
// ============================
if (action == "Edit" && floaterData != null) {
String rel = floaterData["relationship"];
dropdownValue = rel;
// Check if the relationship exists in normalized list
var exists = relationshipObjects.any((e) => e["relationship"] == rel);
// If not found (rare case), insert it for dropdown display
if (!exists) {
relationshipObjects.insert(0, {
"relationship": rel,
"client_policy_id":floaterData["client_policy_id"],
"employee_id":floaterData["employee_id"],
"age_validation": floaterData["age_validation"] ?? {"min": "0", "max": "99"},
});
}
selectedFloaterData = relationshipObjects.firstWhere(
(e) => e["relationship"] == rel,
orElse: () => {
"relationship": rel,
"client_policy_id":floaterData["client_policy_id"],
"employee_id":floaterData["employee_id"],
"age_validation": floaterData["age_validation"] ?? {"min": "0", "max": "99"},
});
_relationShipController.text = rel;
_memberNameController.text = floaterData["name"];
_dobController.text = floaterData["dob"];
}
// ============================
// SHOW POPUP
// ============================
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
content: SizedBox(
width: Responsive.isDesktop(context) ? 500 : 350,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
action == "Edit" ? "Edit Family Member" : "Add Family Member",
style: GoogleFonts.poppins(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFFE26728),
),
),
SizedBox(height: 20),
// RELATIONSHIP DROPDOWN
DropdownButtonFormField<String>(
value: dropdownValue,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Relationship",
),
items: relationshipObjects.map((item) {
return DropdownMenuItem<String>(
value: item["relationship"],
child: Text(item["relationship"]),
);
}).toList(),
onChanged: action == "Edit"
? null
: (value) {
dropdownValue = value!;
_relationShipController.text = value;
// assign selected relationship FULL OBJECT
selectedFloaterData = relationshipObjects.firstWhere(
(item) => item["relationship"] == value);
logDebug('selectedFloaterData1234 $selectedFloaterData');
},
),
SizedBox(height: 15),
// FULL NAME FIELD
TextFormField(
controller: _memberNameController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Member Full Name",
),
),
SizedBox(height: 15),
// DOB → passes FULL SELECTED OBJECT
TextFormField(
controller: _dobController,
readOnly: true,
onTap: () {
_selectDate(context, selectedFloaterData ?? floaterData);
},
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Date of Birth",
suffixIcon: IconButton(
icon: Icon(Icons.calendar_today),
onPressed: () {
_selectDate(context, selectedFloaterData ?? floaterData);
},
),
),
),
SizedBox(height: 20),
// ACTION BUTTONS
Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () => Navigator.pop(context),
child: Text("Cancel"),
),
),
SizedBox(width: 10),
Expanded(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFFE26728),
),
onPressed: () async {
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
};
if (action == "Edit" && floaterData != null) {
final shouldProceed = await showEditConfirmationDialog(
context,
floaterData,
formData,
action != "Edit",
);
if (!shouldProceed) {
return;
}
}
// Call the function to send form data to API
saveAddOnsDetails(
formData,
selectedFloaterData ?? floaterData ?? {},
action
);
// Close the dialog
context.pop();
// Navigator.of(context).pop();
}
},
child: Text(
"Save",
style: TextStyle(color: Colors.white),
),
),
),
],
),
],
),
),
);
},
);
}
void openForm(Map<String, dynamic> floaterData, action) {
dynamic popupName = floaterData['button_name'];
// Check if the action is 'Edit'
selectedRelationships = relationshipOptions
.where(
(option) => option['dependent'] == floaterData['form_type'],
)
.toList();
if (action == 'Add') {
if (floaterData['form_type'] == 'parent_in_law' ||
floaterData['form_type'] == 'parent') {
// 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();
List<Map<String, dynamic>> getTrueDataObjects = getTrueObjects
.map<Map<String, dynamic>>(
(element) => element['data'] as Map<String, dynamic>)
.toList();
selectedRelationships.removeWhere((relationship) =>
getTrueDataObjects.any((dataObject) =>
dataObject['relationship'] ==
relationship['relationship_name']));
}
}
if (action == 'Edit') {
// Set values to all fields
_relationShipController.text = floaterData['relationship'] ?? '';
_memberNameController.text = floaterData['name'] ?? '';
_dobController.text = floaterData['dob'] ?? '';
// Add more fields as needed
}
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
elevation: 0,
backgroundColor: Colors.transparent,
content: SizedBox(
width: Responsive.isDesktop(context) ? 500 : 800,
child: SingleChildScrollView(
child: Card(
elevation: 0,
child: Padding(
padding: EdgeInsets.all(30),
child: Column(
children: [
Container(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
flex: 12,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(popupName ?? '',
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFFE26728),
)),
],
),
),
),
],
),
SizedBox(height: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
DropdownButtonFormField<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();
context.pop();
// 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
context.pop();
// 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),
),
),
),
),
),
],
),
],
),
),
],
),
),
),
),
),
);
},
);
}
double toDoubleSafe(dynamic value) {
if (value == null) return 0.0;
if (value is num) return value.toDouble();
if (value is String) return double.tryParse(value) ?? 0.0;
return 0.0;
}
String formatAmount(double value) {
return value % 1 == 0
? value.toInt().toString()
: value.toStringAsFixed(2);
}
String formatNullableAmount(dynamic value, {String fallback = 'NA'}) {
if (value == null) return fallback;
final numericValue = value is num
? value.toDouble()
: double.tryParse(value.toString());
if (numericValue == null) return value.toString();
return formatAmount(numericValue);
}
List<Widget> generateGmcCards(List<dynamic> data) {
List<Widget> cards = [];
for (var item in data) {
String gmcPolicyName = item['Policy_Name'] ?? '';
String gmcPolicyType = item['type'] ?? '';
String gmcFloaterTextHeading = item['floter_text_heading'] ?? '';
String gmcFloaterTextDescription = item['floter_text_description'] ?? '';
String gmcNotes = item['notes'] ?? '';
String gmcECardDownload = item['eCardDownload'] ?? '';
double gmcGstValue =
double.tryParse(item['family_floaters_of_dependent_and_gst_value']?.toString() ?? '0') ?? 0.0;
double gmcSiPremiumValue =
double.tryParse(item['family_floaters_of_dependent_and_si_premium_value']?.toString() ?? '0') ?? 0.0;
double gmcTotalableValue = gmcGstValue + gmcSiPremiumValue;
bool gmcIsValueValid = (gmcSiPremiumValue > 0 && gmcGstValue > 0);
List gmcMappedFamilyFloaters = item['mapped_family_floaters'] ?? [];
// get true objects
List trueObjects = gmcMappedFamilyFloaters
.where((element) => element['is_value_exist'] == true)
.toList();
double gmcSumInsured;
if (trueObjects.isNotEmpty) {
gmcSumInsured = toDoubleSafe(trueObjects[0]["data"]["basic_cover_si"]);
} else {
gmcSumInsured = toDoubleSafe(item['Policy_Terms']?['sum_insured']);
}
String gmcTypeName = gmcPolicyType;
Widget card = trueObjects.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: Responsive.isDesktop(context) ? 9 : 7,
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(
Responsive.isDesktop(context)
? gmcPolicyName
: gmcPolicyType,
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: Responsive.isDesktop(context) ? 3 : 5,
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(
'${formatNullableAmount(gmcSumInsured)}',
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 = 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 : 14,
color: Color(0xFF232526),
),
),
),
],
);
}).toList(),
),
),
if (Responsive.isDesktop(context) && gmcIsValueValid)
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
Text(
formatAmount(gmcSiPremiumValue),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
Text(
formatAmount(gmcGstValue),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
Text(
formatAmount(gmcTotalableValue),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
if (!Responsive.isDesktop(context) && gmcIsValueValid)
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
formatAmount(gmcSiPremiumValue),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
formatAmount(gmcGstValue),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
],
))),
Expanded(
flex: 5,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
formatAmount(gmcTotalableValue),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
]))
],
),
))
: SizedBox(height: 0);
cards.add(card);
}
return cards;
}
List<Widget> generateGpaCards(List<dynamic> data) {
List<Widget> cards = [];
for (var item in data) {
String? gpaPolicyName = item['Policy_Name'];
String? gpaPolicyType = item['type'];
String? gpaECardDownload = item['eCardDownload'];
String? gpaSumInsured;
// Safe numeric conversion
double gpaGstValue = toDoubleSafe(item['si_gst_value']);
double gpaSiPremiumValue = toDoubleSafe(item['si_premium_value']);
double gpaTotalableValue = gpaSiPremiumValue + gpaGstValue;
bool isValueValid = gpaSiPremiumValue != 0 && gpaGstValue != 0;
// -------------------------------
// FIX: mapped_family_floaters is ALREADY a list
// -------------------------------
List<dynamic> gpaMappedFamilyFloaters =
item['mapped_family_floaters'] is List
? item['mapped_family_floaters']
: [];
// -------------------------------
// FIX: get true objects
// -------------------------------
List<dynamic> getTrueObjects = gpaMappedFamilyFloaters
.where((element) => element['is_value_exist'] == true)
.toList();
// -------------------------------
// FIX: safe Sum Insured check
// -------------------------------
if (getTrueObjects.isNotEmpty) {
gpaSumInsured = getTrueObjects[0]["data"]["basic_cover_si"];
} else {
gpaSumInsured = item['Policy_Terms']?['sumInsured2'];
}
// -------------------------------
// FIX: Safe parsing of OpenForEnrollment
// backend could send "1", 1, null
// -------------------------------
int gpaOpenForEnrollment = 0;
dynamic enroll = item['OpenForEnrollment'];
if (enroll is int) gpaOpenForEnrollment = enroll;
else if (enroll is String) gpaOpenForEnrollment = int.tryParse(enroll) ?? 0;
List<Widget> familyFloaterContainers = [];
for (var floater in gpaMappedFamilyFloaters) {
bool isValueExist = floater['is_value_exist'];
Map<String, dynamic> floaterData = floater['data'];
final dobDate = floaterData['dob'] ?? '';
gpaSelfDetails = floaterData['name'] +
' ~ ' +
floaterData['relationship'] +
' ~ ' +
' DOB : ' + dobDate;
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 : 14,
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: Responsive.isDesktop(context) ? 9 : 7,
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(
Responsive.isDesktop(context)
? '$gpaPolicyName'
: '$gpaPolicyType',
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: Responsive.isDesktop(context) ? 3 : 5,
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(
'${formatNullableAmount(gpaSumInsured)}',
textAlign: TextAlign.right,
style: GoogleFonts.poppins(
fontSize:
Responsive.isDesktop(context) ? 20 : 14,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
],
),
),
SizedBox(height: 10),
Column(
children: familyFloaterContainers,
),
if (Responsive.isDesktop(context) && isValueValid)
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
Text(
(gpaSiPremiumValue ?? '').toString(),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
Text(
(gpaGstValue ?? '').toString(),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
Text(
(gpaTotalableValue ?? '').toString(),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
if (!Responsive.isDesktop(context) && isValueValid)
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
(gpaSiPremiumValue ?? '').toString(),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
],
))),
Expanded(
flex: 6,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
(gpaGstValue ?? '').toString(),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
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: Responsive.isDesktop(context) ? 16 : 13,
fontWeight: FontWeight.w500,
),
),
],
))),
Expanded(
flex: 5,
child: Container(
alignment: Alignment.centerRight,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
(gpaTotalableValue ?? '').toString(),
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12,
),
),
],
))),
],
),
]))
],
),
),
);
cards.add(card);
}
return cards;
}
double calculateGpaTotalAmt(List<Map<String, dynamic>> policies) {
double total = policies
.where((policy) => policy is Map<String, dynamic>)
.map((policy) =>
(policy["si_gst_value"] ?? 0) + (policy["si_premium_value"] ?? 0))
.fold(0.0, (sum, value) => sum + value);
logDebug('Calculated gpaTotalAmt: $total'); // Debug print
return total;
}
List<TableRow> gpaBuildPolicyRows(dynamic policies, BuildContext context) {
if (policies is! List) {
return []; // Return empty list if policies is not a list
}
gpaTotalAmt = calculateGpaTotalAmt(policies.cast<Map<String, dynamic>>());
logDebug('gpaTotalAmt $gpaTotalAmt');
return (policies as List)
.where((policy) => policy is Map<String,
dynamic>) // Ensure each item is a Map<String, dynamic>
.map((policy) {
var siGstValue = policy["si_gst_value"] ?? 0;
var siPremiumValue = policy["si_premium_value"] ?? 0;
if (siGstValue == 0 || siPremiumValue == 0)
return null; // Skip invalid policies
return TableRow(
children: [
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
Responsive.isDesktop(context)
? (policy["Policy_Name"] ?? 'Default Policy Name')
: policy['type'],
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'${policy["si_premium_value"]}/Year',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'${policy["si_gst_value"]}/-',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'${(policy["si_premium_value"] ?? 0) + (policy["si_gst_value"] ?? 0)}/-',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
],
);
})
.whereType<TableRow>() // Filter out null values
.toList();
}
double calculateGmcTotalAmt(List<Map<String, dynamic>> policies) {
double total = policies
.where((policy) => policy is Map<String, dynamic>)
.map((policy) =>
(policy["family_floaters_of_dependent_and_gst_value"] ?? 0) +
(policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0))
.fold(0.0, (sum, value) => sum + value);
logDebug('Calculated gmcTotalAmt: $total'); // Debug print
return total;
}
List<TableRow> gmcBuildPolicyRows(dynamic policies, BuildContext context) {
logDebug('gmcBuildPolicyRows $policies');
if (policies is! List) {
return []; // Return empty list if policies is not a list
}
gmcTotalAmt = calculateGmcTotalAmt(policies.cast<Map<String, dynamic>>());
logDebug('gmcTotalAmt $gmcTotalAmt');
return (policies as List)
.where((policy) => policy is Map<String,
dynamic>) // Ensure each item is a Map<String, dynamic>
.map((policy) {
var siGstValue =
policy["family_floaters_of_dependent_and_gst_value"] ?? 0;
var siPremiumValue =
policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0;
if (siGstValue == 0 || siPremiumValue == 0)
return null; // Skip invalid policies
return TableRow(
children: [
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
Responsive.isDesktop(context)
? (policy["Policy_Name"] ?? 'Default Policy Name')
: policy['type'],
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'${policy["family_floaters_of_dependent_and_si_premium_value"]}/Year',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'${policy["family_floaters_of_dependent_and_gst_value"]}/-',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
TableCell(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'${(policy["family_floaters_of_dependent_and_si_premium_value"] ?? 0) + (policy["family_floaters_of_dependent_and_gst_value"] ?? 0)}/-',
textAlign: TextAlign.start,
style: GoogleFonts.poppins(
fontSize: Responsive.isDesktop(context) ? 14 : 12),
),
),
),
],
);
})
.whereType<TableRow>() // Filter out null values
.toList();
}
}