162 lines
4.6 KiB
Dart
162 lines
4.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:kmobile/data/models/beneficiary.dart';
|
|
import 'package:kmobile/features/beneficiaries/screens/add_beneficiary_screen.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
import '../../../di/injection.dart';
|
|
import 'package:kmobile/api/services/beneficiary_service.dart';
|
|
import 'package:shimmer/shimmer.dart';
|
|
|
|
class ManageBeneficiariesScreen extends StatefulWidget {
|
|
final String customerName;
|
|
const ManageBeneficiariesScreen({super.key, required this.customerName});
|
|
|
|
@override
|
|
State<ManageBeneficiariesScreen> createState() =>
|
|
_ManageBeneficiariesScreen();
|
|
}
|
|
|
|
class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
|
var service = getIt<BeneficiaryService>();
|
|
bool _isLoading = true;
|
|
List<Beneficiary> _beneficiaries = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadBeneficiaries();
|
|
}
|
|
|
|
Future<void> _loadBeneficiaries() async {
|
|
final data = await service.fetchBeneficiaryList();
|
|
setState(() {
|
|
_beneficiaries = data;
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
|
|
Widget _buildShimmerList() {
|
|
return ListView.builder(
|
|
itemCount: 6,
|
|
itemBuilder: (context, index) => Shimmer.fromColors(
|
|
baseColor: Colors.grey.shade300,
|
|
highlightColor: Colors.grey.shade100,
|
|
child: ListTile(
|
|
leading: const CircleAvatar(
|
|
radius: 24,
|
|
backgroundColor: Colors.white,
|
|
),
|
|
title: Container(
|
|
height: 16,
|
|
color: Colors.white,
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
),
|
|
subtitle: Container(
|
|
height: 14,
|
|
color: Colors.white,
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _getBankLogo(String? bankName) {
|
|
if (bankName != null && bankName.toLowerCase().contains('state bank of india')) {
|
|
return Image.asset(
|
|
'assets/images/sbi_logo.png',
|
|
width: 40,
|
|
height: 40,
|
|
);
|
|
}
|
|
if (bankName != null && bankName.toLowerCase().contains('hdfc bank ltd')) {
|
|
return Image.asset(
|
|
'assets/images/hdfc_logo.png',
|
|
width: 40,
|
|
height: 40,
|
|
);
|
|
}
|
|
if (bankName != null && bankName.toLowerCase().contains('icici bank ltd')) {
|
|
return Image.asset(
|
|
'assets/images/icici_logo.png',
|
|
width: 40,
|
|
height: 40,
|
|
);
|
|
}
|
|
if (bankName != null && bankName.toLowerCase().contains('punjab national bank')) {
|
|
return Image.asset(
|
|
'assets/images/pnb_logo.png',
|
|
width: 40,
|
|
height: 40,
|
|
);
|
|
}
|
|
else {
|
|
return const Icon(
|
|
Icons.account_balance,
|
|
size: 40,
|
|
color: Colors.grey,
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _buildBeneficiaryList() {
|
|
if (_beneficiaries.isEmpty) {
|
|
return Center(
|
|
child: Text(AppLocalizations.of(context).noBeneficiaryFound));
|
|
}
|
|
return ListView.builder(
|
|
itemCount: _beneficiaries.length,
|
|
itemBuilder: (context, index) {
|
|
final item = _beneficiaries[index];
|
|
return ListTile(
|
|
leading: CircleAvatar(
|
|
radius: 24,
|
|
backgroundColor: Colors.transparent,
|
|
child: _getBankLogo(item.bankName),
|
|
),
|
|
title: Text(item.name ?? 'Unknown'),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(item.accountNo ?? 'No account number'),
|
|
if (item.bankName != null && item.bankName!.isNotEmpty)
|
|
Text(
|
|
item.bankName!,
|
|
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
String customerName = widget.customerName;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(AppLocalizations.of(context).beneficiaries),
|
|
),
|
|
body: _isLoading ? _buildShimmerList() : _buildBeneficiaryList(),
|
|
floatingActionButton: Padding(
|
|
padding: const EdgeInsets.only(bottom: 8.0),
|
|
child: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
AddBeneficiaryScreen(customerName: customerName),
|
|
),
|
|
);
|
|
},
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
foregroundColor: Theme.of(context).primaryColor,
|
|
elevation: 5,
|
|
child: const Icon(Icons.add),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|