199 lines
6.0 KiB
Dart
199 lines
6.0 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 {
|
|
const ManageBeneficiariesScreen({super.key});
|
|
|
|
@override
|
|
State<ManageBeneficiariesScreen> createState() =>
|
|
_ManageBeneficiariesScreen();
|
|
}
|
|
|
|
/*class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
|
final List<Map<String, String>> beneficiaries = [
|
|
{'bank': 'State Bank Of India', 'name': 'Trina Bakshi'},
|
|
{'bank': 'State Bank Of India', 'name': 'Sheetal Rao'},
|
|
{'bank': 'Punjab National Bank', 'name': 'Manoj Kumar'},
|
|
{'bank': 'State Bank Of India', 'name': 'Rohit Mehra'},
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
leading: IconButton(
|
|
icon: const Icon(Symbols.arrow_back_ios_new),
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
title: Text(
|
|
AppLocalizations.of(context).beneficiaries,
|
|
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
|
|
),
|
|
centerTitle: false,
|
|
actions: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 10.0),
|
|
child: CircleAvatar(
|
|
backgroundColor: Colors.grey[200],
|
|
radius: 20,
|
|
child: SvgPicture.asset(
|
|
'assets/images/avatar_male.svg',
|
|
width: 40,
|
|
height: 40,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: ListView.builder(
|
|
itemCount: beneficiaries.length,
|
|
itemBuilder: (context, index) {
|
|
final beneficiary = beneficiaries[index];
|
|
return ListTile(
|
|
leading: CircleAvatar(
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
child: Text('A'),
|
|
),
|
|
title: Text(beneficiary['name']!),
|
|
subtitle: Text(beneficiary['bank']!),
|
|
trailing: IconButton(
|
|
icon: const Icon(Symbols.delete_forever, color: Colors.red),
|
|
onPressed: () {
|
|
// Delete action
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
floatingActionButton: Padding(
|
|
padding: const EdgeInsets.only(bottom: 8.0),
|
|
child: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const AddBeneficiaryScreen(),
|
|
),
|
|
);
|
|
},
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
foregroundColor: Theme.of(context).primaryColor,
|
|
elevation: 5,
|
|
child: const Icon(Icons.add),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
*/
|
|
class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
|
var service = getIt<BeneficiaryService>();
|
|
//final BeneficiaryService _service = 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: 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 _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: Theme.of(context).primaryColor.withOpacity(0.2),
|
|
child: Text(
|
|
item.name.isNotEmpty
|
|
? item.name[0].toUpperCase()
|
|
: '?',
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
title: Text(item.name ?? 'Unknown'),
|
|
subtitle: Text(item.accountNo ?? 'No account number'),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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) => const AddBeneficiaryScreen(),
|
|
),
|
|
);
|
|
},
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
foregroundColor: Theme.of(context).primaryColor,
|
|
elevation: 5,
|
|
child: const Icon(Icons.add),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |