contact-modal-delete-contact #19

Merged
stcb merged 2 commits from contact-modal-delete-contact into dev 2024-12-20 09:20:18 +00:00
Showing only changes of commit 28aff88319 - Show all commits

View File

@ -94,6 +94,46 @@ class _ContactModalState extends State<ContactModal> {
}
}
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<ContactModal> {
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 [