feat: delete button works in contact_modal
All checks were successful
/ mirror (push) Successful in 4s
All checks were successful
/ mirror (push) Successful in 4s
This commit is contained in:
parent
27192959ed
commit
28aff88319
@ -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 [
|
||||
|
Loading…
Reference in New Issue
Block a user