diff --git a/lib/features/beneficiaries/screens/beneficiary_details_screen.dart b/lib/features/beneficiaries/screens/beneficiary_details_screen.dart index 5c3e810..e5d99b5 100644 --- a/lib/features/beneficiaries/screens/beneficiary_details_screen.dart +++ b/lib/features/beneficiaries/screens/beneficiary_details_screen.dart @@ -10,7 +10,65 @@ class BeneficiaryDetailsScreen extends StatelessWidget { BeneficiaryDetailsScreen({super.key, required this.beneficiary}); final service = getIt(); - @override + + void _deleteBeneficiary(BuildContext context) async { + try { + await service.deleteBeneficiary(beneficiary.accountNo); + _showSuccessDialog(context); + } catch (e) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to delete beneficiary: $e')), + ); + } +} + +void _showSuccessDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Success'), + content: const Text('Beneficiary deleted successfully.'), + actions: [ + TextButton( + child: const Text('OK'), + onPressed: () { + Navigator.of(context).popUntil((route) => route.isFirst); + }, + ), + ], + ); + }, + ); +} + +void _showDeleteConfirmationDialog(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Delete Beneficiary'), + content: + const Text('Are you sure you want to delete this beneficiary?'), + actions: [ + TextButton( + child: const Text('Cancel'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('Delete'), + onPressed: () { + Navigator.of(context).pop(); + _deleteBeneficiary(context); + }, + ), + ], + ); + }, + ); +} @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( @@ -56,6 +114,7 @@ class BeneficiaryDetailsScreen extends StatelessWidget { ElevatedButton.icon( onPressed: () { // Delete beneficiary option + _showDeleteConfirmationDialog(context); }, icon: const Icon(Icons.delete), label: const Text('Delete'),