feat(directory): add form reset functionality in AddContactController and initialize fields in AddContactBottomSheet

This commit is contained in:
Vaibhav Surve 2025-07-05 11:57:15 +05:30
parent b187f1843a
commit 62c49b5429
2 changed files with 44 additions and 45 deletions

View File

@ -41,6 +41,15 @@ class AddContactController extends GetxController {
]); ]);
} }
void resetForm() {
selectedCategory.value = '';
selectedProject.value = '';
selectedBucket.value = '';
enteredTags.clear();
filteredSuggestions.clear();
filteredOrgSuggestions.clear();
}
Future<void> fetchBuckets() async { Future<void> fetchBuckets() async {
try { try {
final response = await ApiService.getContactBucketList(); final response = await ApiService.getContactBucketList();

View File

@ -1,4 +1,3 @@
// unchanged imports
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:marco/controller/directory/add_contact_controller.dart'; import 'package:marco/controller/directory/add_contact_controller.dart';
@ -7,7 +6,20 @@ import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/helpers/widgets/my_text_style.dart'; import 'package:marco/helpers/widgets/my_text_style.dart';
class AddContactBottomSheet extends StatelessWidget { class AddContactBottomSheet extends StatelessWidget {
AddContactBottomSheet({super.key}); AddContactBottomSheet({super.key}) {
controller.resetForm();
nameController.clear();
emailController.clear();
phoneController.clear();
orgController.clear();
tagTextController.clear();
addressController.clear();
descriptionController.clear();
// Reset labels
emailLabel.value = 'Office';
phoneLabel.value = 'Work';
}
final controller = Get.put(AddContactController()); final controller = Get.put(AddContactController());
final formKey = GlobalKey<FormState>(); final formKey = GlobalKey<FormState>();
@ -155,8 +167,7 @@ class AddContactBottomSheet extends StatelessWidget {
border: Border.all(color: Colors.grey.shade300), border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
boxShadow: const [ boxShadow: const [
BoxShadow( BoxShadow(color: Colors.black12, blurRadius: 4, offset: Offset(0, 2)),
color: Colors.black12, blurRadius: 4, offset: Offset(0, 2)),
], ],
), ),
child: ListView.builder( child: ListView.builder(
@ -197,8 +208,7 @@ class AddContactBottomSheet extends StatelessWidget {
color: theme.cardColor, color: theme.cardColor,
borderRadius: const BorderRadius.vertical(top: Radius.circular(24)), borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
boxShadow: const [ boxShadow: const [
BoxShadow( BoxShadow(color: Colors.black12, blurRadius: 12, offset: Offset(0, -2))
color: Colors.black12, blurRadius: 12, offset: Offset(0, -2))
], ],
), ),
child: Padding( child: Padding(
@ -219,10 +229,7 @@ class AddContactBottomSheet extends StatelessWidget {
), ),
), ),
MySpacing.height(12), MySpacing.height(12),
Center( Center(child: MyText.titleMedium("Create New Contact", fontWeight: 700)),
child:
MyText.titleMedium("Create New Contact", fontWeight: 700),
),
MySpacing.height(24), MySpacing.height(24),
_sectionLabel("Basic Info"), _sectionLabel("Basic Info"),
MySpacing.height(16), MySpacing.height(16),
@ -232,21 +239,11 @@ class AddContactBottomSheet extends StatelessWidget {
MySpacing.height(24), MySpacing.height(24),
_sectionLabel("Contact Info"), _sectionLabel("Contact Info"),
MySpacing.height(16), MySpacing.height(16),
_buildLabeledRow( _buildLabeledRow("Email Label", emailLabel, ["Office", "Personal", "Other"],
"Email Label", "Email", emailController, TextInputType.emailAddress),
emailLabel,
["Office", "Personal", "Other"],
"Email",
emailController,
TextInputType.emailAddress),
MySpacing.height(16), MySpacing.height(16),
_buildLabeledRow( _buildLabeledRow("Phone Label", phoneLabel, ["Work", "Mobile", "Other"],
"Phone Label", "Phone", phoneController, TextInputType.phone),
phoneLabel,
["Work", "Mobile", "Other"],
"Phone",
phoneController,
TextInputType.phone),
MySpacing.height(24), MySpacing.height(24),
_sectionLabel("Other Details"), _sectionLabel("Other Details"),
MySpacing.height(16), MySpacing.height(16),
@ -280,8 +277,7 @@ class AddContactBottomSheet extends StatelessWidget {
MySpacing.height(16), MySpacing.height(16),
_buildTextField("Address", addressController, maxLines: 2), _buildTextField("Address", addressController, maxLines: 2),
MySpacing.height(16), MySpacing.height(16),
_buildTextField("Description", descriptionController, _buildTextField("Description", descriptionController, maxLines: 2),
maxLines: 2),
MySpacing.height(24), MySpacing.height(24),
_buildActionButtons(), _buildActionButtons(),
], ],
@ -303,9 +299,8 @@ class AddContactBottomSheet extends StatelessWidget {
controller: controller, controller: controller,
maxLines: maxLines, maxLines: maxLines,
decoration: _inputDecoration("Enter $label"), decoration: _inputDecoration("Enter $label"),
validator: (value) => (value == null || value.trim().isEmpty) validator: (value) =>
? "$label is required" (value == null || value.trim().isEmpty) ? "$label is required" : null,
: null,
), ),
], ],
); );
@ -338,7 +333,7 @@ class AddContactBottomSheet extends StatelessWidget {
}, },
); );
}, },
)) )),
], ],
); );
} }
@ -359,11 +354,7 @@ class AddContactBottomSheet extends StatelessWidget {
children: [ children: [
MyText.labelMedium(label), MyText.labelMedium(label),
MySpacing.height(8), MySpacing.height(8),
_popupSelector( _popupSelector(hint: "Label", selectedValue: selectedLabel, options: options),
hint: "Label",
selectedValue: selectedLabel,
options: options,
),
], ],
), ),
), ),
@ -398,14 +389,15 @@ class AddContactBottomSheet extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: OutlinedButton.icon( child: OutlinedButton.icon(
onPressed: () => Get.back(), onPressed: () {
Get.back();
Get.delete<AddContactController>(); // cleanup
},
icon: const Icon(Icons.close, color: Colors.red), icon: const Icon(Icons.close, color: Colors.red),
label: label: MyText.bodyMedium("Cancel", color: Colors.red, fontWeight: 600),
MyText.bodyMedium("Cancel", color: Colors.red, fontWeight: 600),
style: OutlinedButton.styleFrom( style: OutlinedButton.styleFrom(
side: const BorderSide(color: Colors.red), side: const BorderSide(color: Colors.red),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
borderRadius: BorderRadius.circular(10)),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
), ),
), ),
@ -428,12 +420,10 @@ class AddContactBottomSheet extends StatelessWidget {
} }
}, },
icon: const Icon(Icons.check_circle_outline, color: Colors.white), icon: const Icon(Icons.check_circle_outline, color: Colors.white),
label: label: MyText.bodyMedium("Save", color: Colors.white, fontWeight: 600),
MyText.bodyMedium("Save", color: Colors.white, fontWeight: 600),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.indigo, backgroundColor: Colors.indigo,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
borderRadius: BorderRadius.circular(10)),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10), padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
), ),
), ),