From 7e9ea0134b79bf6442eee7c0594928091b5e0746 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 22 May 2025 12:26:23 +0000 Subject: [PATCH 1/3] validation in departments --- lib/Screens/department/departmentDetails.dart | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/lib/Screens/department/departmentDetails.dart b/lib/Screens/department/departmentDetails.dart index e887bca..43d57d3 100644 --- a/lib/Screens/department/departmentDetails.dart +++ b/lib/Screens/department/departmentDetails.dart @@ -34,8 +34,19 @@ class DepartmentData extends StatefulWidget { class DepartmentDataState extends State { final ApiService apiService = ApiService(); Map? apiData; - final Map controllers = {}; - Map errorMessages = {}; + + final Map controllers = { + "name": TextEditingController(), + "description": TextEditingController(), + }; + + final Map focusNodes = { + "name": FocusNode(), + "description": FocusNode(), + }; + + final Map errorMessages = {}; + String? selectedName; String? selectedDescription; String? userId; @@ -103,7 +114,6 @@ class DepartmentDataState extends State { } bool validateData() { - errorMessages.clear(); final data = { @@ -111,15 +121,17 @@ class DepartmentDataState extends State { "description": controllers["description"]?.text, }; - final requiredFields = [ - "name", - "description" - ]; + final requiredFields = ["name", "description"]; + bool hasFocused = false; - // Check validation for each field for (String field in requiredFields) { - if (data[field] == null || data[field].toString().trim().isEmpty) { + if (data[field] == null || data[field]!.trim().isEmpty) { errorMessages[field] = "Required"; + + if (!hasFocused) { + focusNodes[field]?.requestFocus(); + hasFocused = true; + } } } @@ -130,12 +142,14 @@ class DepartmentDataState extends State { print("inside submit"); userId = await getUserId(); - setState(() { - // This triggers UI rebuild with error messages - if (validateData()) { - postDepartmentData(); - } - }); + final isValid = validateData(); + setState(() {}); // <-- triggers UI update to show errors + + if (isValid) { + // Proceed to submit data + postDepartmentData(); + print("Submitting data: ${controllers["name"]?.text}"); + } final departmentData1 = departmentDetails(); print("submit data - $departmentData1"); @@ -147,7 +161,7 @@ class DepartmentDataState extends State { final departmentData = departmentDetails(); - print("initally value of the Department - $departmentData"); + print("initially value of the Department - $departmentData"); final String apiUrldata; @@ -160,7 +174,7 @@ class DepartmentDataState extends State { } else { print("for add Department id - null"); apiUrldata = '$apiUrl/api/createDepartment'; - print("called apiurl - $apiUrldata"); + print("called apiUrl - $apiUrldata"); departmentData["created_by"] = userId; } print("recently Department data - $departmentData"); @@ -223,7 +237,7 @@ class DepartmentDataState extends State { Row( children: [ Text( - 'Create Department', + (departmentDataId != null) ? 'Edit Department' : 'Create Department', style: GoogleFonts.poppins(fontSize: 15, color: Colors.black), ), const Spacer(), @@ -252,12 +266,14 @@ class DepartmentDataState extends State { isDesktop: widget.isDesktop, color: Colors.transparent, child: SizedBox( - height: 40, + height: 45, child: TextField( controller: controllers["name"], + focusNode: focusNodes["name"], style: const TextStyle(fontSize: 12), - decoration: const InputDecoration( + decoration: InputDecoration( labelText: "Department Name", + errorText: errorMessages["name"], labelStyle: TextStyle(fontSize: 11, color: Colors.grey), floatingLabelBehavior: FloatingLabelBehavior.never, border: InputBorder.none, @@ -292,15 +308,17 @@ class DepartmentDataState extends State { height: 100, child: TextField( controller: controllers["description"], - style: const TextStyle(fontSize: 11), + focusNode: focusNodes["description"], + style: const TextStyle(fontSize: 12), maxLines: null, // Allow infinite lines (textarea behavior) expands: true, // Expands to fill the parent height - decoration: const InputDecoration( + decoration: InputDecoration( labelText: "Description", + errorText: errorMessages["description"], labelStyle: TextStyle(fontSize: 11, color: Colors.grey), floatingLabelBehavior: FloatingLabelBehavior.never, border: InputBorder.none, - contentPadding: EdgeInsets.symmetric(vertical: 16, horizontal: 8), + contentPadding: EdgeInsets.symmetric(vertical: 16), ), ), ), From 157b329de1cdee9f605969916d8eea5e16bd6c4f Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 22 May 2025 13:01:12 +0000 Subject: [PATCH 2/3] validation in departments --- lib/Screens/department/departmentDetails.dart | 71 +++++++++++-------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/lib/Screens/department/departmentDetails.dart b/lib/Screens/department/departmentDetails.dart index 43d57d3..078e395 100644 --- a/lib/Screens/department/departmentDetails.dart +++ b/lib/Screens/department/departmentDetails.dart @@ -35,17 +35,13 @@ class DepartmentDataState extends State { final ApiService apiService = ApiService(); Map? apiData; - final Map controllers = { - "name": TextEditingController(), - "description": TextEditingController(), - }; - final Map focusNodes = { "name": FocusNode(), "description": FocusNode(), }; - final Map errorMessages = {}; + final Map controllers = {}; + Map errorMessages = {}; String? selectedName; String? selectedDescription; @@ -91,6 +87,14 @@ class DepartmentDataState extends State { }); } + @override + void dispose() { + for (var controller in controllers.values) { + controller.dispose(); + } + super.dispose(); + } + void updateDepartmentDetails() { print("Inside Update Function - ${widget.departmentData}"); @@ -124,6 +128,7 @@ class DepartmentDataState extends State { final requiredFields = ["name", "description"]; bool hasFocused = false; + // Check validation for each field for (String field in requiredFields) { if (data[field] == null || data[field]!.trim().isEmpty) { errorMessages[field] = "Required"; @@ -139,21 +144,17 @@ class DepartmentDataState extends State { } Future handleSubmit() async { - print("inside submit"); userId = await getUserId(); - final isValid = validateData(); - setState(() {}); // <-- triggers UI update to show errors - - if (isValid) { - // Proceed to submit data - postDepartmentData(); - print("Submitting data: ${controllers["name"]?.text}"); - } + setState(() { + // This triggers UI rebuild with error messages + if (validateData()) { + postDepartmentData(); + } + }); final departmentData1 = departmentDetails(); print("submit data - $departmentData1"); - } Future postDepartmentData({int isActive = 1}) async { @@ -260,28 +261,32 @@ class DepartmentDataState extends State { color: Color(0xFF575A74)), ), SizedBox(height: 5), - CustomTextFieldForexWrapper( isFocused: false, isDesktop: widget.isDesktop, color: Colors.transparent, child: SizedBox( - height: 45, + height: 40, child: TextField( controller: controllers["name"], focusNode: focusNodes["name"], style: const TextStyle(fontSize: 12), - decoration: InputDecoration( - labelText: "Department Name", - errorText: errorMessages["name"], + decoration: const InputDecoration( + labelText: "Name", labelStyle: TextStyle(fontSize: 11, color: Colors.grey), floatingLabelBehavior: FloatingLabelBehavior.never, border: InputBorder.none, contentPadding: EdgeInsets.symmetric(vertical: 16), ), - // validator: (val) => val == null || val.isEmpty ? 'Enter name' : null, )), ), + if (errorMessages["name"] != null) ...[ + SizedBox(height: 5), // Space before error message + Text( + errorMessages["name"]!, + style: TextStyle(color: Colors.red, fontSize: 12), + ), + ], ], ), SizedBox( @@ -293,10 +298,9 @@ class DepartmentDataState extends State { Text( "Description", style: GoogleFonts.poppins( - fontSize: 12, - fontWeight: FontWeight.w600, - color: Color(0xFF575A74), - ), + fontSize: 12, + fontWeight: FontWeight.w600, + color: Color(0xFF575A74)), ), SizedBox(height: 5), CustomTextFieldForexWrapper( @@ -304,17 +308,15 @@ class DepartmentDataState extends State { isDesktop: widget.isDesktop, color: Colors.transparent, child: SizedBox( - // Increase height for textarea height: 100, child: TextField( controller: controllers["description"], focusNode: focusNodes["description"], style: const TextStyle(fontSize: 12), - maxLines: null, // Allow infinite lines (textarea behavior) - expands: true, // Expands to fill the parent height - decoration: InputDecoration( + maxLines: null, + expands: true, + decoration: const InputDecoration( labelText: "Description", - errorText: errorMessages["description"], labelStyle: TextStyle(fontSize: 11, color: Colors.grey), floatingLabelBehavior: FloatingLabelBehavior.never, border: InputBorder.none, @@ -323,6 +325,13 @@ class DepartmentDataState extends State { ), ), ), + if (errorMessages["description"] != null) ...[ + SizedBox(height: 5), // Space before error message + Text( + errorMessages["description"]!, + style: TextStyle(color: Colors.red, fontSize: 12), + ), + ], ], ), SizedBox( From ca934a3a88a7f80cf3fccc9bb313ec58587503cb Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Fri, 23 May 2025 05:22:22 +0000 Subject: [PATCH 3/3] logo alignment --- lib/Screens/organization/orgSetup.dart | 7 ++++--- lib/routes/custom_appBar.dart | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/Screens/organization/orgSetup.dart b/lib/Screens/organization/orgSetup.dart index 7d189b5..2da5748 100644 --- a/lib/Screens/organization/orgSetup.dart +++ b/lib/Screens/organization/orgSetup.dart @@ -472,7 +472,7 @@ class _OrgSetUpState extends State { color: Colors.white, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, // now -> .center , old -> .start children: [ Padding( padding: const EdgeInsets.only(top: 1.0), @@ -523,8 +523,9 @@ class _OrgSetUpState extends State { ? ClipRect( child: Image.network( selectedOrg!['logo'], - width: 100, - height: 30, + width: 250, // increased + height: 75, // increased + fit: BoxFit.contain, errorBuilder: (context, error, stackTrace) { diff --git a/lib/routes/custom_appBar.dart b/lib/routes/custom_appBar.dart index 7d69ebb..1483a6c 100644 --- a/lib/routes/custom_appBar.dart +++ b/lib/routes/custom_appBar.dart @@ -227,12 +227,14 @@ class _CustomAppBarState extends State { // padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10), child: selectedOrg?['logo'] != null - ? ClipRect( + ? SizedBox( + height: 60, + child: ClipRect( child: Image.network( selectedOrg!['logo'], - width: 130, - height: 80, - // fit: BoxFit.contain, + width: 180, //130 + height: 90, //80 + fit: BoxFit.contain, errorBuilder: (context, error, stackTrace) { return const CircleAvatar( radius: 20, @@ -241,7 +243,7 @@ class _CustomAppBarState extends State { ); }, ), - ) + )) : const CircleAvatar( radius: 20, // backgroundColor: Colors.white,