feat: Add designation field to contact model and update add contact functionality
This commit is contained in:
parent
8576448a32
commit
b286ab854a
@ -94,6 +94,7 @@ class AddContactController extends GetxController {
|
||||
required List<Map<String, String>> phones,
|
||||
required String address,
|
||||
required String description,
|
||||
String? designation,
|
||||
}) async {
|
||||
if (isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
@ -156,6 +157,8 @@ class AddContactController extends GetxController {
|
||||
if (phones.isNotEmpty) "contactPhones": phones,
|
||||
if (address.trim().isNotEmpty) "address": address.trim(),
|
||||
if (description.trim().isNotEmpty) "description": description.trim(),
|
||||
if (designation != null && designation.trim().isNotEmpty)
|
||||
"designation": designation.trim(),
|
||||
};
|
||||
|
||||
logSafe("${id != null ? 'Updating' : 'Creating'} contact");
|
||||
|
@ -24,6 +24,7 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
|
||||
final nameCtrl = TextEditingController();
|
||||
final orgCtrl = TextEditingController();
|
||||
final designationCtrl = TextEditingController();
|
||||
final addrCtrl = TextEditingController();
|
||||
final descCtrl = TextEditingController();
|
||||
final tagCtrl = TextEditingController();
|
||||
@ -49,6 +50,7 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
if (c != null) {
|
||||
nameCtrl.text = c.name;
|
||||
orgCtrl.text = c.organization;
|
||||
designationCtrl.text = c.designation ?? '';
|
||||
addrCtrl.text = c.address;
|
||||
descCtrl.text = c.description;
|
||||
|
||||
@ -109,6 +111,7 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
void dispose() {
|
||||
nameCtrl.dispose();
|
||||
orgCtrl.dispose();
|
||||
designationCtrl.dispose();
|
||||
addrCtrl.dispose();
|
||||
descCtrl.dispose();
|
||||
tagCtrl.dispose();
|
||||
@ -118,6 +121,20 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _labelWithStar(String label, {bool required = false}) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
MyText.labelMedium(label),
|
||||
if (required)
|
||||
const Text(
|
||||
" *",
|
||||
style: TextStyle(color: Colors.red, fontSize: 14),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
InputDecoration _inputDecoration(String hint) => InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: MyTextStyle.bodySmall(xMuted: true),
|
||||
@ -145,7 +162,7 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
MyText.labelMedium(label),
|
||||
_labelWithStar(label, required: required),
|
||||
MySpacing.height(8),
|
||||
TextFormField(
|
||||
controller: ctrl,
|
||||
@ -386,6 +403,7 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
phones: phones,
|
||||
address: addrCtrl.text.trim(),
|
||||
description: descCtrl.text.trim(),
|
||||
designation: designationCtrl.text.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -412,7 +430,7 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
MySpacing.height(16),
|
||||
_textField("Organization", orgCtrl, required: true),
|
||||
MySpacing.height(16),
|
||||
MyText.labelMedium(" Bucket"),
|
||||
_labelWithStar("Bucket", required: true),
|
||||
MySpacing.height(8),
|
||||
Stack(
|
||||
children: [
|
||||
@ -477,11 +495,51 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text("Add Phone"),
|
||||
),
|
||||
Obx(() => showAdvanced.value
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ✅ Move Designation field here
|
||||
_textField("Designation", designationCtrl),
|
||||
MySpacing.height(16),
|
||||
|
||||
_dynamicList(
|
||||
emailCtrls,
|
||||
emailLabels,
|
||||
"Email",
|
||||
["Office", "Personal", "Other"],
|
||||
TextInputType.emailAddress,
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
emailCtrls.add(TextEditingController());
|
||||
emailLabels.add("Office".obs);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text("Add Email"),
|
||||
),
|
||||
_dynamicList(
|
||||
phoneCtrls,
|
||||
phoneLabels,
|
||||
"Phone",
|
||||
["Work", "Mobile", "Other"],
|
||||
TextInputType.phone,
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
phoneCtrls.add(TextEditingController());
|
||||
phoneLabels.add("Work".obs);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text("Add Phone"),
|
||||
),
|
||||
MyText.labelMedium("Category"),
|
||||
MySpacing.height(8),
|
||||
_popupSelector(controller.selectedCategory,
|
||||
controller.categories, "Choose Category"),
|
||||
_popupSelector(
|
||||
controller.selectedCategory,
|
||||
controller.categories,
|
||||
"Choose Category",
|
||||
),
|
||||
MySpacing.height(16),
|
||||
MyText.labelMedium("Tags"),
|
||||
MySpacing.height(8),
|
||||
@ -494,6 +552,9 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
|
||||
)
|
||||
: const SizedBox.shrink()),
|
||||
],
|
||||
)
|
||||
: const SizedBox.shrink()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -2,6 +2,7 @@ class ContactModel {
|
||||
final String id;
|
||||
final List<String>? projectIds;
|
||||
final String name;
|
||||
final String? designation;
|
||||
final List<ContactPhone> contactPhones;
|
||||
final List<ContactEmail> contactEmails;
|
||||
final ContactCategory? contactCategory;
|
||||
@ -15,6 +16,7 @@ class ContactModel {
|
||||
required this.id,
|
||||
required this.projectIds,
|
||||
required this.name,
|
||||
this.designation,
|
||||
required this.contactPhones,
|
||||
required this.contactEmails,
|
||||
required this.contactCategory,
|
||||
@ -30,6 +32,7 @@ class ContactModel {
|
||||
id: json['id'],
|
||||
projectIds: (json['projectIds'] as List?)?.map((e) => e as String).toList(),
|
||||
name: json['name'],
|
||||
designation: json['designation'],
|
||||
contactPhones: (json['contactPhones'] as List)
|
||||
.map((e) => ContactPhone.fromJson(e))
|
||||
.toList(),
|
||||
@ -48,6 +51,7 @@ class ContactModel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ContactPhone {
|
||||
final String id;
|
||||
final String label;
|
||||
|
Loading…
x
Reference in New Issue
Block a user