From ecc4dc9371410aefc40a63bfa30a716c7410ddf5 Mon Sep 17 00:00:00 2001 From: Venba Date: Sat, 20 Jul 2024 13:49:33 +0530 Subject: [PATCH] CHANGE_ --- lib/empDetails.dart | 125 +++++++++++++++++++++++++-------------- lib/empReview.dart | 63 ++++++++++++++++++++ lib/hrPolicyDetails.dart | 19 ++++-- pubspec.yaml | 2 + 4 files changed, 158 insertions(+), 51 deletions(-) diff --git a/lib/empDetails.dart b/lib/empDetails.dart index 3818a65..e37fd97 100644 --- a/lib/empDetails.dart +++ b/lib/empDetails.dart @@ -497,54 +497,81 @@ class _empDetailsState extends State { Future _selectDate(BuildContext context, formType) async { print(formType); var ageValidation = formType['age_validation']; - int min = - int.parse(ageValidation['min']); // Parsing the string to an integer - int max = - int.parse(ageValidation['max']); // Parsing the string to an integer - print(min); - print(max); - late DateTime minDate; - late DateTime maxDate; + print(ageValidation); + // Ensure ageValidation is a Map and contains the expected values + if (ageValidation is Map) { + int min = ageValidation.containsKey('min') + ? int.tryParse(ageValidation['min'].toString()) ?? 0 + : 0; + int max = ageValidation.containsKey('max') + ? int.tryParse(ageValidation['max'].toString()) ?? 100 + : 100; - final DateTime now = DateTime.now(); + print('Min age: $min'); + print('Max age: $max'); + late DateTime minDate; + late DateTime maxDate; - maxDate = DateTime(now.year - min, now.month, now.day); - print(maxDate); - minDate = DateTime(now.year - max, now.month, now.day); - print(minDate); + final DateTime now = DateTime.now(); - // if (formType['form_type'] == 'child') { - // // For 'child' form type, allow 0-25 age - // minDate = DateTime(now.year - 25, now.month, now.day); - // maxDate = now; - // } else { - // // For other form types, allow 18-100 age - // minDate = DateTime(1900); - // maxDate = DateTime(now.year - 18, now.month, now.day); - // } + maxDate = DateTime(now.year - min, now.month, now.day); + print(maxDate); + minDate = DateTime(now.year - max, now.month, now.day); + print(minDate); - // Ensure initialDate is within the range of minDate and maxDate - DateTime initialDate = - _selectedDate ?? maxDate; // Use maxDate if _selectedDate is null - initialDate = initialDate.isBefore(minDate) ? minDate : initialDate; - initialDate = initialDate.isAfter(maxDate) ? maxDate : initialDate; + // if (formType['form_type'] == 'child') { + // // For 'child' form type, allow 0-25 age + // minDate = DateTime(now.year - 25, now.month, now.day); + // maxDate = now; + // } else { + // // For other form types, allow 18-100 age + // minDate = DateTime(1900); + // maxDate = DateTime(now.year - 18, now.month, now.day); + // } - final DateTime? picked = await showDatePicker( - context: context, - initialDate: initialDate, - firstDate: minDate, - lastDate: maxDate, - selectableDayPredicate: (DateTime date) { - return date.isAfter(minDate.subtract(const Duration(days: 1))) && - date.isBefore(maxDate.add(const Duration(days: 1))); - }, - ); + // Ensure initialDate is within the range of minDate and maxDate + DateTime initialDate = + _selectedDate ?? maxDate; // Use maxDate if _selectedDate is null + initialDate = initialDate.isBefore(minDate) ? minDate : initialDate; + initialDate = initialDate.isAfter(maxDate) ? maxDate : initialDate; - if (picked != null && picked != _selectedDate) { - setState(() { - _selectedDate = picked; - _dobController.text = DateFormat('dd-MM-yyyy').format(_selectedDate); - }); + final DateTime? picked = await showDatePicker( + context: context, + initialDate: initialDate, + firstDate: minDate, + lastDate: maxDate, + selectableDayPredicate: (DateTime date) { + return date.isAfter(minDate.subtract(const Duration(days: 1))) && + date.isBefore(maxDate.add(const Duration(days: 1))); + }, + builder: (BuildContext context, Widget? child) { + return Theme( + data: ThemeData.light().copyWith( + primaryColor: Color(0xFFE26728), // Header background color + colorScheme: ColorScheme.light( + primary: Color(0xFFE26728), secondary: Color(0xFFE26728)), + buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.primary), + // dialogBackgroundColor: + // Colors.white, // Background color of the dialog + iconTheme: IconThemeData(color: Color(0xFFE26728)), + textButtonTheme: TextButtonThemeData( + style: TextButton.styleFrom( + foregroundColor: Color(0xFFE26728)), // Button color + ), + ), + child: child!, + ); + }, + ); + + if (picked != null && picked != _selectedDate) { + setState(() { + _selectedDate = picked; + _dobController.text = DateFormat('dd-MM-yyyy').format(_selectedDate); + }); + } + } else { + print('Invalid age validation data'); } } @@ -1314,6 +1341,13 @@ class _empDetailsState extends State { ) .toList(); + // Set the dropdown value based on the form_type + String? dropdownValue; + if (floaterData['form_type'] == 'spouse') { + dropdownValue = 'Spouse'; + _relationShipController.text = 'Spouse'; + } + print(selectedRelationships); print(gmcMappedFamilyFloaters); if (action == 'Add') { @@ -1418,9 +1452,10 @@ class _empDetailsState extends State { contentPadding: EdgeInsets.symmetric( vertical: 5, horizontal: 5), ), - value: action == 'Edit' - ? _relationShipController.text - : null, + value: dropdownValue ?? + (action == 'Edit' + ? _relationShipController.text + : null), onChanged: (value) { _relationShipController.text = value!; }, diff --git a/lib/empReview.dart b/lib/empReview.dart index 888fed3..2d0973c 100644 --- a/lib/empReview.dart +++ b/lib/empReview.dart @@ -705,12 +705,14 @@ class _empReviewDetailsState extends State { isChecked = false; }); print('response.statusCode == 200'); + _showSuccessDialog(); ToastHelper.showSuccessToast(context, 'Saved Successfully...'); } else { setState(() { isLoading = false; }); // Handle other status codes + _showErrorDialog(); ToastHelper.showErrorToast(context, 'Failed to Save'); print('Request failed with status: ${response['code']}'); } @@ -723,6 +725,67 @@ class _empReviewDetailsState extends State { } } + void _showSuccessDialog() { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + backgroundColor: Colors.white, + title: Text( + 'Success', + style: GoogleFonts.poppins( + color: Colors.green, + ), + ), + content: Text('Enrollment Completed'), + actions: [ + TextButton( + child: Text( + 'OK', + style: GoogleFonts.poppins( + color: Color(0xFFE26728), + ), + ), + onPressed: () { + Navigator.popAndPushNamed(context, 'empDetails'); + }, + ), + ], + ); + }, + ); + } + + void _showErrorDialog() { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text( + 'Error', + style: GoogleFonts.poppins( + color: Colors.red, + ), + ), + content: Text('Something went wrong. Enrollemnt not completed'), + actions: [ + TextButton( + child: Text( + 'OK', + style: GoogleFonts.poppins( + color: Color(0xFFE26728), + ), + ), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } + @override Widget build(BuildContext context) { if ((gpaMappedFamilyFloaters == [] && gpaMappedFamilyFloaters == null) && diff --git a/lib/hrPolicyDetails.dart b/lib/hrPolicyDetails.dart index 40b7fe9..915b5fc 100644 --- a/lib/hrPolicyDetails.dart +++ b/lib/hrPolicyDetails.dart @@ -138,14 +138,16 @@ class _HrPolicyDetailsState extends State } Future getEmployeeAndDependence(clintID, getPolicyNo) async { - // setState(() { - isLoading = true; - // }); + setState(() { + isLoading = true; + }); try { final response = await apiService.getEmployeeAndDependenceToApi( clintID!, getPolicyNo!, empRefId!); if (response['status'] == 'success') { - isLoading = false; + setState(() { + isLoading = false; + }); setState(() { getEmpDependenceByClintId = List>.from(response['data']); @@ -155,13 +157,18 @@ class _HrPolicyDetailsState extends State print(filteredData); }); } else { - isLoading = false; + setState(() { + isLoading = false; + }); + // ToastHelper.showWarningToast( // context, 'Request failed with status: ${response.statusCode}'); print('Request failed with status: ${response['code']}'); } } catch (e) { - _isLoading = false; + setState(() { + isLoading = false; + }); print('Exception occurred: $e'); } finally { setState(() { diff --git a/pubspec.yaml b/pubspec.yaml index cedc3e1..ef4dfac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -88,6 +88,8 @@ flutter: - .env - .env.development - .env.production + - .env.uat + - .env.test # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see