diff --git a/lib/presentation/RaiseClaimForm.dart b/lib/presentation/RaiseClaimForm.dart index e75febb..b541f5a 100644 --- a/lib/presentation/RaiseClaimForm.dart +++ b/lib/presentation/RaiseClaimForm.dart @@ -71,7 +71,6 @@ class _RaiseClaimDialogState extends State { dynamic emailId; List> employeePolicyList = []; String? selectedFileNames; - // html.File? uploadedFile; // List uploadedFiles = []; List uploadedFiles = []; @@ -145,7 +144,6 @@ class _RaiseClaimDialogState extends State { bool isIntimationDateValid = true; bool isAdmitDateValid = true; bool isDischargeDateValid = true; - bool isAccidentService = false; @override void initState() { @@ -220,9 +218,9 @@ class _RaiseClaimDialogState extends State { getClaimPoliciesApi = Map.from(response['data']); departmentList = (getClaimPoliciesApi['ticket_type'] as List) .map>((item) => { - 'id': int.parse(item['ticket_type'].toString()), - 'name': item['type_name'].toString(), - }) + 'id': int.parse(item['ticket_type'].toString()), + 'name': item['type_name'].toString(), + }) .toList(); }); } else { @@ -338,7 +336,7 @@ class _RaiseClaimDialogState extends State { if (response['status'] == 'success') { final List> members = - List>.from(response['data']); + List>.from(response['data']); setState(() { employeePolicyList = members.map((m) { @@ -374,6 +372,7 @@ class _RaiseClaimDialogState extends State { } Future sendFormDataToApi() async { + setState(() { isServiceValid = serviceId != null; isPolicyValid = selectedClientPolicyId != null; @@ -396,8 +395,6 @@ class _RaiseClaimDialogState extends State { // ☠ Accident / Death final isAccident = [2, 3, 4].contains(serviceId); - isAccidentService = isAccident ? true : false; - isAccidentDateValid = !isAccident || accidentDate != null; isIntimationDateValid = !isAccident || intimationDate != null; }); @@ -553,10 +550,9 @@ class _RaiseClaimDialogState extends State { pdf.addPage( pw.Page( - build: (pw.Context context) => - pw.Center( - child: pw.Image(image, fit: pw.BoxFit.contain), - ), + build: (pw.Context context) => pw.Center( + child: pw.Image(image, fit: pw.BoxFit.contain), + ), ), ); @@ -651,9 +647,9 @@ class _RaiseClaimDialogState extends State { Future _pickFromToDate(BuildContext context) async { // Define the policy date range final DateTime policyStartDate = - DateFormat('dd-MMM-yyyy').parse(rawPolicyStartDate); + DateFormat('dd-MMM-yyyy').parse(rawPolicyStartDate); final DateTime policyEndDate = - DateFormat('dd-MMM-yyyy').parse(rawPolicyEndDate); + DateFormat('dd-MMM-yyyy').parse(rawPolicyEndDate); // Show the date range picker within the policy date limits final DateTimeRange? pickedDateRange = await showDateRangePicker( @@ -717,45 +713,44 @@ class _RaiseClaimDialogState extends State { @override Widget build(BuildContext context) { return Dialog( - backgroundColor: Colors.white, // ✅ PURE WHITE popup - insetPadding: const EdgeInsets.all(20), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(16), - child: SizedBox( - width: MediaQuery.of(context).size.width * 0.75, // Desktop popup width - height: MediaQuery.of(context).size.height * 0.85, // 🔥 ADD THIS - child: Stack( - children: [ - /// MAIN CONTENT (YOUR EXISTING UI) - SingleChildScrollView( - child: Container( - padding: EdgeInsets.all(20), - color: Colors.white, - child: Column( - children: [ - /// 🔹 HEADER ROW (Title + Close) - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Raise Insurance Claim", - style: GoogleFonts.poppins( - fontSize: 20, - fontWeight: FontWeight.w600, + backgroundColor: Colors.white, // ✅ PURE WHITE popup + insetPadding: const EdgeInsets.all(20), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(16), + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.75, // Desktop popup width + // height: MediaQuery.of(context).size.height * 0.85, + child: Stack( + children: [ + /// MAIN CONTENT (YOUR EXISTING UI) + SingleChildScrollView( + child: Container( + padding: EdgeInsets.all(20), + color: Colors.white, + child: Column( + children: [ + /// 🔹 HEADER ROW (Title + Close) + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Raise Insurance Claim", + style: GoogleFonts.poppins( + fontSize: 20, + fontWeight: FontWeight.w600, + ), ), - ), - IconButton( - icon: const Icon(Icons.close), - tooltip: 'Close', - onPressed: () => Navigator.pop(context), - ), - ], - ), + IconButton( + icon: const Icon(Icons.close), + onPressed: () => Navigator.pop(context), + ), + ], + ), - const SizedBox(height: 16), + const SizedBox(height: 16), Form( key: formKey, @@ -765,8 +760,7 @@ class _RaiseClaimDialogState extends State { buildDropdownField( 'Service', (value) { - final selectedItem = departmentList - .firstWhere( + final selectedItem = departmentList.firstWhere( (item) => item['id'] == value, orElse: () => {}, ); @@ -782,24 +776,21 @@ class _RaiseClaimDialogState extends State { departmentList, 'name', serviceId, - isRequired: true, + required: true, isValid: isServiceValid, ), buildDropdownField( 'Select Policy', (value) { final selectedPolicy = - policyNumberList.firstWhere(( - p) => p['id'] == value); + policyNumberList.firstWhere((p) => p['id'] == value); setState(() { // ✅ THIS is what you send to API - selectedClientPolicyId = - selectedPolicy['id']; + selectedClientPolicyId = selectedPolicy['id']; // optional - selectedPolicyTypeId = - selectedPolicy['policy_type_id']; + selectedPolicyTypeId = selectedPolicy['policy_type_id']; policyNumberId = value; isPolicyValid = true; @@ -810,71 +801,54 @@ class _RaiseClaimDialogState extends State { policyNumberList, 'label', // 👈 DISPLAY FIELD policyNumberId, - isRequired: true, - isValid: isPolicyValid, // 👈 Hooked to your state + required: true, + isValid: isPolicyValid, ), buildDropdownFieldSearch( 'Member Name', (value) { - final member = employeePolicyList - .firstWhere( + final member = employeePolicyList.firstWhere( (m) => m['id'] == value, ); setState(() { selectedMemberId = value; - selectedMemberObject = - member; // ✅ FULL OBJECT + selectedMemberObject = member; // ✅ FULL OBJECT selectedMemberName = member['name']; isMemberValid = true; - print( - 'selectedMemberObject $selectedMemberObject'); + print('selectedMemberObject $selectedMemberObject'); }); }, employeePolicyList, 'name', selectedMemberId, - isRequired: true, - isValid: isMemberValid, // 👈 Hooked to your state + required: true, + isValid: isMemberValid, ), ]), _row([ - buildTextField('Message', messageController, - isRequired: false, isValid: true), + buildTextField('Message', messageController), if (serviceId == 1 || serviceId == 72)...[ - buildTextField( - 'Hospital Name', hospitalNameController, - isRequired: true, - isValid: isHospitalNameValid), - buildTextField('Hospital Address', - hospitalAddressController, - isRequired: true, - isValid: isHospitalAddressValid), + buildTextField('Hospital Name', hospitalNameController,required: true, isValid: isHospitalNameValid), + buildTextField('Hospital Address', hospitalAddressController,required: true, isValid: isHospitalAddressValid), ] ]), if (serviceId == 1 || serviceId == 72) _row([ - buildTextField( - 'Hospital City', hospitalCityController, - isRequired: true, - isValid: isHospitalCityValid), - buildTextField( - 'Hospital State', hospitalStateController, - isRequired: true, - isValid: isHospitalStateValid), + buildTextField('Hospital City', hospitalCityController,required: true, isValid: isHospitalCityValid), + buildTextField('Hospital State', hospitalStateController,required: true, isValid: isHospitalStateValid), buildTextField( 'Hospital Pincode', hospitalPinCodeController, keyboardType: TextInputType.number, - isRequired: true, - isValid: isHospitalPincodeValid, inputFormatters: [ FilteringTextInputFormatter.digitsOnly, LengthLimitingTextInputFormatter(6), ], + required: true, isValid: isHospitalPincodeValid ), ]), if (serviceId == 1 || serviceId == 72) @@ -883,46 +857,38 @@ class _RaiseClaimDialogState extends State { 'Hospital Phone No', hospitalPhoneNoController, keyboardType: TextInputType.number, - isRequired: true, - isValid: isHospitalPhoneNoValid, inputFormatters: [ FilteringTextInputFormatter.digitsOnly, LengthLimitingTextInputFormatter(10), ], + required: true, isValid: isHospitalPhoneNoValid ), buildDatePickerField( label: 'Admit Date', selectedDate: admitDate, allowFuture: false, - isRequired: true, - isValid: isAdmitDateValid, onDateSelected: (d) { setState(() { admitDate = d; dischargeDate = null; }); }, + required: true, isValid: isAdmitDateValid ), buildDatePickerField( label: 'Discharge Date', selectedDate: dischargeDate, allowFuture: true, - minDate: admitDate?.add( - const Duration(days: 1)), - isRequired: true, - isValid: isDischargeDateValid, - onDateSelected: (d) => - setState(() => dischargeDate = d), + minDate: admitDate?.add(const Duration(days: 1)), + onDateSelected: (d) => setState(() => dischargeDate = d), + required: true, isValid: isDischargeDateValid ), buildTextField( 'Claims Amount', claimAmountController, keyboardType: TextInputType.number, - isRequired: true, - isValid: isClaimAmountValid, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly - ], + inputFormatters: [FilteringTextInputFormatter.digitsOnly], + required: true, isValid: isClaimAmountValid ), ]), @@ -932,16 +898,12 @@ class _RaiseClaimDialogState extends State { label: 'Date of Birth', selectedDate: birthDate, allowFuture: false, - isRequired: false,isValid: true, - onDateSelected: (d) => - setState(() => birthDate = d), + onDateSelected: (d) => setState(() => birthDate = d), ), buildDatePickerField( label: 'Accident Date', selectedDate: accidentDate, allowFuture: false, - isRequired: isAccidentService, - isValid: isAccidentDateValid, onDateSelected: (d) { setState(() { accidentDate = d; @@ -949,15 +911,13 @@ class _RaiseClaimDialogState extends State { intimationDate = null; }); }, + required: true, isValid: isAccidentDateValid ), buildDatePickerField( label: 'Date of Death', selectedDate: deathDate, allowFuture: false, - isRequired: false, - isValid: true, - onDateSelected: (d) => - setState(() => deathDate = d), + onDateSelected: (d) => setState(() => deathDate = d), ), ]), if ([2, 3, 4].contains(serviceId)) @@ -966,19 +926,14 @@ class _RaiseClaimDialogState extends State { label: 'Date of Intimation', selectedDate: intimationDate, allowFuture: false, - isRequired: isAccidentService, - isValid: isIntimationDateValid, - onDateSelected: (d) => - setState(() => intimationDate = d), + onDateSelected: (d) => setState(() => intimationDate = d), + required: true, isValid: isIntimationDateValid ), buildTextField( 'Sum Insured', sumInsuredController, keyboardType: TextInputType.number, - isRequired: false,isValid: true, - inputFormatters: [ - FilteringTextInputFormatter.digitsOnly - ], + inputFormatters: [FilteringTextInputFormatter.digitsOnly], ), const SizedBox(), ]), @@ -992,9 +947,7 @@ class _RaiseClaimDialogState extends State { width: 120, height: 42, child: ElevatedButton( - onPressed: isSubmitting - ? null - : sendFormDataToApi, + onPressed: isSubmitting ? null : sendFormDataToApi, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFE26728), shape: RoundedRectangleBorder( @@ -1052,45 +1005,86 @@ class _RaiseClaimDialogState extends State { return Padding( padding: const EdgeInsets.only(bottom: 14), child: Row( - crossAxisAlignment: CrossAxisAlignment.start, children: children .map((e) => Expanded( - child: Padding( - padding: const EdgeInsets.only(right: 12), - child: e, - ))) + child: Padding( + padding: const EdgeInsets.only(right: 12), + child: e, + ))) .toList(), ), ); } - Widget buildTextField(String label, + Widget fieldLabel(String text, {bool required = false}) { + return Padding( + padding: const EdgeInsets.only(bottom: 6), + child: RichText( + text: TextSpan( + text: text, + style: GoogleFonts.poppins( + fontSize: 12, + fontWeight: FontWeight.w500, + color: Colors.black, + ), + children: required + ? const [ + TextSpan( + text: ' *', + style: TextStyle(color: Colors.red), + ) + ] + : [], + ), + ), + ); + } + + Widget errorText(bool isValid) { + return SizedBox( + height: 16, // fixed height for alignment + child: isValid + ? null + : const Text( + "Required", + style: TextStyle( + color: Colors.red, + fontSize: 11, + ), + ), + ); + } + + + Widget buildTextField( + String label, TextEditingController controller, { + bool required = false, + bool isValid = true, TextInputType keyboardType = TextInputType.text, - bool isRequired = true, bool isValid = true, List? inputFormatters, }) { - return Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - fieldLabel(label, isRequired: isRequired), - formBox( - child: TextField( - controller: controller, - keyboardType: keyboardType, - inputFormatters: inputFormatters, - decoration: const InputDecoration( - isDense: true, - border: InputBorder.none, - ), + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + fieldLabel(label, required: required), + formBox( + child: TextField( + controller: controller, + keyboardType: keyboardType, + inputFormatters: inputFormatters, + decoration: const InputDecoration( + isDense: true, + border: InputBorder.none, ), ), - if (!isValid) validationText(), - ], - ),); + ), + errorText(isValid), + ], + ); } + Widget buildTextAreaField(String label, TextEditingController controller) { return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -1121,76 +1115,51 @@ class _RaiseClaimDialogState extends State { List> itemsList, String displayField, int? selectedValue, { - bool isRequired = true, + bool required = false, bool isValid = true, }) { - - // Logic to calculate font size based on string length - double getDynamicFontSize(String text) { - if (text.length > 25) return 9.0; - if (text.length > 15) return 10.0; - return 12.0; - } - return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - fieldLabel(label, isRequired: isRequired), + fieldLabel(label, required: required), formBox( child: DropdownButtonHideUnderline( child: DropdownButton( isExpanded: true, value: selectedValue, - hint: const Text( - 'Select', - style: TextStyle(fontSize: 12), - ), + hint: const Text('Select'), icon: const Icon(Icons.keyboard_arrow_down), items: itemsList.map>((item) { - String textValue = item[displayField].toString(); // Get the text first return DropdownMenuItem( value: item['id'], - child: Text( - textValue, - overflow: TextOverflow.ellipsis, - softWrap: false, - maxLines: 1, // Strictly keep to one line - style: TextStyle( - // Call the function here and pass the textValue - fontSize: getDynamicFontSize(textValue), - ), - ), + child: Text(item[displayField]), ); }).toList(), onChanged: onChanged, ), ), ), - if (!isValid) - Padding( - padding: const EdgeInsets.only(top: 4, left: 4), - child: Text( - "Required", - style: TextStyle(color: Colors.red, fontSize: 12), - ), - ), + if (required) errorText(isValid), ], ); } - Widget buildDropdownFieldSearch(String label, + + + Widget buildDropdownFieldSearch( + String label, void Function(int?) onChanged, List> itemsList, String displayField, - int? selectedValue, - { - bool isRequired = true, // Added - bool isValid = true, // Added + int? selectedValue, { + bool required = false, + bool isValid = true, }) { + return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - fieldLabel(label, isRequired: isRequired), + fieldLabel(label, required: required), const SizedBox(height: 4), Container( height: 40, @@ -1270,12 +1239,7 @@ class _RaiseClaimDialogState extends State { ), ), ), - if (!isValid) - Padding( - padding: const EdgeInsets.only(top: 4, left: 4), - child: Text("Required", - style: GoogleFonts.poppins(color: Colors.red, fontSize: 12)), - ), + if (required) errorText(isValid), ], ); } @@ -1288,14 +1252,24 @@ class _RaiseClaimDialogState extends State { required ValueChanged onDateSelected, DateTime? minDate, DateTime? maxDate, - bool isRequired = true, + bool required = false, bool isValid = true, }) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - fieldLabel(label, isRequired: isRequired), - formBox( + fieldLabel(label, required: required), + + Container( + height: 42, + padding: const EdgeInsets.symmetric(horizontal: 12), + decoration: BoxDecoration( + color: const Color(0xFFF1F1F1), + borderRadius: BorderRadius.circular(8), + // border: required && !isValid + // ? Border.all(color: Colors.red) + // : null, + ), child: InkWell( onTap: () async { final DateTime now = DateTime.now(); @@ -1331,11 +1305,13 @@ class _RaiseClaimDialogState extends State { ), ), ), - if (!isValid) validationText(), + + errorText(isValid), ], ); } + // Widget uploadBox() { // return Column( // crossAxisAlignment: CrossAxisAlignment.start, @@ -1370,39 +1346,6 @@ class _RaiseClaimDialogState extends State { ); } - Widget fieldLabel(String text, {bool isRequired = false}) { - return Padding( - padding: const EdgeInsets.only(bottom: 6), - child: RichText( - text: TextSpan( - text: text, - style: GoogleFonts.poppins( - fontSize: 12, - fontWeight: FontWeight.w500, - color: Colors.black, - ), - children: [ - if (isRequired) - const TextSpan( - text: ' *', - style: TextStyle( - color: Colors.red, fontWeight: FontWeight.bold), - ), - ], - ), - ), - ); - } - Widget validationText() { - return Padding( - padding: const EdgeInsets.only(top: 4, left: 4), - child: Text( - "Required", - style: GoogleFonts.poppins( - color: Colors.red, fontSize: 12, fontWeight: FontWeight.w500), - ), - ); - } } // class RaiseClaimDialog extends StatelessWidget {