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 {
try {
final response = await ApiService.getContactBucketList();

View File

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