Refactor AddEmployeeScreen for improved readability and consistency

This commit is contained in:
Vaibhav Surve 2025-05-09 10:13:00 +05:30
parent 1ea960b0ec
commit db8a811a63

View File

@ -24,12 +24,12 @@ class AddEmployeeScreen extends StatefulWidget {
} }
class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin { class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
AddEmployeeController controller = Get.put(AddEmployeeController()); final AddEmployeeController controller = Get.put(AddEmployeeController());
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Layout( return Layout(
child: GetBuilder( child: GetBuilder<AddEmployeeController>(
init: controller, init: controller,
tag: 'add_employee_controller', tag: 'add_employee_controller',
builder: (controller) { builder: (controller) {
@ -73,8 +73,7 @@ class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
Widget detail() { Widget detail() {
return Form( return Form(
key: controller key: controller.basicValidator.formKey,
.basicValidator.formKey, // Ensure the key is correctly assigned
child: MyCard.bordered( child: MyCard.bordered(
borderRadiusAll: 4, borderRadiusAll: 4,
border: Border.all(color: Colors.grey.withOpacity(0.2)), border: Border.all(color: Colors.grey.withOpacity(0.2)),
@ -97,10 +96,8 @@ class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
MyText.labelMedium("First Name"), MyText.labelMedium("First Name"),
MySpacing.height(8), MySpacing.height(8),
TextFormField( TextFormField(
validator: validator: controller.basicValidator.getValidation('first_name'),
controller.basicValidator.getValidation('first_name'), controller: controller.basicValidator.getController('first_name'),
controller:
controller.basicValidator.getController('first_name'),
keyboardType: TextInputType.name, keyboardType: TextInputType.name,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "eg: Jhon", hintText: "eg: Jhon",
@ -117,10 +114,8 @@ class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
MyText.labelMedium("Last Name"), MyText.labelMedium("Last Name"),
MySpacing.height(8), MySpacing.height(8),
TextFormField( TextFormField(
validator: validator: controller.basicValidator.getValidation('last_name'),
controller.basicValidator.getValidation('last_name'), controller: controller.basicValidator.getController('last_name'),
controller:
controller.basicValidator.getController('last_name'),
keyboardType: TextInputType.name, keyboardType: TextInputType.name,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "eg: Doe", hintText: "eg: Doe",
@ -137,10 +132,8 @@ class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
MyText.labelMedium("Phone Number"), MyText.labelMedium("Phone Number"),
MySpacing.height(8), MySpacing.height(8),
TextFormField( TextFormField(
validator: validator: controller.basicValidator.getValidation('phone_number'),
controller.basicValidator.getValidation('phone_number'), controller: controller.basicValidator.getController('phone_number'),
controller:
controller.basicValidator.getController('phone_number'),
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
decoration: InputDecoration( decoration: InputDecoration(
hintText: "eg: +91 9876543210", hintText: "eg: +91 9876543210",
@ -171,8 +164,7 @@ class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
return DropdownMenuItem<Gender>( return DropdownMenuItem<Gender>(
value: gender, value: gender,
child: MyText.labelMedium( child: MyText.labelMedium(
gender.name[0].toUpperCase() + gender.name[0].toUpperCase() + gender.name.substring(1),
gender.name.substring(1),
), ),
); );
}).toList(), }).toList(),
@ -235,11 +227,10 @@ class _AddEmployeeScreenState extends State<AddEmployeeScreen> with UIMixin {
children: [ children: [
MyButton.text( MyButton.text(
onPressed: () { onPressed: () {
Get.toNamed('/dashboard/employees'); Get.back();
}, },
padding: MySpacing.xy(20, 16), padding: MySpacing.xy(20, 16),
splashColor: splashColor: contentTheme.secondary.withValues(alpha: 0.1),
contentTheme.secondary.withValues(alpha: 0.1),
child: MyText.bodySmall('Cancel'), child: MyText.bodySmall('Cancel'),
), ),
MySpacing.width(12), MySpacing.width(12),