Manage Beneficiary fetch
This commit is contained in:
@@ -103,5 +103,29 @@ class BeneficiaryService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<dynamic>> fetchBeneficiaryList() async {
|
||||||
|
try {
|
||||||
|
final response = await _dio.get(
|
||||||
|
"/api/beneficiaries/get", // replace with actual path
|
||||||
|
options: Options(
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
// Assuming API returns JSON array of beneficiaries
|
||||||
|
return response.data as List<dynamic>;
|
||||||
|
} else {
|
||||||
|
throw Exception("Failed to fetch beneficiaries");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("Error fetching beneficiaries: $e");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'theme_state.dart';
|
import 'theme_state.dart';
|
||||||
import 'package:kmobile/config/theme_type.dart';
|
import 'package:kmobile/config/theme_type.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
// import 'package:kmobile/config/themes.dart';
|
|
||||||
|
|
||||||
class ThemeCubit extends Cubit<ThemeState> {
|
class ThemeCubit extends Cubit<ThemeState> {
|
||||||
ThemeCubit(): super(ThemeViolet()) {
|
ThemeCubit(): super(ThemeViolet()) {
|
||||||
|
@@ -3,6 +3,10 @@ import 'package:flutter_svg/svg.dart';
|
|||||||
import 'package:kmobile/features/beneficiaries/screens/add_beneficiary_screen.dart';
|
import 'package:kmobile/features/beneficiaries/screens/add_beneficiary_screen.dart';
|
||||||
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
import 'package:material_symbols_icons/material_symbols_icons.dart';
|
||||||
import '../../../l10n/app_localizations.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 {
|
class ManageBeneficiariesScreen extends StatefulWidget {
|
||||||
const ManageBeneficiariesScreen({super.key});
|
const ManageBeneficiariesScreen({super.key});
|
||||||
@@ -12,7 +16,7 @@ class ManageBeneficiariesScreen extends StatefulWidget {
|
|||||||
_ManageBeneficiariesScreen();
|
_ManageBeneficiariesScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
/*class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
||||||
final List<Map<String, String>> beneficiaries = [
|
final List<Map<String, String>> beneficiaries = [
|
||||||
{'bank': 'State Bank Of India', 'name': 'Trina Bakshi'},
|
{'bank': 'State Bank Of India', 'name': 'Trina Bakshi'},
|
||||||
{'bank': 'State Bank Of India', 'name': 'Sheetal Rao'},
|
{'bank': 'State Bank Of India', 'name': 'Sheetal Rao'},
|
||||||
@@ -94,3 +98,103 @@ class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
|
||||||
|
var service = getIt<BeneficiaryService>();
|
||||||
|
//final BeneficiaryService _service = BeneficiaryService();
|
||||||
|
bool _isLoading = true;
|
||||||
|
List<dynamic> _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'] != null && 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'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -227,6 +227,7 @@
|
|||||||
"invalidIfsc": "Invalid IFSC code",
|
"invalidIfsc": "Invalid IFSC code",
|
||||||
"validIfsc": "Valid IFSC",
|
"validIfsc": "Valid IFSC",
|
||||||
"beneficiaryAddedSuccess": "Beneficiary Added Successfully",
|
"beneficiaryAddedSuccess": "Beneficiary Added Successfully",
|
||||||
"beneficiaryAdditionFailed": "Beneficiary Addition Failed"
|
"beneficiaryAdditionFailed": "Beneficiary Addition Failed",
|
||||||
|
"noBeneficiaryFound": "No beneficiaries found"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -227,5 +227,6 @@
|
|||||||
"invalidIfsc": "अमान्य IFSC कोड",
|
"invalidIfsc": "अमान्य IFSC कोड",
|
||||||
"validIfsc": "मान्य IFSC",
|
"validIfsc": "मान्य IFSC",
|
||||||
"beneficiaryAddedSuccess": "लाभार्थी सफलतापूर्वक जोड़ा गया",
|
"beneficiaryAddedSuccess": "लाभार्थी सफलतापूर्वक जोड़ा गया",
|
||||||
"beneficiaryAdditionFailed": "लाभार्थी जोड़ने में विफल"
|
"beneficiaryAdditionFailed": "लाभार्थी जोड़ने में विफल",
|
||||||
|
"noBeneficiaryFound": "कोई लाभार्थी नहीं मिला"
|
||||||
}
|
}
|
||||||
|
@@ -1390,6 +1390,12 @@ abstract class AppLocalizations {
|
|||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
/// **'Beneficiary Addition Failed'**
|
/// **'Beneficiary Addition Failed'**
|
||||||
String get beneficiaryAdditionFailed;
|
String get beneficiaryAdditionFailed;
|
||||||
|
|
||||||
|
/// No description provided for @noBeneficiaryFound.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No beneficiaries found'**
|
||||||
|
String get noBeneficiaryFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||||
|
@@ -655,4 +655,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get beneficiaryAdditionFailed => 'Beneficiary Addition Failed';
|
String get beneficiaryAdditionFailed => 'Beneficiary Addition Failed';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get noBeneficiaryFound => 'No beneficiaries found';
|
||||||
}
|
}
|
||||||
|
@@ -655,4 +655,7 @@ class AppLocalizationsHi extends AppLocalizations {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String get beneficiaryAdditionFailed => 'लाभार्थी जोड़ने में विफल';
|
String get beneficiaryAdditionFailed => 'लाभार्थी जोड़ने में विफल';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get noBeneficiaryFound => 'कोई लाभार्थी नहीं मिला';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user