This commit is contained in:
venbaittech 2025-12-15 16:20:42 +05:30
commit b9f2032d3b
3 changed files with 436 additions and 423 deletions

File diff suppressed because one or more lines are too long

View File

@ -55,6 +55,15 @@ import 'dart:typed_data';
// ); // );
// } // }
// } // }
import 'package:flutter/services.dart';
final digitsOnlyFormatter = [
FilteringTextInputFormatter.digitsOnly,
];
final decimalFormatter = [
FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}$')),
];
class policyValidation extends ConsumerStatefulWidget { class policyValidation extends ConsumerStatefulWidget {
final dynamic item; final dynamic item;
@ -109,6 +118,8 @@ class _policyValidationState extends ConsumerState<policyValidation> {
late TextEditingController commissionAmountController; late TextEditingController commissionAmountController;
final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey(); final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
final _formKey = GlobalKey<FormState>();
@override @override
void initState() { void initState() {
@ -247,14 +258,6 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Future<void> getPolicyFilePath() async { Future<void> getPolicyFilePath() async {
_pdfViewerKey.currentState?.openBookmarkView(); _pdfViewerKey.currentState?.openBookmarkView();
// 🔥 Use DIRECT FIXED URL you asked for
// const directPdfUrl = "https://venbait.in/nhance/mypdf.pdf";
//
// setState(() {
// pdfUrl = directPdfUrl;
// });
//
// debugPrint("FINAL PDF URL -> $pdfUrl");
final policyId = widget.item?['policy_id']; final policyId = widget.item?['policy_id'];
if (policyId == null) { if (policyId == null) {
@ -273,42 +276,10 @@ class _policyValidationState extends ConsumerState<policyValidation> {
setState(() { setState(() {
pdfUrl = "$url"; pdfUrl = "$url";
}); });
print("FINAL PDF URL -> $pdfUrl");
final response = await apiService.policyFilePathApi(
policyId,
'policy_pdf',
);
debugPrint('policyFilePathApi response: $response');
if (response != null && response['status'] == 'success') {
// final filePath = response['data']?.toString();
//
// // The API returns a server absolute path like:
// // /home3/.../uploads/policy/policy_pdf/yourfile.pdf
// // You must convert it to a usable URL for web/mobile.
//
// if (filePath != null && filePath.isNotEmpty) {
// // EXAMPLE:
// // Build full URL based on your domain
// // final baseUrl = filePath;
// final baseUrl = "https://venbait.in/nhance/mypdf.pdf";
//
// final fileName = filePath.split('/').last;
//
// setState(() {
// pdfUrl = "$baseUrl$fileName";
// });
//
// debugPrint("FINAL PDF URL -> $pdfUrl");
// }
} else {
debugPrint(
'policyFilePathApi returned error: ${response?['message'] ?? 'unknown'}',
);
}
} catch (e, st) { } catch (e, st) {
debugPrint('Exception in getPolicyFilePath: $e\n$st'); print('Exception in getPolicyFilePath: $e\n$st');
} finally { } finally {
if (!mounted) return; if (!mounted) return;
setState(() => isLoading = false); setState(() => isLoading = false);
@ -437,11 +408,24 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Future<void> _save() async { Future<void> _save() async {
final policyId = widget.item?['policy_id']; final policyId = widget.item?['policy_id'];
if (policyId == null) { if (policyId == null) {
ToastHelper.showWarningToast(context, 'Missing policy id'); ToastHelper.showWarningToast(context, 'Missing policy id');
return; return;
} }
if (!_formKey.currentState!.validate()) {
ToastHelper.showWarningToast(context, "Please fill all required fields");
return;
}
if (widget.item?['is_data_accuracy_checked'] == "1") {
ToastHelper.showWarningToast(context, "Data already confirmed");
return;
}
final payload = { final payload = {
"id": policyId, "id": policyId,
"rc_no": rcNoController.text, "rc_no": rcNoController.text,
@ -565,28 +549,53 @@ class _policyValidationState extends ConsumerState<policyValidation> {
TextInputType keyboardType = TextInputType.text, TextInputType keyboardType = TextInputType.text,
bool readOnly = false, bool readOnly = false,
VoidCallback? onTap, VoidCallback? onTap,
bool required = false,
List<TextInputFormatter>? inputFormatters, // 👈 ADD THIS
}) { }) {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(label, style: const TextStyle(fontWeight: FontWeight.w500)), Text(label, style: const TextStyle(fontWeight: FontWeight.w500)),
const SizedBox(height: 6), const SizedBox(height: 6),
TextField( TextFormField(
controller: controller, controller: controller,
keyboardType: keyboardType, keyboardType: keyboardType,
readOnly: readOnly, readOnly: readOnly,
onTap: onTap, onTap: onTap,
inputFormatters: inputFormatters, // 👈 USE HERE
validator: (value) {
if (required && (value == null || value.trim().isEmpty)) {
return "$label is required";
}
return null;
},
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: BorderRadius.circular(6)), border: OutlineInputBorder(borderRadius: BorderRadius.circular(6)),
isDense: true, isDense: true,
// alignment fix
helperText: ' ',
helperStyle: const TextStyle(height: 1),
errorMaxLines: 2,
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(6),
borderSide: const BorderSide(color: Colors.red),
),
contentPadding: const EdgeInsets.all(10), contentPadding: const EdgeInsets.all(10),
), ),
), ),
const SizedBox(height: 12),
], ],
); );
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Ensure global AppHeader remains visible by pushing content down by 64px // Ensure global AppHeader remains visible by pushing content down by 64px
@ -755,13 +764,14 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
flex: 1, flex: 1,
child: SingleChildScrollView( child: SingleChildScrollView(
child: Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Card( child: Card(
elevation: 2, elevation: 2,
color: Colors.white, color: Colors.white,
margin: EdgeInsets.zero, // flush with container margin: EdgeInsets.zero,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
borderRadius: BorderRadius.circular(8),
),
child: Padding( child: Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Column( child: Column(
@ -790,14 +800,14 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Policy Number', 'Policy Number',
policyNumberController, policyNumberController, required: true,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Insured Name', 'Insured Name',
insuredNameController, insuredNameController, required: true
), ),
), ),
], ],
@ -808,7 +818,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
child: _buildInput( child: _buildInput(
'Issued Date', 'Issued Date',
issuedDateController, issuedDateController,
readOnly: true, readOnly: true, required: true,
onTap: () => _pickDate( onTap: () => _pickDate(
issuedDateController, issuedDateController,
context, context,
@ -820,7 +830,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
child: _buildInput( child: _buildInput(
'Start Date', 'Start Date',
startDateController, startDateController,
readOnly: true, readOnly: true, required: true,
onTap: () => _pickDate( onTap: () => _pickDate(
startDateController, startDateController,
context, context,
@ -832,7 +842,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
child: _buildInput( child: _buildInput(
'End Date', 'End Date',
endDateController, endDateController,
readOnly: true, readOnly: true, required: true,
onTap: () => _pickDate( onTap: () => _pickDate(
endDateController, endDateController,
context, context,
@ -846,16 +856,16 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Premium Amount', 'Premium Amount',
premiumController, premiumController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Remarks', 'Remarks',
remarksController, remarksController,required: false
), ),
), ),
], ],
@ -890,27 +900,27 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'TP', 'TP',
tpController, tpController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'OD', 'OD',
odController, odController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'PA', 'PA',
paController, paController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
], ],
@ -920,27 +930,27 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'CGST', 'CGST',
cgstController, cgstController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'SGST', 'SGST',
sgstController, sgstController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'IGST', 'IGST',
igstController, igstController,required: true,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
], ],
@ -975,23 +985,25 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'RTO State Name', 'RTO State Name',
rtoStateCodeController, rtoStateCodeController,required: false,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'RTO City Code', 'RTO City Code',
rtoCityCodeController, rtoCityCodeController,required: false,
keyboardType: TextInputType.number,
inputFormatters: digitsOnlyFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Weight', 'Weight',
weightController, weightController,required: false,
keyboardType: keyboardType: TextInputType.number,
TextInputType.number, inputFormatters: digitsOnlyFormatter,
), ),
), ),
], ],
@ -1001,14 +1013,14 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Fuel Type', 'Fuel Type',
fuelTypeController, fuelTypeController,required: false,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Date of Registration', 'Date of Registration',
registrationDateController, registrationDateController,required: false,
readOnly: true, readOnly: true,
onTap: () => _pickDate( onTap: () => _pickDate(
registrationDateController, registrationDateController,
@ -1020,9 +1032,9 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Year of Manufacture', 'Year of Manufacture',
yomController, yomController,required: false,
keyboardType: keyboardType: TextInputType.number,
TextInputType.number, inputFormatters: digitsOnlyFormatter,
), ),
), ),
], ],
@ -1032,14 +1044,14 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Engine No', 'Engine No',
engineNoController, engineNoController,required: false,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Chassis No', 'Chassis No',
chassisNoController, chassisNoController,required: false,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
@ -1047,7 +1059,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
child: Expanded( child: Expanded(
child: _buildInput( child: _buildInput(
'Make', 'Make',
makeController, makeController,required: false,
), ),
), ),
), ),
@ -1058,23 +1070,23 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Model', 'Model',
modelController, modelController,required: false,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Cubic Capacity', 'Cubic Capacity',
cubicCapacityController, cubicCapacityController,required: false,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Vehicle Type', 'Vehicle Type',
vehicleTypeController, vehicleTypeController,required: false,
), ),
), ),
], ],
@ -1109,16 +1121,16 @@ class _policyValidationState extends ConsumerState<policyValidation> {
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Broker Name', 'Broker Name',
brokerNameController, brokerNameController,required: false,
), ),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded( Expanded(
child: _buildInput( child: _buildInput(
'Commission Amount', 'Commission Amount',
commissionAmountController, commissionAmountController,required: false,
keyboardType: keyboardType: TextInputType.numberWithOptions(decimal: true),
TextInputType.number, inputFormatters: decimalFormatter,
), ),
), ),
], ],
@ -1137,6 +1149,7 @@ class _policyValidationState extends ConsumerState<policyValidation> {
), ),
), ),
), ),
)
], ],
), ),
), ),

View File

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