Travel Policy

This commit is contained in:
venbaittech 2025-05-29 20:00:56 +05:30
parent dbe248195d
commit 057da00078
4 changed files with 125 additions and 32 deletions

View File

@ -0,0 +1,36 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required String title}) : super(key: key);
@override
MyHomePageState createState() => MyHomePageState();
}
class MyHomePageState extends State<MyHomePage> {
QuillController _controller = QuillController.basic();
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20),
child: Column(
children: [
Text("data"),
QuillSimpleToolbar(
controller: _controller,
config: const QuillSimpleToolbarConfig(),
),
Expanded(
child: QuillEditor.basic(
controller: _controller,
config: const QuillEditorConfig(),
),
),
],
),
);
}
}

View File

@ -311,7 +311,7 @@ class _PolicyState extends State<Policy> {
print("Services - $services");
print("USR Detail Submit - $policyData");
policyCriteriaKey.currentState?.saveCurrentPolicy();
policyCriteriaKey.currentState?.saveCurrentPolicy(services);
// Now the full data is ready in policyDataFromChild
print("Submitting full policyData: $policyData");
@ -1006,6 +1006,7 @@ class _PolicyState extends State<Policy> {
children: services.asMap().entries.map((entry) {
int index = entry.key + 1;
String service = entry.value;
String serviceId = index.toString();
bool isSelected = selectedServiceIndex.value == index.toString();
return SizedBox(
@ -1022,11 +1023,18 @@ class _PolicyState extends State<Policy> {
selectedServiceIndex.value = index.toString();
selectedService = service;
print(
" selectedServiceIndex.value - ${selectedServiceIndex.value}");
// policyCriteriaKey.currentState?.fieldForPolicy();
// policyCriteriaKey.currentState
// ?.addOrUpdatePolicy(selectedServiceIndex.value);
if (selectedService == "Flight" ||
selectedService == "Train") {
showClass = true;
showCost = true;
int serviceCode = selectedService == "Flight" ? 1 : 2;
policyCriteriaKey.currentState?.fetchTrainFlightClass();
} else if (selectedService == "Accommodation") {
showClass = true;

View File

@ -87,6 +87,7 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
void initState() {
super.initState();
fieldForPolicy();
widget.selectedTabNotifier.addListener(() {
print("selectedTab changed: ${widget.selectedTabNotifier.value}");
fieldForPolicy();
@ -99,11 +100,57 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
userId = await getUserId();
}
void saveCurrentPolicy() {
// void saveCurrentPolicy(List<Map<String, dynamic>> services) {
// print("saveCurrentPolicy- $services");
// if (ServiceId != null) {
// print("Saving curremt Add or Update");
// addOrUpdatePolicy(ServiceId!);
// }
// }
void saveCurrentPolicy(List<Map<String, dynamic>> services) {
print("saveCurrentPolicy- $services");
// Step 1: Save currently selected policy first (if not already saved)
if (ServiceId != null) {
print("Saving curremt Add or Update");
print("Saving current Add or Update");
addOrUpdatePolicy(ServiceId!);
}
// Step 2: Collect existing service_ids from policyData
final existingServiceIds =
policyData?.map((e) => e['service_id'].toString()).toSet();
// Step 3: Loop through all service definitions
for (var service in services) {
String id = service['service_id'].toString();
// Skip if already present
if (existingServiceIds!.contains(id)) continue;
// Step 4: Initialize any missing controllers or data
costController.putIfAbsent(id, () => TextEditingController());
classAction.putIfAbsent(id, () => "1");
FirstApproverAction.putIfAbsent(id, () => "None");
SecondApproverAction.putIfAbsent(id, () => "None");
ThirdApproverAction.putIfAbsent(id, () => "None");
SelectedParallelProcess.putIfAbsent(id, () => "3");
// Step 5: Add default policy entry
policyData?.add({
"service_id": int.parse(id),
"cost": "",
"class": classAction[id],
"a1_action": FirstApproverAction[id],
"a2_action": SecondApproverAction[id],
"a3_action": ThirdApproverAction[id],
"parallel_process_from": SelectedParallelProcess[id],
"created_by": widget.userId,
});
}
// Step 6: Emit updated policy data
widget.onPolicyDataChanged(policyData);
}
// To set the data (update)
@ -148,6 +195,7 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
}
void addOrUpdatePolicy(String serviceId) {
print("addOrUpdatePolicyserviceId - $serviceId");
// 1. First, find existing item if any
final existingIndex =
policyData!.indexWhere((item) => item["service_id"] == serviceId);
@ -297,6 +345,7 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
// Save current input to policyData before switching
if (ServiceId != null) {
print("Calling addOrUpdatePolicy");
addOrUpdatePolicy(
ServiceId!); // 👈 Save current values for existing service
}
@ -304,12 +353,12 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
ServiceId = widget.selectedTabNotifier.value ?? "1";
// Initialize controllers and variables if not present
costController.putIfAbsent(ServiceId!, () => TextEditingController());
classAction.putIfAbsent(ServiceId!, () => null);
classAction.putIfAbsent(ServiceId!, () => "1");
// classController.putIfAbsent(ServiceId!, () => TextEditingController());
FirstApproverAction.putIfAbsent(ServiceId!, () => null);
SecondApproverAction.putIfAbsent(ServiceId!, () => null);
ThirdApproverAction.putIfAbsent(ServiceId!, () => null);
FirstApproverAction.putIfAbsent(ServiceId!, () => "None");
SecondApproverAction.putIfAbsent(ServiceId!, () => "None");
ThirdApproverAction.putIfAbsent(ServiceId!, () => "None");
SelectedParallelProcess.putIfAbsent(ServiceId!, () => "3");
});

View File

@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: "0c64e928dcbefddecd234205422bcfc2b5e6d31be0b86fef0d0dd48d7b4c9742"
sha256: "2fde1607386ab523f7a36bb3e7edb43bd58e6edaf2ffb29d8a6d578b297fdbbd"
url: "https://pub.dev"
source: hosted
version: "4.0.4"
version: "4.0.7"
args:
dependency: transitive
description:
@ -149,10 +149,10 @@ packages:
dependency: transitive
description:
name: ffi
sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6"
sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
version: "2.1.4"
file:
dependency: transitive
description:
@ -165,10 +165,10 @@ packages:
dependency: "direct main"
description:
name: file_picker
sha256: "36a1652d99cb6bf8ccc8b9f43aded1fd60b234d23ce78af422c07f950a436ef7"
sha256: "77f8e81d22d2a07d0dee2c62e1dda71dc1da73bf43bb2d45af09727406167964"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
version: "10.1.9"
file_selector_linux:
dependency: transitive
description:
@ -181,10 +181,10 @@ packages:
dependency: transitive
description:
name: file_selector_macos
sha256: "271ab9986df0c135d45c3cdb6bd0faa5db6f4976d3e4b437cf7d0f258d941bfc"
sha256: "8c9250b2bd2d8d4268e39c82543bacbaca0fda7d29e0728c3c4bbb7c820fd711"
url: "https://pub.dev"
source: hosted
version: "0.9.4+2"
version: "0.9.4+3"
file_selector_platform_interface:
dependency: transitive
description:
@ -279,10 +279,10 @@ packages:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "5a1e6fb2c0561958d7e4c33574674bda7b77caaca7a33b758876956f2902eea3"
sha256: f948e346c12f8d5480d2825e03de228d0eb8c3a737e4cdaa122267b89c022b5e
url: "https://pub.dev"
source: hosted
version: "2.0.27"
version: "2.0.28"
flutter_quill:
dependency: "direct main"
description:
@ -353,10 +353,10 @@ packages:
dependency: "direct main"
description:
name: http
sha256: fe7ab022b76f3034adc518fb6ea04a82387620e19977665ea18d30a1cf43442f
sha256: "2c11f3f94c687ee9bad77c171151672986360b2b001d109814ee7140b2cf261b"
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.4.0"
http_parser:
dependency: "direct main"
description:
@ -377,10 +377,10 @@ packages:
dependency: transitive
description:
name: image_picker_android
sha256: "8bd392ba8b0c8957a157ae0dc9fcf48c58e6c20908d5880aea1d79734df090e9"
sha256: "317a5d961cec5b34e777b9252393f2afbd23084aa6e60fcf601dcf6341b9ebeb"
url: "https://pub.dev"
source: hosted
version: "0.8.12+22"
version: "0.8.12+23"
image_picker_for_web:
dependency: transitive
description:
@ -617,18 +617,18 @@ packages:
dependency: transitive
description:
name: posix
sha256: a0117dc2167805aa9125b82eee515cc891819bac2f538c83646d355b16f58b9a
sha256: f0d7856b6ca1887cfa6d1d394056a296ae33489db914e365e2044fdada449e62
url: "https://pub.dev"
source: hosted
version: "6.0.1"
version: "6.0.2"
provider:
dependency: transitive
description:
name: provider
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
sha256: "4abbd070a04e9ddc287673bf5a030c7ca8b685ff70218720abab8b092f53dd84"
url: "https://pub.dev"
source: hosted
version: "6.1.2"
version: "6.1.5"
quill_native_bridge:
dependency: transitive
description:
@ -729,10 +729,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_android
sha256: "3ec7210872c4ba945e3244982918e502fa2bfb5230dff6832459ca0e1879b7ad"
sha256: "20cbd561f743a342c76c151d6ddb93a9ce6005751e7aa458baad3858bfbfb6ac"
url: "https://pub.dev"
source: hosted
version: "2.4.8"
version: "2.4.10"
shared_preferences_foundation:
dependency: transitive
description:
@ -942,10 +942,10 @@ packages:
dependency: transitive
description:
name: video_player_android
sha256: "28dcc4122079f40f93a0965b3679aff1a5f4251cf79611bd8011f937eb6b69de"
sha256: "4a5135754a62dbc827a64a42ef1f8ed72c962e191c97e2d48744225c2b9ebb73"
url: "https://pub.dev"
source: hosted
version: "2.8.4"
version: "2.8.7"
video_player_avfoundation:
dependency: transitive
description:
@ -990,10 +990,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: dc6ecaa00a7c708e5b4d10ee7bec8c270e9276dfcab1783f57e9962d7884305f
sha256: "329edf97fdd893e0f1e3b9e88d6a0e627128cc17cc316a8d67fda8f1451178ba"
url: "https://pub.dev"
source: hosted
version: "5.12.0"
version: "5.13.0"
xdg_directories:
dependency: transitive
description:
@ -1004,4 +1004,4 @@ packages:
version: "1.1.0"
sdks:
dart: ">=3.7.0 <4.0.0"
flutter: ">=3.27.0"
flutter: ">=3.29.0"