import 'package:flutter/material.dart'; import 'package:kmobile/data/models/beneficiary.dart'; import 'package:kmobile/di/injection.dart'; import 'package:kmobile/widgets/bank_logos.dart'; import 'package:kmobile/api/services/beneficiary_service.dart'; import '../../../l10n/app_localizations.dart'; class BeneficiaryDetailsScreen extends StatelessWidget { final Beneficiary beneficiary; BeneficiaryDetailsScreen({super.key, required this.beneficiary}); final service = getIt(); void _deleteBeneficiary(BuildContext context) async { try { await service.deleteBeneficiary(beneficiary.accountNo); _showSuccessDialog(context); } catch (e) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( '${AppLocalizations.of(context).failedToDeleteBeneficiary}: $e')), ); } } void _showSuccessDialog(BuildContext context) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text(AppLocalizations.of(context).success), content: Text(AppLocalizations.of(context).beneficiaryDeletedSuccessfully), actions: [ TextButton( child: Text(AppLocalizations.of(context).ok), onPressed: () { Navigator.of(context).popUntil((route) => route.isFirst); }, ), ], ); }, ); } void _showDeleteConfirmationDialog(BuildContext context) { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text(AppLocalizations.of(context).deleteBeneficiary), content: Text(AppLocalizations.of(context) .areYouSureYouWantToDeleteThisBeneficiary), actions: [ TextButton( child: Text(AppLocalizations.of(context).cancel), onPressed: () { Navigator.of(context).pop(); }, ), TextButton( child: Text(AppLocalizations.of(context).delete), onPressed: () { //Navigator.of(context).pop(); _deleteBeneficiary(context); }, ), ], ); }, ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(AppLocalizations.of(context).beneficiarydetails), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ CircleAvatar( radius: 24, backgroundColor: Colors.transparent, child: getBankLogo(beneficiary.bankName), ), const SizedBox(width: 16), Text( beneficiary.name, style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold), ), ], ), const SizedBox(height: 24), _buildDetailRow('${AppLocalizations.of(context).bankName} ', beneficiary.bankName ?? 'N/A'), _buildDetailRow('${AppLocalizations.of(context).accountNumber} ', beneficiary.accountNo), _buildDetailRow('${AppLocalizations.of(context).accountType} ', beneficiary.accountType), _buildDetailRow('${AppLocalizations.of(context).ifscCode} ', beneficiary.ifscCode), _buildDetailRow('${AppLocalizations.of(context).branchName} ', beneficiary.branchName ?? 'N/A'), const Spacer(), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ // ElevatedButton.icon( // onPressed: () { // // Set Transaction Limit for this beneficiary // }, // icon: const Icon(Icons.currency_rupee), // label: const Text('Set Limit'), // ), ElevatedButton.icon( onPressed: () { // Delete beneficiary option _showDeleteConfirmationDialog(context); }, icon: const Icon(Icons.delete), label: Text(AppLocalizations.of(context).delete), ), ], ), ], ), ), ); } Widget _buildDetailRow(String label, String value) { return Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(label, style: const TextStyle(fontWeight: FontWeight.bold)), Text(value), ], ), ); } }