PMJBY/SBY enquiry created
This commit is contained in:
215
lib/features/yojna/screens/pmsby_enquiry_screen.dart
Normal file
215
lib/features/yojna/screens/pmsby_enquiry_screen.dart
Normal file
@@ -0,0 +1,215 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/yojna_service.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
|
||||
class PMSBYEnquiryScreen extends StatefulWidget {
|
||||
final String? cifNumber;
|
||||
|
||||
const PMSBYEnquiryScreen({
|
||||
super.key,
|
||||
required this.cifNumber,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PMSBYEnquiryScreen> createState() => _PMSBYEnquiryScreenState();
|
||||
}
|
||||
|
||||
class _PMSBYEnquiryScreenState extends State<PMSBYEnquiryScreen> {
|
||||
String? _selectedFinancialYear;
|
||||
bool _isLoading = false;
|
||||
Map<String, dynamic>? _enquiryData;
|
||||
String? _errorMessage;
|
||||
|
||||
final List<String> _financialYears = [
|
||||
'2021-2022',
|
||||
'2022-2023',
|
||||
'2023-2024',
|
||||
'2024-2025',
|
||||
'2025-2026',
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedFinancialYear = null;
|
||||
}
|
||||
|
||||
Future<void> _fetchEnquiryData() async {
|
||||
if (_selectedFinancialYear == null || widget.cifNumber == null) return;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_enquiryData = null;
|
||||
_errorMessage = null;
|
||||
});
|
||||
|
||||
final formattedYear = _selectedFinancialYear!.replaceAll('-', '');
|
||||
|
||||
try {
|
||||
final response = await getIt<YojnaService>().enquiry(
|
||||
scheme: '01',
|
||||
action: 'E',
|
||||
financialyear: formattedYear,
|
||||
customerno: widget.cifNumber,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
if (response is Map<String, dynamic>) {
|
||||
if (response['status'] == 'FAILED') {
|
||||
_errorMessage = response['message'] ?? 'No record found';
|
||||
} else {
|
||||
_enquiryData = response;
|
||||
}
|
||||
} else if (response is List && response.isNotEmpty) {
|
||||
_enquiryData = response[0] as Map<String, dynamic>;
|
||||
} else {
|
||||
_errorMessage = 'No data found for the selected year.';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_errorMessage = 'Error: ${e.toString()}';
|
||||
});
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('PMSBY details'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.person, color: Colors.blue),
|
||||
title: const Text('CIF Number'),
|
||||
subtitle: Text(
|
||||
widget.cifNumber ?? 'N/A',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
value: _selectedFinancialYear,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Select Financial Year',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.calendar_today),
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
items: _financialYears.map((String year) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: year,
|
||||
child: Text(year),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? newValue) {
|
||||
setState(() {
|
||||
_selectedFinancialYear = newValue;
|
||||
});
|
||||
_fetchEnquiryData();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
if (_isLoading)
|
||||
const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20.0),
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else if (_errorMessage != null)
|
||||
Card(
|
||||
color: Colors.red.shade50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
_errorMessage!,
|
||||
style: TextStyle(color: Colors.red.shade700, fontWeight: FontWeight.bold),
|
||||
//textAlign: Center,
|
||||
),
|
||||
),
|
||||
)
|
||||
else if (_enquiryData != null)
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Scheme Details',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
_buildDetailRow('Customer Name', _enquiryData!['customername']),
|
||||
_buildDetailRow('Policy Number', _enquiryData!['policynumber'] ?? _enquiryData!['policyno']),
|
||||
_buildDetailRow('Account Number', _enquiryData!['accountno']),
|
||||
_buildDetailRow('Premium Amount', _enquiryData!['preimiumamount'] ?? _enquiryData!['premiumamount']),
|
||||
_buildDetailRow('Nominee Name', _enquiryData!['nomineename']),
|
||||
_buildDetailRow('Transaction Date', _enquiryData!['transactiondate']),
|
||||
_buildDetailRow('Journal No', _enquiryData!['journalno']),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, dynamic value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500, color: Colors.grey),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
value?.toString() ?? 'N/A',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.end,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user