diff --git a/lib/Screens/plans/create_plans.dart b/lib/Screens/plans/create_plans.dart index 1070859..254389c 100644 --- a/lib/Screens/plans/create_plans.dart +++ b/lib/Screens/plans/create_plans.dart @@ -423,6 +423,7 @@ class CreateNewPlansState extends State { bool hasAction = true; bool hasSoNumber = false; bool hasExceptionalClass = false; + bool hasExceptionalClassInUpdate = false; late Map costCenterMap; List costCenterIds = []; @@ -587,6 +588,9 @@ class CreateNewPlansState extends State { fetchCostCenter(); fetchCountryList(); + print("hasExceptionalClass - $hasExceptionalClass"); + print("hasExceptionalClassInUpdate - $hasExceptionalClassInUpdate"); + // _tripTitleFocusNode.addListener(() { // setState(() { // _isTripTitleFocused = _tripTitleFocusNode.hasFocus; @@ -678,8 +682,11 @@ class CreateNewPlansState extends State { _excepntldescriptionController.text = widget.selectedPlanData['exceptional_plan_reason'] ?? ''; - if (_excepntldescriptionController.text != "") { - hasExceptionalClass = true; + if (_excepntldescriptionController.text != "" && + _excepntldescriptionController.text != null) { + hasExceptionalClassInUpdate = true; + print("hasExceptionalClass1 - $hasExceptionalClass"); + print("hasExceptionalClassInUpdate1 - $hasExceptionalClassInUpdate"); } _selectedTripType = widget.selectedPlanData['trip_type']; @@ -1166,9 +1173,9 @@ class CreateNewPlansState extends State { "cost_center_id": selectedCostCenterId, "functional_department": selectedFuncDept, "purpose_of_travel": selectedPurpose, + if (hasExceptionalClass) "exceptional_plan_reason": _excepntldescriptionController.text, - if (hasSoNumber) "so_number": _soNumberController.text, }; print("validateForm.....3"); @@ -1337,8 +1344,12 @@ class CreateNewPlansState extends State { setState(() { hasExceptionalClass = exceptionalCount >= 1; + if (hasExceptionalClass && + _excepntldescriptionController.text.trim().isEmpty) { + _showExceptionalReasonModal(context); + } if (!hasExceptionalClass) { - _excepntldescriptionController.text = ''; + _excepntldescriptionController.text = ""; } }); @@ -1774,7 +1785,10 @@ class CreateNewPlansState extends State { // _buildDescriptionColumn(isDesktop), SizedBox(width: 25), - if (hasExceptionalClass) _buildNonDescriptionColumn(), + + if (hasExceptionalClassInUpdate || + _excepntldescriptionController.text != "") + _buildNonDescriptionColumn(), ], ) : Column( @@ -1782,7 +1796,8 @@ class CreateNewPlansState extends State { children: [ _buildDescriptionColumn(isDesktop), SizedBox(height: 15), - if (hasExceptionalClass) _buildNonDescriptionColumn(), + if (hasExceptionalClassInUpdate) + _buildNonDescriptionColumn(), ], ), @@ -3396,6 +3411,105 @@ class CreateNewPlansState extends State { ]; } + void _showExceptionalReasonModal(BuildContext context) { + showDialog( + context: context, + barrierDismissible: false, // prevent closing by tapping outside + builder: (context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + child: Container( + padding: const EdgeInsets.all(16), + // decoration: BoxDecoration( + // border: Border.all( + // color: Colors.grey, // or any color you prefer + // width: 1.0, + // ), + // borderRadius: BorderRadius.circular(10), + // ), + color: Colors.white, + width: 400, + // width: MediaQuery.of(context).size.width * 0.5, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "Reason for travel policy exception", + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + const SizedBox(height: 16), + TextField( + controller: _excepntldescriptionController, + maxLines: 3, + decoration: InputDecoration( + hintText: "Enter reason...", + hintStyle: GoogleFonts.poppins(fontSize: 10), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular( + 10, + ), // 👈 Rounded border + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: BorderSide(color: layoutColor!), // optional + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10), + borderSide: BorderSide(color: layoutColor!), // optional + ), + ), + ), + const SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); // Cancel + }, + child: Text( + "Cancel", + style: GoogleFonts.poppins(fontSize: 12), + ), + ), + const SizedBox(width: 8), + ElevatedButton( + onPressed: () { + // Use the entered text + String reason = + _excepntldescriptionController.text.trim(); + if (reason.isNotEmpty) { + print("Reason entered: $reason"); + setState(() { + hasExceptionalClassInUpdate = true; + validationErrors.remove("exceptional_plan_reason"); + }); + + Navigator.of(context).pop(); // Close dialog + } else { + // Optional: show a validation message + } + }, + child: Text( + "OK", + style: GoogleFonts.poppins(fontSize: 12), + ), + ), + ], + ), + ], + ), + ), + ); + }, + ); + } + Widget _buildNonDescriptionColumn() { return Column( children: [ @@ -3430,6 +3544,9 @@ class CreateNewPlansState extends State { controller: _excepntldescriptionController, maxLines: 2, keyboardType: TextInputType.multiline, + onChanged: (value) { + validationErrors.remove("exceptional_plan_reason"); + }, style: TextStyle(fontSize: 12), enabled: !widget.isViewMode, decoration: InputDecoration( diff --git a/lib/app.dart b/lib/app.dart index 10dfed7..5760d4f 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; +// import 'package:flutter/rendering.dart'; import 'dart:html' as html; import 'package:frontend/config/apiUrl.dart'; // 1 newly added import 'package:frontend/services/apiService.dart'; @@ -31,7 +31,7 @@ class _MyAppState extends State { @override void initState() { super.initState(); - SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here + // SemanticsBinding.instance.ensureSemantics(); // ✅ Safe here if (kIsWeb) { final uri = Uri.parse(html.window.location.href); print("URI - $uri");