Manage Beneficiary
This commit is contained in:
@@ -103,10 +103,10 @@ class BeneficiaryService {
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<List<dynamic>> fetchBeneficiaryList() async {
|
||||
Future<List<Beneficiary>> fetchBeneficiaryList() async{
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
"/api/beneficiaries/get", // replace with actual path
|
||||
"/api/beneficiary/get",
|
||||
options: Options(
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -115,8 +115,8 @@ class BeneficiaryService {
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// Assuming API returns JSON array of beneficiaries
|
||||
return response.data as List<dynamic>;
|
||||
return Beneficiary.listFromJson(response.data);
|
||||
|
||||
} else {
|
||||
throw Exception("Failed to fetch beneficiaries");
|
||||
}
|
||||
|
@@ -1,23 +1,32 @@
|
||||
|
||||
|
||||
class Beneficiary {
|
||||
final String accountNo;
|
||||
final String accountType;
|
||||
final String name;
|
||||
final String ifscCode;
|
||||
|
||||
final String? bankName;
|
||||
final String? branchName;
|
||||
|
||||
Beneficiary({
|
||||
required this.accountNo,
|
||||
required this.accountType,
|
||||
required this.name,
|
||||
required this.ifscCode,
|
||||
this.bankName,
|
||||
this.branchName,
|
||||
});
|
||||
|
||||
factory Beneficiary.fromJson(Map<String, dynamic> json) {
|
||||
print('==============================');
|
||||
print(json);
|
||||
return Beneficiary(
|
||||
accountNo: json['accountNo'] ?? '',
|
||||
accountType: json['accountType'] ?? '',
|
||||
name: json['name'] ?? '',
|
||||
ifscCode: json['ifscCode'] ?? '',
|
||||
bankName: json['bankName'] ?? '',
|
||||
branchName: json['branchName'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,6 +39,12 @@ class Beneficiary {
|
||||
};
|
||||
}
|
||||
|
||||
static List<Beneficiary> listFromJson(List<dynamic> jsonList) {
|
||||
final beneficiaryList = jsonList.map((beneficiary) => Beneficiary.fromJson(beneficiary)).toList();
|
||||
print(beneficiaryList);
|
||||
return beneficiaryList;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Beneficiary(accountNo: $accountNo, accountType: $accountType, ifscCode: $ifscCode, name: $name)';
|
||||
|
45
lib/data/models/beneficiary_recieve.dart
Normal file
45
lib/data/models/beneficiary_recieve.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
class BeneficiaryRecieve {
|
||||
final String accountNo;
|
||||
final String accountType;
|
||||
final String name;
|
||||
final String ifscCode;
|
||||
final String bankName;
|
||||
final String branchName;
|
||||
|
||||
|
||||
BeneficiaryRecieve({
|
||||
required this.accountNo,
|
||||
required this.accountType,
|
||||
required this.name,
|
||||
required this.ifscCode,
|
||||
required this.bankName,
|
||||
required this.branchName,
|
||||
});
|
||||
|
||||
factory BeneficiaryRecieve.fromJson(Map<String, dynamic> json) {
|
||||
return BeneficiaryRecieve(
|
||||
accountNo: json['account_no'] ?? '',
|
||||
accountType: json['account_type'] ?? '',
|
||||
name: json['name'] ?? '',
|
||||
ifscCode: json['ifsc_code'] ?? '',
|
||||
bankName: json['bank_name'] ?? '',
|
||||
branchName: json['branch_name'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'account_no': accountNo,
|
||||
'account_type': accountType,
|
||||
'name': name,
|
||||
'ifsc_code' : ifscCode,
|
||||
'bank_name' : bankName,
|
||||
'branch_name' : branchName
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ListBeneficiary(accountNo: $accountNo, accountType: $accountType, ifscCode: $ifscCode, name: $name, bankName: $bankName, branchName: $branchName)';
|
||||
}
|
||||
}
|
@@ -18,9 +18,12 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||
super.initState();
|
||||
|
||||
// Automatically go to login after 6 seconds
|
||||
Timer(const Duration(seconds: 6), () {
|
||||
// Timer(const Duration(seconds: 6), () {
|
||||
|
||||
|
||||
// }
|
||||
// );
|
||||
widget.onContinue();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:kmobile/data/models/beneficiary.dart';
|
||||
import 'package:kmobile/features/beneficiaries/screens/add_beneficiary_screen.dart';
|
||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import '../../../di/injection.dart';
|
||||
import 'package:kmobile/api/services/beneficiary_service.dart';
|
||||
@@ -103,7 +102,7 @@ class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
||||
var service = getIt<BeneficiaryService>();
|
||||
//final BeneficiaryService _service = BeneficiaryService();
|
||||
bool _isLoading = true;
|
||||
List<dynamic> _beneficiaries = [];
|
||||
List<Beneficiary> _beneficiaries = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -114,7 +113,7 @@ class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
||||
Future<void> _loadBeneficiaries() async {
|
||||
final data = await service.fetchBeneficiaryList();
|
||||
setState(() {
|
||||
_beneficiaries = data;
|
||||
_beneficiaries = data ;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
@@ -158,14 +157,14 @@ class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
||||
radius: 24,
|
||||
backgroundColor: Theme.of(context).primaryColor.withOpacity(0.2),
|
||||
child: Text(
|
||||
item['name'] != null && item['name'].isNotEmpty
|
||||
? item['name'][0].toUpperCase()
|
||||
item.name.isNotEmpty
|
||||
? item.name[0].toUpperCase()
|
||||
: '?',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
title: Text(item['name'] ?? 'Unknown'),
|
||||
subtitle: Text(item['accountNumber'] ?? 'No account number'),
|
||||
title: Text(item.name ?? 'Unknown'),
|
||||
subtitle: Text(item.accountNo ?? 'No account number'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@@ -202,7 +202,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
backgroundColor:Theme.of(context).scaffoldBackgroundColor,
|
||||
automaticallyImplyLeading: false,
|
||||
title: Text(
|
||||
AppLocalizations.of(context).kMobile,
|
||||
AppLocalizations.of(context).kconnect,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -482,7 +482,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const FundTransferBeneficiaryScreen()));
|
||||
}, disable: true),
|
||||
}, disable: false),
|
||||
_buildQuickLink(Symbols.server_person,
|
||||
AppLocalizations.of(context).accountInfo, () {
|
||||
Navigator.push(
|
||||
|
Reference in New Issue
Block a user