diff --git a/dialer/lib/features/contacts/widgets/contact_modal.dart b/dialer/lib/features/contacts/widgets/contact_modal.dart index 265a769..66cfdda 100644 --- a/dialer/lib/features/contacts/widgets/contact_modal.dart +++ b/dialer/lib/features/contacts/widgets/contact_modal.dart @@ -94,6 +94,46 @@ class _ContactModalState extends State { } } +void _deleteContact() async { + final bool shouldDelete = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Delete Contact'), + content: Text('Are you sure you want to delete ${widget.contact.displayName}?'), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(false), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () => Navigator.of(context).pop(true), + child: const Text('Delete'), + ), + ], + ), + ); + + if (shouldDelete) { + try { + // Delete the contact + await FlutterContacts.deleteContact(widget.contact); + + // Show success message + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('${widget.contact.displayName} deleted')), + ); + + // Close the modal + Navigator.of(context).pop(); + } catch (e) { + // Handle errors and show a failure message + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to delete ${widget.contact.displayName}: $e')), + ); + } + } +} + @override Widget build(BuildContext context) { String email = widget.contact.emails.isNotEmpty @@ -141,8 +181,9 @@ class _ContactModalState extends State { icon: const Icon(Icons.more_vert, color: Colors.white), onSelected: (String choice) { - // Implement actions here - debugPrint('Selected: $choice'); + if (choice == 'delete') { + _deleteContact(); + } }, itemBuilder: (BuildContext context) { return [