143 lines
8.6 KiB
Dart
143 lines
8.6 KiB
Dart
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';
|
|
|
|
class BeneficiaryDetailsScreen extends StatelessWidget {
|
|
final Beneficiary beneficiary;
|
|
|
|
BeneficiaryDetailsScreen({super.key, required this.beneficiary});
|
|
|
|
final service = getIt<BeneficiaryService>();
|
|
|
|
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: <Widget>[
|
|
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: <Widget>[
|
|
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(
|
|
title: const Text('Beneficiary Details'),
|
|
),
|
|
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('Beneficiary Name', beneficiary.bankName ?? 'N/A'),
|
|
_buildDetailRow('Account No.', beneficiary.accountNo),
|
|
_buildDetailRow('Account Type', beneficiary.accountType),
|
|
_buildDetailRow('IFSC Code', beneficiary.ifscCode),
|
|
_buildDetailRow('Branch Name', 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: const Text('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),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|