From 7c9ec2310bba09813976f41b9feafd4b4ae731c4 Mon Sep 17 00:00:00 2001 From: venbaittech Date: Fri, 23 May 2025 14:52:28 +0530 Subject: [PATCH] org settings --- lib/Screens/allTrips/list_all_plans.dart | 53 ++++- lib/Screens/allTrips/travel_agent_list.dart | 53 ++++- lib/Screens/approvals/approval_list.dart | 69 +++++-- lib/Screens/forex/forexDetails.dart | 11 + lib/Screens/group/groupList.dart | 1 - lib/Screens/itnerary/accomodations.dart | 43 ++-- lib/Screens/itnerary/bus.dart | 2 +- lib/Screens/itnerary/flights.dart | 18 +- lib/Screens/itnerary/forex.dart | 20 +- lib/Screens/itnerary/insurance.dart | 31 +-- lib/Screens/itnerary/taxi.dart | 2 +- lib/Screens/itnerary/train.dart | 2 +- lib/Screens/itnerary/visa.dart | 10 +- .../itnerary_list/accomodation_list.dart | 56 ++++- lib/Screens/itnerary_list/bus_list.dart | 56 ++++- lib/Screens/itnerary_list/flight_list.dart | 56 ++++- lib/Screens/itnerary_list/forex_list.dart | 40 +++- lib/Screens/itnerary_list/insurance_list.dart | 12 +- lib/Screens/itnerary_list/taxi_list.dart | 56 ++++- lib/Screens/itnerary_list/train_list.dart | 56 ++++- lib/Screens/itnerary_list/visa_list.dart | 39 +++- lib/Screens/plans/create_plans.dart | 32 ++- lib/Screens/plans/list_plans.dart | 195 +++++++++++++++--- .../create_user/create_user.dart | 59 ++++-- .../create_user/office_details.dart | 19 +- .../create_user/personal_details.dart | 1 + .../create_user/traveller_details.dart | 1 + lib/app.dart | 6 +- lib/routes/custom_appBar.dart | 163 ++++----------- lib/routes/custom_router.dart | 5 + lib/routes/organizationSetting.dart | 184 +++++++++++++++++ lib/services/apiService.dart | 104 +++++++++- lib/widgets/popup_listPlan_action.dart | 3 +- 33 files changed, 1119 insertions(+), 339 deletions(-) create mode 100644 lib/routes/organizationSetting.dart diff --git a/lib/Screens/allTrips/list_all_plans.dart b/lib/Screens/allTrips/list_all_plans.dart index 1461a44..6e8c628 100644 --- a/lib/Screens/allTrips/list_all_plans.dart +++ b/lib/Screens/allTrips/list_all_plans.dart @@ -125,6 +125,21 @@ class _ListAllPlansState extends State { } } + void refresh() { + print("Refresj"); + setState(() { + futurePlans = fetchPlans(); + }); + + // Wait for futurePlans to be fetched and update allPlans + futurePlans.then((plans) { + setState(() { + allPlans = plans; // Set allPlans after the fetch is complete + filteredPlans = allPlans; // You can update filteredPlans too if needed + }); + }); + } + Future getUserId() async { final prefs = await SharedPreferences.getInstance(); final String? userDataString = prefs.getString('user_data'); @@ -231,13 +246,20 @@ class _ListAllPlansState extends State { } void deletePlan(String planId) async { - try { - Map planData = await ApiService.getViewPlan(planId); - print("ViewAAA - $planData"); + bool confirmed = + await apiService.showCancelConfirmationDialog(context, layoutColor); - postPlanData(planData, planId); - } catch (e) { - print("Error fetching plan: $e"); + if (confirmed) { + try { + Map planData = await ApiService.getViewPlan(planId); + print("ViewAAA - $planData"); + refresh(); + // postPlanData(planData, planId); + } catch (e) { + print("Error fetching plan: $e"); + } + } else { + print("User cancelled"); } } @@ -289,10 +311,20 @@ class _ListAllPlansState extends State { } Widget buildTableLayout(isDesktop) { + // String _formatDate(String rawDate) { + // try { + // final dateTime = DateTime.parse(rawDate); + // return DateFormat('dd, MMM yyyy hh:m a').format(dateTime); + // } catch (e) { + // return rawDate; // fallback if parsing fails + // } + // } + String _formatDate(String rawDate) { try { final dateTime = DateTime.parse(rawDate); - return DateFormat('dd, MMM yyyy hh:m a').format(dateTime); + return DateFormat('dd, MMM yyyy HH:mm') + .format(dateTime); // 24-hour format } catch (e) { return rawDate; // fallback if parsing fails } @@ -753,10 +785,9 @@ class _ListAllPlansState extends State { }, ), IconButton( - icon: Image.asset( - 'assets/images/IconsImg/delete.png', - width: 20, - height: 15), + icon: Icon( + Icons.cancel_rounded, + size: 18), onPressed: () { Navigator.pop(context); deletePlan(plan.planId); diff --git a/lib/Screens/allTrips/travel_agent_list.dart b/lib/Screens/allTrips/travel_agent_list.dart index 88de1bf..721efe8 100644 --- a/lib/Screens/allTrips/travel_agent_list.dart +++ b/lib/Screens/allTrips/travel_agent_list.dart @@ -124,6 +124,21 @@ class _TravelAgentListPlansState extends State { } } + void refresh() { + print("Refresj"); + setState(() { + futurePlans = fetchPlans(); + }); + + // Wait for futurePlans to be fetched and update allPlans + futurePlans.then((plans) { + setState(() { + allPlans = plans; // Set allPlans after the fetch is complete + filteredPlans = allPlans; // You can update filteredPlans too if needed + }); + }); + } + Future getUserId() async { final prefs = await SharedPreferences.getInstance(); final String? userDataString = prefs.getString('user_data'); @@ -224,13 +239,20 @@ class _TravelAgentListPlansState extends State { } void deletePlan(String planId) async { - try { - Map planData = await ApiService.getViewPlan(planId); - print("ViewAAA - $planData"); + bool confirmed = + await apiService.showCancelConfirmationDialog(context, layoutColor); - postPlanData(planData, planId); - } catch (e) { - print("Error fetching plan: $e"); + if (confirmed) { + try { + Map planData = await ApiService.getViewPlan(planId); + print("ViewAAA - $planData"); + refresh(); + // postPlanData(planData, planId); + } catch (e) { + print("Error fetching plan: $e"); + } + } else { + print("User cancelled"); } } @@ -279,10 +301,20 @@ class _TravelAgentListPlansState extends State { } Widget buildTableLayout(isDesktop) { + // String _formatDate(String rawDate) { + // try { + // final dateTime = DateTime.parse(rawDate); + // return DateFormat('dd,MMM yyyy hh:m a').format(dateTime); + // } catch (e) { + // return rawDate; // fallback if parsing fails + // } + // } + String _formatDate(String rawDate) { try { final dateTime = DateTime.parse(rawDate); - return DateFormat('dd,MMM yyyy hh:m a').format(dateTime); + return DateFormat('dd, MMM yyyy HH:mm') + .format(dateTime); // 24-hour format } catch (e) { return rawDate; // fallback if parsing fails } @@ -687,10 +719,9 @@ class _TravelAgentListPlansState extends State { }, ), IconButton( - icon: Image.asset( - 'assets/images/IconsImg/delete.png', - width: 20, - height: 15), + icon: Icon( + Icons.cancel_rounded, + size: 18), onPressed: () { Navigator.pop(context); deletePlan(plan.planId); diff --git a/lib/Screens/approvals/approval_list.dart b/lib/Screens/approvals/approval_list.dart index 54b8503..0cda2f5 100644 --- a/lib/Screens/approvals/approval_list.dart +++ b/lib/Screens/approvals/approval_list.dart @@ -109,6 +109,21 @@ class _ApprovalListState extends State { } } + void refresh() { + print("Refresj"); + setState(() { + futurePlans = fetchPlans(); + }); + + // Wait for futurePlans to be fetched and update allPlans + futurePlans.then((plans) { + setState(() { + allPlans = plans; // Set allPlans after the fetch is complete + filteredPlans = allPlans; // You can update filteredPlans too if needed + }); + }); + } + Future getUserId() async { final prefs = await SharedPreferences.getInstance(); final String? userDataString = prefs.getString('user_data'); @@ -215,13 +230,29 @@ class _ApprovalListState extends State { } void deletePlan(String planId) async { - try { - Map planData = await getViewPlan(planId); - print("ViewAAA - $planData"); + // try { + // Map planData = await getViewPlan(planId); + // print("ViewAAA - $planData"); + // + // postPlanData(planData, planId); + // } catch (e) { + // print("Error fetching plan: $e"); + // } - postPlanData(planData, planId); - } catch (e) { - print("Error fetching plan: $e"); + bool confirmed = + await apiService.showCancelConfirmationDialog(context, layoutColor); + + if (confirmed) { + try { + Map planData = await ApiService.getViewPlan(planId); + print("ViewAAA - $planData"); + refresh(); + // postPlanData(planData, planId); + } catch (e) { + print("Error fetching plan: $e"); + } + } else { + print("User cancelled"); } } @@ -342,10 +373,20 @@ class _ApprovalListState extends State { } Widget buildTableLayout(isDesktop) { + // String _formatDate(String rawDate) { + // try { + // final dateTime = DateTime.parse(rawDate); + // return DateFormat('dd, MMM yyyy hh:m a').format(dateTime); + // } catch (e) { + // return rawDate; // fallback if parsing fails + // } + // } + String _formatDate(String rawDate) { try { final dateTime = DateTime.parse(rawDate); - return DateFormat('dd, MMM yyyy hh:m a').format(dateTime); + return DateFormat('dd, MMM yyyy HH:mm') + .format(dateTime); // 24-hour format } catch (e) { return rawDate; // fallback if parsing fails } @@ -730,10 +771,9 @@ class _ApprovalListState extends State { }, ), IconButton( - icon: Image.asset( - 'assets/images/IconsImg/delete.png', - width: 20, - height: 15), + icon: Icon( + Icons.cancel_rounded, + size: 18), onPressed: () { Navigator.pop(context); deletePlan(plan.planId); @@ -924,10 +964,9 @@ class _ApprovalListState extends State { }, ), IconButton( - icon: Image.asset( - 'assets/images/IconsImg/delete.png', - width: 20, - height: 15), + icon: Icon( + Icons.cancel_rounded, + size: 18), onPressed: () { Navigator.pop(context); deletePlan(plan.planId); diff --git a/lib/Screens/forex/forexDetails.dart b/lib/Screens/forex/forexDetails.dart index 4c6ec99..0291648 100644 --- a/lib/Screens/forex/forexDetails.dart +++ b/lib/Screens/forex/forexDetails.dart @@ -245,6 +245,17 @@ class ForexDataState extends State { // dispose(); Navigator.of(context).pop(); + } else if (response.statusCode == 404) { + Navigator.of(context).pop(); + final message = jsonDecode(response.body)['message'] ?? 'Unknown error'; + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(message), + backgroundColor: Colors.redAccent, + behavior: SnackBarBehavior.floating, + ), + ); } else { print("Failed to submit plan. Status: ${response.statusCode}"); print("Error: ${response.body}"); diff --git a/lib/Screens/group/groupList.dart b/lib/Screens/group/groupList.dart index 97abbac..086387d 100644 --- a/lib/Screens/group/groupList.dart +++ b/lib/Screens/group/groupList.dart @@ -314,7 +314,6 @@ class _GroupListState extends State { child: Text( "Policy: ${group['domestic_policy_name'] ?? group['international_policy_name']}")), Expanded(child: Text("${group['description'] ?? 'N/A'}")), - Expanded(child: Text(" ${group['created_by']}")), ], ), Row( diff --git a/lib/Screens/itnerary/accomodations.dart b/lib/Screens/itnerary/accomodations.dart index b51bea4..2d085f1 100644 --- a/lib/Screens/itnerary/accomodations.dart +++ b/lib/Screens/itnerary/accomodations.dart @@ -152,17 +152,22 @@ class _AccomodationScreenState extends State { "flightfirstToDestinationNotifier: $flightFirstToDestinationNotifier.value "); // ✅ Only set controller after value is updated - final parsedDate = - DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + // final parsedDate = DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + final parsedDate = DateFormat("dd-MM-yyyy") + .parse(flightFirstTripDateNotifier.value ?? ''); if (parsedDate != null) { - _checkInController.text = DateFormat('yyyy-MM-dd').format(parsedDate); + _checkInController.text = DateFormat('dd-MM-yyyy').format(parsedDate); } - final parsedEndDate = - DateTime.tryParse(flightLastTripDateNotifier.value ?? ''); + // final parsedEndDate = DateTime.tryParse(flightLastTripDateNotifier.value ?? ''); + final parsedEndDate = DateFormat("dd-MM-yyyy") + .parse(flightLastTripDateNotifier.value ?? ''); + if (parsedEndDate != null) { + // _checkOutController.text = DateFormat('dd-MM-yyyy').format(parsedEndDate); + _checkOutController.text = - DateFormat('yyyy-MM-dd').format(parsedEndDate); + DateFormat('dd-MM-yyyy').format(parsedEndDate); } // ✅ Check and set default times if empty @@ -260,8 +265,13 @@ class _AccomodationScreenState extends State { checkIn.toString().isNotEmpty && checkOut.toString().isNotEmpty) { try { - final checkInDate = DateTime.parse(checkIn); - final checkOutDate = DateTime.parse(checkOut); + final format = DateFormat("dd-MM-yyyy"); + final formatTime = DateFormat("dd-MM-yyyy HH:mm"); + // final checkInDate = format.parse(checkIn); + // final checkOutDate = format.parse(checkOut); + + final checkInDate = format.parse("$checkIn"); + final checkOutDate = format.parse("$checkOut"); if (checkOutDate.isBefore(checkInDate)) { errorMessages["checkout_date"] = @@ -273,10 +283,9 @@ class _AccomodationScreenState extends State { checkInTime.toString().isNotEmpty && checkOutTime.toString().isNotEmpty) { try { - final checkInDateTime = - DateTime.parse("${checkIn}T${checkInTime}"); + final checkInDateTime = formatTime.parse("$checkIn $checkInTime"); final checkOutDateTime = - DateTime.parse("${checkOut}T${checkOutTime}"); + formatTime.parse("$checkOut $checkOutTime"); if (!checkOutDateTime.isAfter(checkInDateTime)) { errorMessages["checkout_time"] = @@ -563,7 +572,7 @@ class _AccomodationScreenState extends State { if (pickedDate != null && pickedDate != _selectedCheckInDate) { setState(() { _selectedCheckInDate = pickedDate; - _checkInController.text = DateFormat('yyyy-MM-dd').format(pickedDate); + _checkInController.text = DateFormat('dd-MM-yyyy').format(pickedDate); }); } } @@ -618,10 +627,14 @@ class _AccomodationScreenState extends State { Future _selectCheckOutDate(BuildContext context) async { DateTime now = DateTime.now(); DateTime today = DateTime(now.year, now.month, now.day); + final format = DateFormat("dd-MM-yyyy HH:mm"); + + // final prevDateTime = DateTime.parse("$prevDateStr $prevTimeStr"); + // final currDateTime = DateTime.parse("$currDateStr $currTimeStr"); DateTime? checkInDate; try { - checkInDate = DateTime.parse(_checkInController.text); + checkInDate = format.parse(_checkInController.text); } catch (e) { checkInDate = today; } @@ -650,7 +663,8 @@ class _AccomodationScreenState extends State { setState(() { _selectedCheckOutDate = pickedDate; _checkOutController.text = - DateFormat('yyyy-MM-dd').format(pickedDate); + DateFormat('dd-MM-yyyy').format(pickedDate); + errorMessages.remove("checkout_date"); }); } } @@ -671,6 +685,7 @@ class _AccomodationScreenState extends State { pickedTime.minute), ); _checkOutTimeController.text = formattedTime; + errorMessages.remove("checkout_time"); }); } } diff --git a/lib/Screens/itnerary/bus.dart b/lib/Screens/itnerary/bus.dart index 2ceaefe..6738e33 100644 --- a/lib/Screens/itnerary/bus.dart +++ b/lib/Screens/itnerary/bus.dart @@ -371,7 +371,7 @@ class _BusScreenState extends State { if (pickedDate != null && pickedDate != _selectedCheckOutDate) { setState(() { _selectedCheckOutDate = pickedDate; - _dateController.text = DateFormat('yyyy-MM-dd').format(pickedDate); + _dateController.text = DateFormat('dd-MM-yyyy').format(pickedDate); }); } } diff --git a/lib/Screens/itnerary/flights.dart b/lib/Screens/itnerary/flights.dart index faa86c1..b4ca591 100644 --- a/lib/Screens/itnerary/flights.dart +++ b/lib/Screens/itnerary/flights.dart @@ -521,6 +521,8 @@ class FlightScreenState extends State { String? currDateStr = textControllers["_date${index}Controller"]?.text; String? currTimeStr = textControllers["_time${index}Controller"]?.text; + print("prevDateTime - $prevTimeStr"); + print("currDateTime - $currTimeStr"); if (prevDateStr != null && prevDateStr.isNotEmpty && prevTimeStr != null && @@ -530,8 +532,13 @@ class FlightScreenState extends State { currTimeStr != null && currTimeStr.isNotEmpty) { try { - final prevDateTime = DateTime.parse("$prevDateStr $prevTimeStr"); - final currDateTime = DateTime.parse("$currDateStr $currTimeStr"); + final format = DateFormat("dd-MM-yyyy HH:mm"); + + // final prevDateTime = DateTime.parse("$prevDateStr $prevTimeStr"); + // final currDateTime = DateTime.parse("$currDateStr $currTimeStr"); + + final prevDateTime = format.parse("$prevDateStr $prevTimeStr"); + final currDateTime = format.parse("$currDateStr $currTimeStr"); if (!currDateTime.isAfter(prevDateTime)) { errorMessages["time_$index"] = "Must be after previous time"; @@ -542,6 +549,7 @@ class FlightScreenState extends State { errorMessages.remove("time_$index"); } } catch (e) { + print(" Invalid time format"); errorMessages["time_$index"] = "Invalid time format"; } } @@ -1112,7 +1120,7 @@ class FlightScreenState extends State { flightLastTripDateNotifier.value != null && flightLastTripDateNotifier.value!.isNotEmpty) { try { - final tripDate = DateFormat('yyyy-MM-dd') + final tripDate = DateFormat('dd-MM-yyyy') .parseStrict(flightLastTripDateNotifier.value!); if (tripDate.isAfter(today)) { firstDate = tripDate; @@ -1126,7 +1134,7 @@ class FlightScreenState extends State { if (previousDateString != null && previousDateString.isNotEmpty) { try { final previousDate = - DateFormat('yyyy-MM-dd').parseStrict(previousDateString); + DateFormat('dd-MM-yyyy').parseStrict(previousDateString); if (previousDate.isAfter(today)) { firstDate = previousDate; } @@ -1153,7 +1161,7 @@ class FlightScreenState extends State { _selectedCheckOutDate = pickedDate; // _dateController.text = DateFormat('yyyy-MM-dd').format(pickedDate); textControllers["_date${index}Controller"]?.text = - DateFormat('yyyy-MM-dd').format(pickedDate); + DateFormat('dd-MM-yyyy').format(pickedDate); }); } } diff --git a/lib/Screens/itnerary/forex.dart b/lib/Screens/itnerary/forex.dart index 3975a1a..c52ab0d 100644 --- a/lib/Screens/itnerary/forex.dart +++ b/lib/Screens/itnerary/forex.dart @@ -279,7 +279,7 @@ class _ForexScreenState extends State { DateTime? _parseDate(String date) { try { - return DateFormat("yyyy-MM-dd").parse(date); // Change format if needed + return DateFormat("dd-MM-yyyy").parse(date); // Change format if needed } catch (e) { return null; } @@ -331,18 +331,20 @@ class _ForexScreenState extends State { flightLastTripDateNotifier.value = result['lastTripDate']; // ✅ Only set controller after value is updated - final parsedDate = - DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + // final parsedDate = + // DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + final parsedDate = DateFormat("dd-MM-yyyy") + .parse(flightFirstTripDateNotifier.value ?? ''); if (parsedDate != null) { textControllers["_forexStartDate"]?.text = - DateFormat('yyyy-MM-dd').format(parsedDate); + DateFormat('dd-MM-yyyy').format(parsedDate); } - final parsedEndDate = - DateTime.tryParse(flightLastTripDateNotifier.value ?? ''); + final parsedEndDate = DateFormat("dd-MM-yyyy") + .parse(flightLastTripDateNotifier.value ?? ''); if (parsedEndDate != null) { textControllers["_forexEndDate"]?.text = - DateFormat('yyyy-MM-dd').format(parsedEndDate); + DateFormat('dd-MM-yyyy').format(parsedEndDate); } }); } @@ -766,7 +768,7 @@ class _ForexScreenState extends State { setState(() { _selectedCheckOutDate = pickedDate; textControllers["_forexStartDate"]?.text = - DateFormat('yyyy-MM-dd').format(pickedDate); + DateFormat('dd-MM-yyyy').format(pickedDate); }); } } @@ -816,7 +818,7 @@ class _ForexScreenState extends State { setState(() { _selectedEndDate = pickedDate; textControllers["_forexEndDate"]?.text = - DateFormat('yyyy-MM-dd').format(pickedDate); + DateFormat('dd-MM-yyyy').format(pickedDate); // textControllers["_forexEndDate"]?.text = // DateFormat('dd-MM-yyyy').format(initialDate); }); diff --git a/lib/Screens/itnerary/insurance.dart b/lib/Screens/itnerary/insurance.dart index dc91e89..d1a903c 100644 --- a/lib/Screens/itnerary/insurance.dart +++ b/lib/Screens/itnerary/insurance.dart @@ -121,17 +121,24 @@ class _InsuranceScreenState extends State { flightLastTripDateNotifier.value = result['lastTripDate']; // ✅ Only set controller after value is updated - final parsedDate = - DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + // final parsedDate = + // DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + final parsedDate = DateFormat("dd-MM-yyyy") + .parse(flightFirstTripDateNotifier.value ?? ''); if (parsedDate != null) { - _startdateController.text = DateFormat('yyyy-MM-dd').format(parsedDate); + _startdateController.text = DateFormat('dd-MM-yyyy').format(parsedDate); } - final parsedEndDate = - DateTime.tryParse(flightLastTripDateNotifier.value ?? ''); + final parsedEndDate = DateFormat("dd-MM-yyyy") + .parse(flightLastTripDateNotifier.value ?? ''); if (parsedEndDate != null) { _endDateController.text = - DateFormat('yyyy-MM-dd').format(parsedEndDate); + DateFormat('dd-MM-yyyy').format(parsedEndDate); + + print("parsedDate"); + print(parsedDate); + print("parsedEndDate"); + print(parsedEndDate); } }); } @@ -189,7 +196,7 @@ class _InsuranceScreenState extends State { errorMessages[field] = "Required"; } } - + final format = DateFormat("dd-MM-yyyy"); // Additional validation: checkout_date >= checkin_date final checkIn = data["start_date"]; final checkOut = data["end_date"]; @@ -199,8 +206,8 @@ class _InsuranceScreenState extends State { checkIn.toString().isNotEmpty && checkOut.toString().isNotEmpty) { try { - final checkInDate = DateTime.parse(checkIn); - final checkOutDate = DateTime.parse(checkOut); + final checkInDate = format.parse(checkIn); + final checkOutDate = format.parse(checkOut); if (checkOutDate.isBefore(checkInDate)) { errorMessages["end_date"] = "EndDate date cannot be before StartDate"; } @@ -230,7 +237,7 @@ class _InsuranceScreenState extends State { DateTime? _parseDate(String date) { try { - return DateFormat("yyyy-MM-dd").parse(date); // Change format if needed + return DateFormat("dd-MM-yyyy").parse(date); // Change format if needed } catch (e) { return null; } @@ -463,7 +470,7 @@ class _InsuranceScreenState extends State { setState(() { _selectedCheckOutDate = pickedDate; _startdateController.text = - DateFormat('yyyy-MM-dd').format(pickedDate); + DateFormat('dd-MM-yyyy').format(pickedDate); }); } } @@ -512,7 +519,7 @@ class _InsuranceScreenState extends State { if (pickedDate != null && pickedDate != _selectedCheckOutDate) { setState(() { _selectedCheckOutDate = pickedDate; - _endDateController.text = DateFormat('yyyy-MM-dd').format(pickedDate); + _endDateController.text = DateFormat('dd-MM-yyyy').format(pickedDate); }); } } diff --git a/lib/Screens/itnerary/taxi.dart b/lib/Screens/itnerary/taxi.dart index 2e22d8d..6549298 100644 --- a/lib/Screens/itnerary/taxi.dart +++ b/lib/Screens/itnerary/taxi.dart @@ -477,7 +477,7 @@ class _TaxiScreenState extends State { if (pickedDate != null && pickedDate != _selectedCheckOutDate) { setState(() { _selectedCheckOutDate = pickedDate; - _dateController.text = DateFormat('yyyy-MM-dd').format(pickedDate); + _dateController.text = DateFormat('dd-MM-yyyy').format(pickedDate); }); } } diff --git a/lib/Screens/itnerary/train.dart b/lib/Screens/itnerary/train.dart index 5bb5f40..e2ddd7d 100644 --- a/lib/Screens/itnerary/train.dart +++ b/lib/Screens/itnerary/train.dart @@ -466,7 +466,7 @@ class _TrainScreenState extends State { if (pickedDate != null && pickedDate != _selectedCheckOutDate) { setState(() { _selectedCheckOutDate = pickedDate; - _dateController.text = DateFormat('yyyy-MM-dd').format(pickedDate); + _dateController.text = DateFormat('dd-MM-yyyy').format(pickedDate); }); } } diff --git a/lib/Screens/itnerary/visa.dart b/lib/Screens/itnerary/visa.dart index eea08a4..b8de533 100644 --- a/lib/Screens/itnerary/visa.dart +++ b/lib/Screens/itnerary/visa.dart @@ -128,10 +128,12 @@ class _VisaScreenState extends State { flightLastTripDateNotifier.value = result['lastTripDate']; // ✅ Only set controller after value is updated - final parsedDate = - DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + // final parsedDate = + // DateTime.tryParse(flightFirstTripDateNotifier.value ?? ''); + final parsedDate = DateFormat("dd-MM-yyyy") + .parse(flightFirstTripDateNotifier.value ?? ''); if (parsedDate != null) { - _dateController.text = DateFormat('yyyy-MM-dd').format(parsedDate); + _dateController.text = DateFormat('dd-MM-yyyy').format(parsedDate); } }); } @@ -406,7 +408,7 @@ class _VisaScreenState extends State { if (pickedDate != null && pickedDate != _selectedCheckOutDate) { setState(() { _selectedCheckOutDate = pickedDate; - _dateController.text = DateFormat('yyyy-MM-dd').format(pickedDate); + _dateController.text = DateFormat('dd-MM-yyyy').format(pickedDate); }); } } diff --git a/lib/Screens/itnerary_list/accomodation_list.dart b/lib/Screens/itnerary_list/accomodation_list.dart index 1db208a..432e160 100644 --- a/lib/Screens/itnerary_list/accomodation_list.dart +++ b/lib/Screens/itnerary_list/accomodation_list.dart @@ -138,10 +138,19 @@ class AccomodationListWidget extends StatelessWidget { accommodationList.where((item) => item["is_active"] == "1").toList(); print("filteredList- $filteredList"); + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } + String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } @@ -150,20 +159,47 @@ class AccomodationListWidget extends StatelessWidget { String formatTime(String timeString) { try { final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + final now = DateTime.now(); - final dateTime = DateTime( - now.year, - now.month, - now.day, - int.parse(parts[0]), - int.parse(parts[1]), - ); - return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format } catch (e) { return "Invalid Time"; } } + // String formatTime(String timeString) { + // try { + // final parts = timeString.split(':'); + // final now = DateTime.now(); + // final dateTime = DateTime( + // now.year, + // now.month, + // now.day, + // int.parse(parts[0]), + // int.parse(parts[1]), + // ); + // return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + // } catch (e) { + // return "Invalid Time"; + // } + // } + return ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), diff --git a/lib/Screens/itnerary_list/bus_list.dart b/lib/Screens/itnerary_list/bus_list.dart index 4bdf283..4e20724 100644 --- a/lib/Screens/itnerary_list/bus_list.dart +++ b/lib/Screens/itnerary_list/bus_list.dart @@ -117,10 +117,36 @@ class BusListWidget extends StatelessWidget { busList.where((item) => item["is_active"] == "1").toList(); print("filteredList- $filteredList"); + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } + // + // String formatTime(String timeString) { + // try { + // final parts = timeString.split(':'); + // final now = DateTime.now(); + // final dateTime = DateTime( + // now.year, + // now.month, + // now.day, + // int.parse(parts[0]), + // int.parse(parts[1]), + // ); + // return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + // } catch (e) { + // return "Invalid Time"; + // } + // } + String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } @@ -129,15 +155,25 @@ class BusListWidget extends StatelessWidget { String formatTime(String timeString) { try { final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + final now = DateTime.now(); - final dateTime = DateTime( - now.year, - now.month, - now.day, - int.parse(parts[0]), - int.parse(parts[1]), - ); - return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format } catch (e) { return "Invalid Time"; } diff --git a/lib/Screens/itnerary_list/flight_list.dart b/lib/Screens/itnerary_list/flight_list.dart index 845ef9d..1c837d8 100644 --- a/lib/Screens/itnerary_list/flight_list.dart +++ b/lib/Screens/itnerary_list/flight_list.dart @@ -177,10 +177,36 @@ class _FlightListWidgetState extends State { .toString(); } + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } + // + // String formatTime(String timeString) { + // try { + // final parts = timeString.split(':'); + // final now = DateTime.now(); + // final dateTime = DateTime( + // now.year, + // now.month, + // now.day, + // int.parse(parts[0]), + // int.parse(parts[1]), + // ); + // return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + // } catch (e) { + // return "Invalid Time"; + // } + // } + String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } @@ -189,15 +215,25 @@ class _FlightListWidgetState extends State { String formatTime(String timeString) { try { final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + final now = DateTime.now(); - final dateTime = DateTime( - now.year, - now.month, - now.day, - int.parse(parts[0]), - int.parse(parts[1]), - ); - return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format } catch (e) { return "Invalid Time"; } diff --git a/lib/Screens/itnerary_list/forex_list.dart b/lib/Screens/itnerary_list/forex_list.dart index 04ab33d..3b826ed 100644 --- a/lib/Screens/itnerary_list/forex_list.dart +++ b/lib/Screens/itnerary_list/forex_list.dart @@ -171,15 +171,51 @@ class ForexListWidget extends StatelessWidget { .toString(); } + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } + String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } } + String formatTime(String timeString) { + try { + final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + + final now = DateTime.now(); + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format + } catch (e) { + return "Invalid Time"; + } + } + return ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), diff --git a/lib/Screens/itnerary_list/insurance_list.dart b/lib/Screens/itnerary_list/insurance_list.dart index 5b73362..e512edb 100644 --- a/lib/Screens/itnerary_list/insurance_list.dart +++ b/lib/Screens/itnerary_list/insurance_list.dart @@ -147,10 +147,18 @@ class InsuranceListWidget extends StatelessWidget { .toString(); } + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('dd MMMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } diff --git a/lib/Screens/itnerary_list/taxi_list.dart b/lib/Screens/itnerary_list/taxi_list.dart index 468912c..3f3d4b6 100644 --- a/lib/Screens/itnerary_list/taxi_list.dart +++ b/lib/Screens/itnerary_list/taxi_list.dart @@ -140,10 +140,36 @@ class TaxiListWidget extends StatelessWidget { .toString(); } + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } + // + // String formatTime(String timeString) { + // try { + // final parts = timeString.split(':'); + // final now = DateTime.now(); + // final dateTime = DateTime( + // now.year, + // now.month, + // now.day, + // int.parse(parts[0]), + // int.parse(parts[1]), + // ); + // return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + // } catch (e) { + // return "Invalid Time"; + // } + // } + String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } @@ -152,15 +178,25 @@ class TaxiListWidget extends StatelessWidget { String formatTime(String timeString) { try { final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + final now = DateTime.now(); - final dateTime = DateTime( - now.year, - now.month, - now.day, - int.parse(parts[0]), - int.parse(parts[1]), - ); - return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format } catch (e) { return "Invalid Time"; } diff --git a/lib/Screens/itnerary_list/train_list.dart b/lib/Screens/itnerary_list/train_list.dart index 01e53ed..cdacc3c 100644 --- a/lib/Screens/itnerary_list/train_list.dart +++ b/lib/Screens/itnerary_list/train_list.dart @@ -221,10 +221,36 @@ class _TrainListWidgetState extends State { .toString(); } + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } + // + // String formatTime(String timeString) { + // try { + // final parts = timeString.split(':'); + // final now = DateTime.now(); + // final dateTime = DateTime( + // now.year, + // now.month, + // now.day, + // int.parse(parts[0]), + // int.parse(parts[1]), + // ); + // return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + // } catch (e) { + // return "Invalid Time"; + // } + // } + String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } @@ -233,15 +259,25 @@ class _TrainListWidgetState extends State { String formatTime(String timeString) { try { final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + final now = DateTime.now(); - final dateTime = DateTime( - now.year, - now.month, - now.day, - int.parse(parts[0]), - int.parse(parts[1]), - ); - return DateFormat.jm().format(dateTime); // e.g., 12:16 PM or 12 AM + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format } catch (e) { return "Invalid Time"; } diff --git a/lib/Screens/itnerary_list/visa_list.dart b/lib/Screens/itnerary_list/visa_list.dart index 4a0aff9..cd7a441 100644 --- a/lib/Screens/itnerary_list/visa_list.dart +++ b/lib/Screens/itnerary_list/visa_list.dart @@ -212,15 +212,50 @@ class VisaListWidget extends StatelessWidget { .toString(); } + // String formatDate(String dateString) { + // try { + // DateTime date = DateTime.parse(dateString); + // return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + // } catch (e) { + // return "Invalid Date"; + // } + // } String formatDate(String dateString) { try { - DateTime date = DateTime.parse(dateString); - return DateFormat('d MMM yy').format(date); // Example: 4 Apr 25 + DateTime date = DateFormat("dd-MM-yyyy").parse(dateString); + return DateFormat('dd MMM yy').format(date); // Example: 23 May 25 } catch (e) { return "Invalid Date"; } } + String formatTime(String timeString) { + try { + final parts = timeString.split(':'); + int hour = int.parse(parts[0]); + int minute = int.parse(parts[1]); + + final now = DateTime.now(); + + DateTime dateTime; + + if (hour == 24 && minute == 0) { + // 24:00 is treated as 00:00 on the next day + dateTime = DateTime(now.year, now.month, now.day) + .add(const Duration(days: 1)); + } else { + if (hour < 0 || hour > 23 || minute < 0 || minute > 59) { + throw FormatException("Invalid hour or minute"); + } + dateTime = DateTime(now.year, now.month, now.day, hour, minute); + } + + return DateFormat('HH:mm').format(dateTime); // 24-hour format + } catch (e) { + return "Invalid Time"; + } + } + return ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), diff --git a/lib/Screens/plans/create_plans.dart b/lib/Screens/plans/create_plans.dart index 2baac1c..69fb7e1 100644 --- a/lib/Screens/plans/create_plans.dart +++ b/lib/Screens/plans/create_plans.dart @@ -232,7 +232,20 @@ class _CreatePlansState extends State { padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12), ), onPressed: () { - isApprover ? context.go('/approvallist') : context.go('/listPlan'); + final currentUri = GoRouterState.of(context) + .uri + .toString(); // ✅ safer than `.location` + print("currentUri - $currentUri"); + + if (currentUri == "/allTrips/trips") { + context.go('/listAllPlan'); + } else if (currentUri == "/createPlan") { + context.go('/listPlan'); + } else { + isApprover + ? context.go('/approvallist') + : context.go('/listPlan'); + } }, child: Text("Cancel")), SizedBox( @@ -1091,9 +1104,20 @@ class CreateNewPlansState extends State { // " "); postPlanData(planData); - widget.isApprover - ? context.go('/approvallist') - : context.go('/listPlan'); + final currentUri = GoRouterState.of(context) + .uri + .toString(); // ✅ safer than `.location` + print("currentUri - $currentUri"); + + if (currentUri == "/allTrips/trips") { + context.go('/listAllPlan'); + } else if (currentUri == "/createPlan") { + context.go('/listPlan'); + } else { + widget.isApprover + ? context.go('/approvallist') + : context.go('/listPlan'); + } } }); } diff --git a/lib/Screens/plans/list_plans.dart b/lib/Screens/plans/list_plans.dart index 38bd712..67b6a32 100644 --- a/lib/Screens/plans/list_plans.dart +++ b/lib/Screens/plans/list_plans.dart @@ -49,7 +49,6 @@ class _ListPlansState extends State { void initState() { super.initState(); - super.initState(); // futurePlans = fetchPlans(); // // futurePlans.then((plans) { @@ -78,6 +77,21 @@ class _ListPlansState extends State { // futurePlans = fetchPlans(); } + void refresh() { + print("Refresj"); + setState(() { + futurePlans = fetchPlans(); + }); + + // Wait for futurePlans to be fetched and update allPlans + futurePlans.then((plans) { + setState(() { + allPlans = plans; // Set allPlans after the fetch is complete + filteredPlans = allPlans; // You can update filteredPlans too if needed + }); + }); + } + void filterPlans(String query) { print("allPlans before filtering: $allPlans"); final lowerQuery = query.toLowerCase(); @@ -276,13 +290,29 @@ class _ListPlansState extends State { // } void deletePlan(String planId) async { - try { - Map planData = await ApiService.getViewPlan(planId); - print("ViewAAA - $planData"); + // try { + // Map planData = await ApiService.getViewPlan(planId); + // print("ViewAAA - $planData"); + // + // postPlanData(planData, planId); + // } catch (e) { + // print("Error fetching plan: $e"); + // } - postPlanData(planData, planId); - } catch (e) { - print("Error fetching plan: $e"); + bool confirmed = + await apiService.showCancelConfirmationDialog(context, layoutColor); + + if (confirmed) { + try { + Map planData = await ApiService.getViewPlan(planId); + print("ViewAAA - $planData"); + refresh(); + // postPlanData(planData, planId); + } catch (e) { + print("Error fetching plan: $e"); + } + } else { + print("User cancelled"); } } @@ -331,10 +361,20 @@ class _ListPlansState extends State { } Widget buildTableLayout(isDesktop) { + // String _formatDate(String rawDate) { + // try { + // final dateTime = DateTime.parse(rawDate); + // return DateFormat('dd, MMM yyyy hh:m a').format(dateTime); + // } catch (e) { + // return rawDate; // fallback if parsing fails + // } + // } + String _formatDate(String rawDate) { try { final dateTime = DateTime.parse(rawDate); - return DateFormat('dd, MMM yyyy hh:m a').format(dateTime); + return DateFormat('dd, MMM yyyy HH:mm') + .format(dateTime); // 24-hour format } catch (e) { return rawDate; // fallback if parsing fails } @@ -796,24 +836,27 @@ class _ListPlansState extends State { isMyTrips: true); }, ), + if (plan.statusValue == + "Pending Approval" || + plan.statusValue == + "Partially Approved") + IconButton( + icon: Image.asset( + 'assets/images/IconsImg/edit.png', + width: 20, + height: 15), + onPressed: () { + Navigator.pop(context); + ApiService.viewPlan( + context, plan.planId, + isViewMode: false, + isMyTrips: true); + }, + ), IconButton( - icon: Image.asset( - 'assets/images/IconsImg/edit.png', - width: 20, - height: 15), - onPressed: () { - Navigator.pop(context); - ApiService.viewPlan( - context, plan.planId, - isViewMode: false, - isMyTrips: true); - }, - ), - IconButton( - icon: Image.asset( - 'assets/images/IconsImg/delete.png', - width: 20, - height: 15), + icon: Icon( + Icons.cancel_rounded, + size: 18), onPressed: () { Navigator.pop(context); deletePlan(plan.planId); @@ -953,11 +996,103 @@ class _ListPlansState extends State { ), ), ), - PlanPopupMenu( - plan: plan, - deletePlan: deletePlan, - apiService: apiService, - layoutColor: layoutColor, + // PlanPopupMenu( + // plan: plan, + // deletePlan: deletePlan, + // apiService: apiService, + // layoutColor: layoutColor, + // ), + PopupMenuButton( + color: Colors.white, + padding: EdgeInsets.zero, + offset: Offset(0, 30), + icon: Icon(Icons.more_vert, + size: 14, color: Color(0xFF475569)), + itemBuilder: (context) => [ + CustomPopupMenuEntry( + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 8, vertical: 8), + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + IconButton( + icon: Icon( + Icons.remove_red_eye, + color: Color(0xFF475569), + size: 18), + onPressed: () { + Navigator.pop( + context); // Close popup manually + ApiService.viewPlan( + context, plan.planId, + isViewMode: true, + isMyTrips: true); + }, + ), + if (plan.statusValue == + "Pending Approval" || + plan.statusValue == + "Partially Approved") + IconButton( + icon: Image.asset( + 'assets/images/IconsImg/edit.png', + width: 20, + height: 15), + onPressed: () { + Navigator.pop(context); + ApiService.viewPlan( + context, plan.planId, + isViewMode: false, + isMyTrips: true); + }, + ), + IconButton( + icon: Icon( + Icons.cancel_rounded, + size: 18), + onPressed: () { + Navigator.pop(context); + deletePlan(plan.planId); + }, + ), + IconButton( + icon: Icon(Icons.download, + color: Color(0xFF114D8B), + size: 18), + onPressed: () { + Navigator.pop(context); + apiService.getPdfDownload( + plan.planId); + }, + ), + IconButton( + icon: const Icon( + Icons.comment, + color: Color(0xFF475569), + size: 11, + ), + onPressed: () { + showDialog( + context: context, + builder: (context) => + CommentModalList( + // planId: plan.planId, + planId: plan + .planId + .toString(), + layoutColorForUser: + layoutColor!, + role: "User"), + ); + }), + ], + ), + ), + ), + ], ), ], ), diff --git a/lib/Screens/userManagement/create_user/create_user.dart b/lib/Screens/userManagement/create_user/create_user.dart index e13dfc8..86bad75 100644 --- a/lib/Screens/userManagement/create_user/create_user.dart +++ b/lib/Screens/userManagement/create_user/create_user.dart @@ -115,9 +115,9 @@ class _CreateUserFormDetialsState extends State { "address", "postalCode", "country", - "passportNumber", - "placeOfIssue", - "passportDoc", + // "passportNumber", + // "placeOfIssue", + // "passportDoc", "userType", "roleId", "deptId", @@ -128,8 +128,8 @@ class _CreateUserFormDetialsState extends State { "employeeCode", "delegationStartDate", "delegationEndDate", - "dateOfIssue", - "dateOfExpiry", + // "dateOfIssue", + // "dateOfExpiry", "changePassword" ]; @@ -166,12 +166,12 @@ class _CreateUserFormDetialsState extends State { "second_approver": selectedSecondApprover, "third_approver": selectedThirdApprover, "delegated_to_user_id": selectedSubstituteApprover, - "passport_number": controllers["passportNumber"]?.text, - "place_of_issue": controllers["placeOfIssue"]?.text, - "passport_document": passportFile, + // "passport_number": controllers["passportNumber"]?.text, + // "place_of_issue": controllers["placeOfIssue"]?.text, + // "passport_document": passportFile, - "date_of_issue": controllers["dateOfIssue"]?.text, - "date_of_expiry": controllers["dateOfExpiry"]?.text, + // "date_of_issue": controllers["dateOfIssue"]?.text, + // "date_of_expiry": controllers["dateOfExpiry"]?.text, "created_by": userId, "is_active": "1", "org_id": orgId, @@ -725,23 +725,38 @@ class _CreateUserFormDetialsState extends State { request.fields['user_id'] = apiselectedUser!["user_id"].toString(); } - // Add all non-null and non-empty user data fields // userData.forEach((key, value) { - // if (value != null && value.toString().trim().isNotEmpty) { - // request.fields[key] = value.toString(); + // // if (value == null) { + // // // skip nulls + // // return; + // // } + // + // if (key == 'travel_details' && value is Map) { + // // Encode travel_details map as JSON string + // request.fields[key] = jsonEncode(value); + // print("✅ Encoded travel_details: ${request.fields[key]}"); + // } else { + // // If the value is empty or only whitespace, add it as empty string + // if (value.toString().trim().isEmpty) { + // request.fields[key] = ''; + // } else { + // // Otherwise add the actual string value + // request.fields[key] = value.toString(); + // } // } // }); userData.forEach((key, value) { - if (value != null && value.toString().trim().isNotEmpty) { - if (key == 'travel_details' && value is Map) { - // ✅ Encode travel_details as a proper JSON string - request.fields[key] = jsonEncode(value); - print("✅ Encoded travel_details: ${request.fields[key]}"); - } else { - request.fields[key] = value.toString(); - } + // if (value != null && value.toString().trim().isNotEmpty) { + if (key == 'travel_details' && value is Map) { + // ✅ Encode travel_details as a proper JSON string + request.fields[key] = jsonEncode(value); + + print("✅ Encoded travel_details: ${request.fields[key]}"); + } else { + request.fields[key] = value.toString(); } + // } }); // Attach file if selected @@ -1031,6 +1046,8 @@ class _CreateUserFormDetialsState extends State { onFirstSubsApproverChanged: (role) { setState(() { selectedSubstituteApprover = role; + + print("onFirstSubsApproverChanged - $selectedSubstituteApprover"); }); }, ); diff --git a/lib/Screens/userManagement/create_user/office_details.dart b/lib/Screens/userManagement/create_user/office_details.dart index c37df69..2ca78e3 100644 --- a/lib/Screens/userManagement/create_user/office_details.dart +++ b/lib/Screens/userManagement/create_user/office_details.dart @@ -96,7 +96,8 @@ class _OfficeDetailsState extends State { Uint8List? passportDocumentBytes; String? passportFileUrlFromApi; String? base64PDF; - + DateTime? _selectedCheckOutDate; + DateTime? _selectedEndDate; html.File? passportFile; List dataHeader = [ @@ -169,7 +170,16 @@ class _OfficeDetailsState extends State { void handleReset() { setState(() { - isResetTrue = true; + selectedSubstituteApprover = null; + widget.onFirstSubsApproverChanged?.call(null); // Notify parent if needed + + // Clear date selections and fields + _selectedCheckOutDate = null; + _selectedEndDate = null; + + widget.controllers["delegationStartDate"]?.text = ""; + widget.controllers["delegationEndDate"]?.text = ""; + // selectedSubstituteApprover = null; // widget.onFirstSubsApproverChanged?.call(null); // widget.controllers["delegationStartDate"]?.clear(); @@ -1051,9 +1061,6 @@ class _OfficeDetailsState extends State { } Widget buildDelegationStartDateField(bool isDesktop) { - DateTime? _selectedCheckOutDate; - DateTime? _selectedEndDate; - Future _selectCheckOutDate(BuildContext context) async { DateTime now = DateTime.now(); DateTime today = DateTime(now.year, now.month, now.day); @@ -1150,7 +1157,7 @@ class _OfficeDetailsState extends State { } Widget buildDelegationEndDateField(bool isDesktop) { - DateTime? _selectedEndDate; + // DateTime? _selectedEndDate; Future _selectForexEndDate(BuildContext context) async { DateTime now = DateTime.now(); DateTime today = DateTime(now.year, now.month, now.day); diff --git a/lib/Screens/userManagement/create_user/personal_details.dart b/lib/Screens/userManagement/create_user/personal_details.dart index dc0bac0..cb525ff 100644 --- a/lib/Screens/userManagement/create_user/personal_details.dart +++ b/lib/Screens/userManagement/create_user/personal_details.dart @@ -237,6 +237,7 @@ class PersonalDetailsState extends State { @override Widget build(BuildContext context) { return Container( + height: MediaQuery.of(context).size.height, decoration: BoxDecoration( border: Border( top: BorderSide( diff --git a/lib/Screens/userManagement/create_user/traveller_details.dart b/lib/Screens/userManagement/create_user/traveller_details.dart index 3aa7021..3d4a880 100644 --- a/lib/Screens/userManagement/create_user/traveller_details.dart +++ b/lib/Screens/userManagement/create_user/traveller_details.dart @@ -662,6 +662,7 @@ class TravellerDetailsState extends State { @override Widget build(BuildContext context) { return Container( + height: MediaQuery.of(context).size.height, decoration: BoxDecoration( border: Border( top: BorderSide( diff --git a/lib/app.dart b/lib/app.dart index 9c54b77..9a41869 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -46,17 +46,19 @@ class _MyAppState extends State { SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here if (kIsWeb) { final uri = Uri.parse(html.window.location.href); - if (uri.path == '/tstat/authredirection' && + if (uri.path == '/authredirection' && uri.queryParameters['code'] != null) { _authCode = uri.queryParameters['code']; // _isAuthRedirect = true; - + html.window.console.log("Auth code detected: $_authCode"); // print(">>> _isAuthRedirect: $_isAuthRedirect"); print(">>> Auth code found at startup: $_authCode"); WidgetsBinding.instance.addPostFrameCallback((_) { handleTokenUsingMS(_authCode); }); + } else { + html.window.console.log("No auth code found or wrong path."); } } } diff --git a/lib/routes/custom_appBar.dart b/lib/routes/custom_appBar.dart index 7d69ebb..ad0b3ad 100644 --- a/lib/routes/custom_appBar.dart +++ b/lib/routes/custom_appBar.dart @@ -271,10 +271,8 @@ class _CustomAppBarState extends State { icon: Icons.format_list_bulleted_rounded, // icon: Icons.insights_outlined, ), - if (userDetails["role"] != "Travel Agent") const SizedBox(width: 20), - if (userData?["role"] == "Travel Agent") buildNavItem( "Trips", @@ -286,7 +284,6 @@ class _CustomAppBarState extends State { icon: Icons.shopping_bag_outlined, // icon: Icons.request_page_outlined, ), - if (userData?["role"] != "Travel Agent") // for others buildNavItem( "My Trips", @@ -297,18 +294,6 @@ class _CustomAppBarState extends State { isSelected: selectedTab == TabSelection.myTrips, icon: Icons.shopping_bag_outlined, ), - // if (userDetails["role"] == "Travel Agent") - // buildNavItem("My Trips", _myTravelRequestColor, - // () => context.go('/listTravelAgentPlan'), - // isSelected: selectedTab == "My Trips"), - // ...[ - // const SizedBox(width: 20), - // buildNavItem("My Trips", _myTravelRequestColor, - // () => context.go('/listPlan'), - // isSelected: selectedTab == "My Trips"), - // ], - // - const SizedBox(width: 20), if (userData?["role"] != "Travel Agent") buildNavItem( @@ -321,23 +306,6 @@ class _CustomAppBarState extends State { isSelected: selectedTab == TabSelection.myApprovals, icon: Icons.verified_outlined, ), - - // buildNavItem("My Approvals", _myApprovalsColor, () { - // isSelected: - // selectedTab == "My Approvals", - // context.go('/ApprovalList'), - // icon:Icons.insights_outlined; - // }) - - // if (userData?["role"] == "Travel Agent") { - // isSelected: - // selectedTab == "My Approvals"; - // context.go('/listTravelAgentPlan'); - // } else { - // isSelected: - // selectedTab == "My Approvals"; - // context.go('/ApprovalList'); - // } ], ), ), @@ -359,26 +327,29 @@ class _CustomAppBarState extends State { offset: const Offset(0, 50), // 👈 shift it 50 pixels down onSelected: (String value) { switch (value) { - case '/OrganizationSetup': - context.go('/OrganizationSetup'); + case '/OrganizationSettings': + context.go('/OrganizationSettings'); break; + // case '/OrganizationSetup': + // context.go('/OrganizationSetup'); + // break; case '/listUser': context.go('/listUser'); break; - case '/group': - context.go('/group'); - break; - case '/department': - context.go('/department'); - break; - case '/PolicyList': - context.go('/PolicyList'); - case '/getPerdiem': - context.go('/getPerdiem'); - case '/templateList': - context.go('/templateList'); - case '/template': - context.go('/template'); + // case '/group': + // context.go('/group'); + // break; + // case '/department': + // context.go('/department'); + // break; + // case '/PolicyList': + // context.go('/PolicyList'); + // case '/getPerdiem': + // context.go('/getPerdiem'); + // case '/templateList': + // context.go('/templateList'); + // case '/template': + // context.go('/template'); case '/CreateUserDetails': context.go( "/CreateUserDetails", @@ -441,18 +412,6 @@ class _CustomAppBarState extends State { ]; }, - // itemBuilder: (BuildContext context) { - // final isUser = userData?["role"] == "User"; - // final filteredItems = isUser - // ? menuItems - // .where((item) => - // item['value'] == '/CreateUserDetails' || - // item['value'] == '/logout') - // .toList() - // : menuItems; - // - // return filteredItems.map(buildMenuItem).toList(); - // }, child: MouseRegion( cursor: SystemMouseCursors.click, child: Row( @@ -503,26 +462,31 @@ class _CustomAppBarState extends State { } final List> menuItems = [ + // { + // 'value': '/OrganizationSetup', + // 'icon': Icons.business, + // 'label': 'Organization' + // }, { - 'value': '/OrganizationSetup', + 'value': '/OrganizationSettings', 'icon': Icons.business, - 'label': 'Organization' + 'label': 'Org Management' }, { 'value': '/listUser', 'icon': Icons.manage_accounts, 'label': 'User Management' }, - {'value': '/group', 'icon': Icons.group, 'label': 'Group'}, - {'value': '/department', 'icon': Icons.group, 'label': 'Department'}, - {'value': '/PolicyList', 'icon': Icons.policy, 'label': 'Policy'}, - {'value': '/getPerdiem', 'icon': Icons.ac_unit_sharp, 'label': 'Forex'}, - { - 'value': '/templateList', - 'icon': Icons.ac_unit_sharp, - 'label': 'Template List' - }, - {'value': '/template', 'icon': Icons.ac_unit_sharp, 'label': 'Template'}, + // {'value': '/group', 'icon': Icons.group, 'label': 'Group'}, + // {'value': '/department', 'icon': Icons.group, 'label': 'Department'}, + // {'value': '/PolicyList', 'icon': Icons.policy, 'label': 'Policy'}, + // {'value': '/getPerdiem', 'icon': Icons.ac_unit_sharp, 'label': 'Forex'}, + // { + // 'value': '/templateList', + // 'icon': Icons.ac_unit_sharp, + // 'label': 'Template List' + // }, + // {'value': '/template', 'icon': Icons.ac_unit_sharp, 'label': 'Template'}, { 'value': '/CreateUserDetails', 'icon': Icons.account_circle, @@ -607,58 +571,3 @@ Widget buildNavItem(String label, VoidCallback onTap, Color? layoutColor, ), ); } - -Widget buildNavItem1(String label, VoidCallback onTap, - {bool isSelected = true, IconData? icon}) { - return MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - onTap: onTap, - child: Container( - padding: EdgeInsets.only(bottom: 2), - decoration: isSelected - ? BoxDecoration( - border: Border( - bottom: BorderSide( - width: 2, // underline thickness - color: Colors.red), - ), - ) - : null, // no underline when not selected - child: Row( - children: [ - if (icon != null) - Icon( - icon, - size: 16, - color: isSelected ? Colors.red : Colors.black, - // color: Colors.red, - ), - if (icon != null) SizedBox(width: 4), - Text( - label, - style: GoogleFonts.poppins( - fontSize: 12, - fontWeight: FontWeight.w500, - color: isSelected ? Colors.red : Colors.black, - // color: Colors.red, - ), - ), - - // Red underline positioned below (e.g. under green line) - if (isSelected) - Positioned( - bottom: -50, // adjust this to push it below green line - left: 0, - right: 0, - child: Container( - height: 2, - color: Colors.red, - ), - ), - ], - ), - ), - ), - ); -} diff --git a/lib/routes/custom_router.dart b/lib/routes/custom_router.dart index 7d74693..8ab3eb3 100644 --- a/lib/routes/custom_router.dart +++ b/lib/routes/custom_router.dart @@ -14,6 +14,7 @@ import 'package:frontend/Screens/policy/policy.dart'; import 'package:frontend/Screens/policy/policy_list.dart'; import 'package:frontend/Screens/userManagement/create_user/create_user1.dart'; import 'package:frontend/Screens/userManagement/user_List.dart'; +import 'package:frontend/routes/organizationSetting.dart'; import 'package:go_router/go_router.dart'; import '../Screens/allTrips/list_all_plans.dart'; @@ -102,6 +103,10 @@ final GoRouter router = GoRouter( path: '/OrganizationSetup', builder: (context, state) => OrgSetUp(), ), + GoRoute( + path: '/OrganizationSettings', + builder: (context, state) => OrganizationSetting(), + ), GoRoute( path: '/group', builder: (context, state) => GroupList(), diff --git a/lib/routes/organizationSetting.dart b/lib/routes/organizationSetting.dart new file mode 100644 index 0000000..2c6807f --- /dev/null +++ b/lib/routes/organizationSetting.dart @@ -0,0 +1,184 @@ +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:responsive_builder/responsive_builder.dart'; + +import 'custom_appBar.dart'; +import 'custom_drawer.dart'; + +class OrganizationSetting extends StatefulWidget { + const OrganizationSetting({super.key}); + + @override + OrganizationSettingState createState() => OrganizationSettingState(); +} + +class OrganizationSettingState extends State { + @override + Widget build(BuildContext context) { + return ResponsiveBuilder(builder: (context, sizingInfo) { + bool isDesktop = sizingInfo.deviceScreenType == DeviceScreenType.desktop; + + return Scaffold( + backgroundColor: Color(0xFFf5f5f5), + // backgroundColor: Color(0xFFFCFCFC), + + // appBar: isDesktop ? null : const CustomAppBar(title: 'Home'), + // drawer: isDesktop ? null : CustomDrawer(isDesktop: false), + appBar: CustomAppBar(isDesktop: isDesktop), + drawer: CustomDrawer(isDesktop: false), + body: Padding( + padding: isDesktop + ? EdgeInsets.symmetric( + horizontal: MediaQuery.of(context).size.width * + 0.1, // 30% of screen width as horizontal padding + vertical: MediaQuery.of(context).size.height * + 0, // 5% of screen height as vertical padding + ) + : EdgeInsets.all(0), + child: Row( + children: [ + // if (isDesktop) CustomDrawer(isDesktop: true), + Expanded(child: buildGroupListLayout(isDesktop)) + ], + ), + ), + ); + }); + } + + Widget buildGroupListLayout(bool isDesktop) { + final int cardsPerRow = 3; + + final List> menuItems = [ + { + 'value': '/OrganizationSetup', + 'icon': Icons.business, + 'label': 'Organization Settings', + 'description': 'Edit Logo and Email Configurations' + }, + { + 'value': '/group', + 'icon': Icons.groups, + 'label': 'Groups', + 'description': 'Create and Edit Groups' + }, + { + 'value': '/PolicyList', + 'icon': Icons.policy, + 'label': 'Travel Policies', + 'description': 'Create and Edit Travel Policy' + }, + { + 'value': '/department', + 'icon': Icons.group_add_outlined, + 'label': 'Departments', + 'description': 'Create and Edit Department' + }, + { + 'value': '/getPerdiem', + 'icon': Icons.attach_money, + 'label': 'Perdiem Amount', + 'description': 'Create and Edit Perdiem Amount' + }, + { + 'value': '/templateList', + 'icon': Icons.email_outlined, + 'label': 'Email Templates', + 'description': ' Edit Email Template' + }, + ]; + + List rows = []; + for (int i = 0; i < menuItems.length; i += cardsPerRow) { + List cards = []; + for (int j = i; j < i + cardsPerRow && j < menuItems.length; j++) { + final item = menuItems[j]; + + cards.add( + Expanded( + child: Card( + margin: EdgeInsets.all(8), + color: Colors.white, + child: InkWell( + onTap: () { + // Navigate using go_router + final route = item['value'] as String; + switch (route) { + case '/OrganizationSetup': + case '/group': + case '/department': + case '/PolicyList': + case '/getPerdiem': + case '/templateList': + context.go(route); + break; + default: + // Handle unknown routes or do nothing + print('Unknown route: $route'); + } + }, + child: Padding( + padding: EdgeInsets.all(12), + child: Row( + children: [ + Icon(item['icon'], size: 40, color: Color(0xFF114D8B)), + SizedBox(width: 16), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + item['label'], + style: GoogleFonts.poppins( + fontSize: 14, fontWeight: FontWeight.w500), + ), + SizedBox(height: 4), + Text( + item['description'], + style: TextStyle( + fontSize: 14, color: Colors.grey[700]), + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + ); + } + + rows.add(Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: cards, + )); + } + + return Container( + // color: Colors.white, + padding: EdgeInsets.symmetric(vertical: 16, horizontal: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Organization Settings', + style: GoogleFonts.poppins( + fontSize: 15, + fontWeight: FontWeight.w500, + color: Colors.black87, + ), + ), + SizedBox(height: 8), + Divider(thickness: 0.2, color: Colors.blueGrey.shade100), + SizedBox(height: 12), + ...rows, // Spread operator to insert all row widgets + ], + ), + ); + } +} diff --git a/lib/services/apiService.dart b/lib/services/apiService.dart index 42a1c45..2640fd3 100644 --- a/lib/services/apiService.dart +++ b/lib/services/apiService.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:frontend/utils/auth_utils.dart'; import 'package:go_router/go_router.dart'; +import 'package:google_fonts/google_fonts.dart'; import 'package:http/http.dart' as http; import 'package:universal_html/html.dart' as html; import 'package:universal_html/js.dart'; @@ -423,6 +424,32 @@ class ApiService { } static Future> getViewPlan(String planId) async { + final String apiUrldata = '$apiUrl/api/plans/cancle_plan?plan_id=$planId'; + + // final String apiUrldata = '$apiUrl/api/plans/find/$planId'; + print("API URL: $apiUrldata"); + // final token = await getToken(); + + final token = await getToken(); + + final response = await http.get( + Uri.parse(apiUrldata), + headers: { + 'Authorization': 'Bearer $token', // Add token here + 'Content-Type': 'application/json', + }, + ); + + if (response.statusCode == 200) { + final Map? resData = json.decode(response.body); + + return resData?["data"]; + } else { + throw Exception('Failed to load plans'); + } + } + + static Future> getViewPlanEdit(String planId) async { final String apiUrldata = '$apiUrl/api/plans/find/$planId'; print("API URL: $apiUrldata"); // final token = await getToken(); @@ -449,7 +476,7 @@ class ApiService { static Future viewPlan(BuildContext context, String planId, {bool isViewMode = false, bool isMyTrips = false}) async { try { - Map planData = await getViewPlan(planId); + Map planData = await getViewPlanEdit(planId); print("ViewAAA - $planData"); context.go(isMyTrips ? '/createPlan' : '/allTrips/trips', @@ -462,7 +489,7 @@ class ApiService { static Future viewPlanForApprover(BuildContext context, String planId, {bool isViewMode = false, bool isApprover = true}) async { try { - Map planData = await getViewPlan(planId); + Map planData = await getViewPlanEdit(planId); print("ViewAAA - $planData"); context.replace('/createPlan', extra: { @@ -840,16 +867,18 @@ class ApiService { // print(data); if (!data.containsKey('data') || data['data'] is! List) { - throw Exception("Invalid response format: 'data' field is missing or not a List"); + throw Exception( + "Invalid response format: 'data' field is missing or not a List"); } - final List> listData = List>.from(data['data']); + final List> listData = + List>.from(data['data']); if (listData.isEmpty) { throw Exception("No department found with ID $id"); } - return listData[0]; + return listData[0]; } catch (e) { throw Exception('Error parsing response: $e'); } @@ -858,5 +887,68 @@ class ApiService { } } - + Future showCancelConfirmationDialog( + BuildContext context, Color? layoutColor) async { + return await showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + backgroundColor: Colors.white, + title: Text( + 'Cancel Confirmation', + style: GoogleFonts.poppins( + fontSize: 18, fontWeight: FontWeight.w500), + ), + content: Text( + 'Do you want to cancel?', + style: GoogleFonts.poppins( + fontSize: 14.5, fontWeight: FontWeight.w500), + ), + actions: [ + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + foregroundColor: layoutColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: layoutColor ?? Colors.grey, width: 2), + ), + padding: + EdgeInsets.symmetric(horizontal: 20, vertical: 12), + ), + onPressed: () { + Navigator.of(context).pop(false); + }, + child: Text( + "Cancel", + style: GoogleFonts.poppins(fontSize: 12), + )), + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: layoutColor, // Keep original color + foregroundColor: Colors.white, // Keep original color + disabledBackgroundColor: + layoutColor, // Ensure color remains when disabled + disabledForegroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: BorderSide( + color: layoutColor ?? Colors.grey, width: 1), + ), + padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12), + ), + onPressed: () => Navigator.of(context) + .pop(true), // Disable when in view mode + child: Text( + "OK", + style: GoogleFonts.poppins(fontSize: 12), + ), + ), + ], + ); + }, + ) ?? + false; // Default to false if dismissed + } } diff --git a/lib/widgets/popup_listPlan_action.dart b/lib/widgets/popup_listPlan_action.dart index c721c5f..16a6f7f 100644 --- a/lib/widgets/popup_listPlan_action.dart +++ b/lib/widgets/popup_listPlan_action.dart @@ -61,8 +61,7 @@ class PlanPopupMenu extends StatelessWidget { }, ), IconButton( - icon: Image.asset('assets/images/IconsImg/delete.png', - width: 20, height: 15), + icon: Icon(Icons.cancel_rounded, size: 18), onPressed: () { Navigator.pop(context); deletePlan(plan.planId);