This commit is contained in:
Surendiran 2026-01-23 19:08:28 +05:30
commit d991ee2a49
4 changed files with 93 additions and 47 deletions

File diff suppressed because one or more lines are too long

View File

@ -392,6 +392,10 @@ class BrokerState extends ConsumerState<Broker> {
child: ThemedFormInlineField(
controller: controllers['code']!,
validator: (value) => Validators.requiredField(value, "code"),
inputFormatters: [
// This line now allows letters, numbers, hyphens, and underscores
FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9\-_ ]')),
],
txtwidth: MediaQuery.of(context).size.width * 0.15,
borderColor: Color(0xFFE2E8F0),
highlightColor: Color(0xFF50A398),

View File

@ -94,7 +94,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
'enquiry_vehicle_type_id_for_commission',
//find Policy
'insurance_plan_type',
'insurance_plan_type_id',
];
late Map<String, TextEditingController> controllers;
String? selectedInsuranceId;
@ -129,6 +129,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
String? selectedPaymentMode;
String? selectedFuelType;
String? selectedBroker;
String? selectedInsurerName;
String? selectedInsurerShortName;
final GlobalKey<DropdownSearchState<Map<String, dynamic>>> dropDownKey =
GlobalKey<DropdownSearchState<Map<String, dynamic>>>();
@ -282,7 +284,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
? controllers["payment_mode"]?.text
: selectedPaymentMode,
"insurance_plan_type_id": selectedInsurancePlanTypeId,
// "insurance_plan_type": controllers["insurance_plan_type"]?.text.trim().isNotEmpty == true ? controllers['insurance_plan_type']?.text : selectedInsurancPlanType,
};
}
@ -707,6 +708,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
if (!mounted) return;
debugPrint('findPolicyApi response2:');
setState(() {
selectedInsurerShortName = safeText(data['insurer_short_name']);
selectedInsurerName = safeText(data['insurer_name']);
controllers["policyNumber"]?.text = safeText(data['policy_number']);
controllers["insuredName"]!.text = safeText(data['insured_name']);
controllers["premiumAmount"]!.text = safeText(data['premium_amount']);
@ -753,23 +756,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
data['year_of_manufacture'],
);
// selectedInsurancPlanType = safeText(data['insurance_plan_type']);
// controllers["insurance_plan_type"]?.text = safeText(data['insurance_plan_type']);
final planName = safeText(data['insurance_plan_type']);
final matchedPlan = filteredInsurancPlanTypeData.firstWhere(
(item) =>
item['insurance_plan_type']
.toString()
.toLowerCase() ==
planName.toLowerCase(),
orElse: () => {},
);
if (matchedPlan.isNotEmpty) {
selectedInsurancePlanTypeId = matchedPlan['id'].toString();
}
selectedInsuranceId = safeText(data['insurer_id']);
selectedAgentRentionRate = safeText(data['agent_retention_rate']);
selectedManagerRentionRate = safeText(data['manager_retention_rate']);
@ -782,6 +768,11 @@ class _policyValidationState extends ConsumerState<policyValidation> {
selectedVehicleTypeForEnquiryID = data['enquiry_vehicle_type_id_for_commission']?.toString() ?? '';
controllers["enquiry_reg_no_for_commission"]?.text = safeText(data['enquiry_reg_no_for_commission']);
// controllers["rcNo"]!.text = safeText(data['rc_no']);
// 1. Set the State variable (This makes the Dropdown show the correct item)
selectedInsurancePlanTypeId = data['insurance_plan_type_id']?.toString();
// 2. Set the Controller (This ensures dataDetails() can pick it up if needed)
controllers["insurance_plan_type_id"]?.text = selectedInsurancePlanTypeId ?? '';
});
debugPrint('findPolicyApi response3:');
@ -1466,7 +1457,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
}
Widget buildInsurancPlanType(BuildContext context) {
final Map<String, dynamic>? selectedPlan =
final Map<String, dynamic>? selectedIPT =
selectedInsurancePlanTypeId != null
? filteredInsurancPlanTypeData.firstWhere(
(item) =>
@ -1487,28 +1478,46 @@ class _policyValidationState extends ConsumerState<policyValidation> {
),
),
const SizedBox(height: 6),
DropdownSearch<Map<String, dynamic>>(
key: dropDownKeyInsurancPlanType,
items: (filter, _) => filteredInsurancPlanTypeData,
selectedItem:
selectedPlan != null && selectedPlan.isNotEmpty
? selectedPlan
: null,
itemAsString: (item) =>
item['insurance_plan_type'].toString(),
// disabledItemFn: (item) => item['is_active'] == "0",
compareFn: (a, b) =>
a['id'].toString() == b['id'].toString(),
selectedItem: selectedIPT != null && selectedIPT.isNotEmpty
? selectedIPT
: null,
itemAsString: (item) => item['insurance_plan_type'].toString(),
// 2. Styling for the items in the list
popupProps: PopupProps.menu(
itemBuilder: (context, item, isSelected, isHovered) {
final bool isActive = item['is_active'] == "1";
return ListTile(
title: Text(
item['insurance_plan_type'].toString(),
style: TextStyle(
// Gray out text if inactive
color: isActive ? Colors.black : Colors.grey,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
// Add a "Disabled" subtitle for clarity
subtitle: isActive ? null : const Text("Inactive", style: TextStyle(fontSize: 10, color: Colors.red)),
);
},
),
onChanged: (val) {
if (val != null) {
// setState(() {
selectedInsurancePlanTypeId =
val['id'].toString();
// });
selectedInsurancePlanTypeId = val['id'].toString(); // store ID
// WRITE INTO CONTROLLER (CRITICAL)
controllers['insurance_plan_type_id']?.text = selectedInsurancePlanTypeId!;
}
},
@ -1522,7 +1531,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
}
Widget _sectionHeader(String title, {IconData icon = Icons.info}) {
Widget _sectionHeader(String title, {IconData icon = Icons.info , String? rightTitle,}) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
decoration: BoxDecoration(
@ -1544,6 +1553,18 @@ class _policyValidationState extends ConsumerState<policyValidation> {
title,
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
),
// Push right title to end
const Spacer(),
// Right title (optional)
if (rightTitle != null && rightTitle.isNotEmpty)
Text(
rightTitle,
style: GoogleFonts.poppins(
fontWeight: FontWeight.w600,
fontSize: 12,
),
),
],
),
);
@ -1559,13 +1580,32 @@ class _policyValidationState extends ConsumerState<policyValidation> {
String? hintText,
List<TextInputFormatter>? inputFormatters, // 👈 ADD THIS
ValueChanged<String>? onChanged, // 👈 ADD THIS
String? rightLabel, // 👈 ADD THIS
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
// Text(
// label,
// style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
// ),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label,
style: GoogleFonts.poppins(fontWeight: FontWeight.w500, fontSize: 11),
),
if (rightLabel != null)
Text(
rightLabel,
style: GoogleFonts.poppins(
fontWeight: FontWeight.w500,
fontSize: 11,
color: Colors.grey[700],
),
),
],
),
const SizedBox(height: 6),
TextFormField(
@ -1822,6 +1862,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
_sectionHeader(
'Policy Details',
icon: Icons.policy,
rightTitle: selectedInsurerShortName?.isNotEmpty == true ? 'INSURER - ${selectedInsurerShortName}' : '',
),
SizedBox(height: 10),
Row(
@ -1831,6 +1872,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
'Policy Number *',
controllers['policyNumber']!,
required: true,
// rightLabel: selectedInsurerName,
),
),
const SizedBox(width: 8),

View File

@ -700,26 +700,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
url: "https://pub.dev"
source: hosted
version: "11.0.2"
version: "10.0.9"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
version: "3.0.10"
version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.1"
lints:
dependency: transitive
description:
@ -1297,10 +1297,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev"
source: hosted
version: "0.7.6"
version: "0.7.4"
toastification:
dependency: "direct main"
description:
@ -1417,10 +1417,10 @@ packages:
dependency: transitive
description:
name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.1.4"
vm_service:
dependency: transitive
description: