From eb812690832293188e11b7f2ae340cb4cd8835c2 Mon Sep 17 00:00:00 2001 From: asif Date: Mon, 9 Mar 2026 18:17:18 +0530 Subject: [PATCH] PMJBY/SBY enquiry created --- lib/api/services/yojna_service.dart | 35 +++ lib/features/yojna/screens/apy_screen.dart | 113 +++++++++ .../yojna/screens/gov_scheme_screen.dart | 15 +- .../yojna/screens/pm_main_screen.dart | 36 ++- .../yojna/screens/pmjjby_enquiry_screen.dart | 215 ++++++++++++++++++ lib/features/yojna/screens/pmjjby_screen.dart | 100 +++++++- .../yojna/screens/pmsby_enquiry_screen.dart | 215 ++++++++++++++++++ lib/features/yojna/screens/pmsby_screen.dart | 99 +++++++- 8 files changed, 814 insertions(+), 14 deletions(-) create mode 100644 lib/features/yojna/screens/pmjjby_enquiry_screen.dart create mode 100644 lib/features/yojna/screens/pmsby_enquiry_screen.dart diff --git a/lib/api/services/yojna_service.dart b/lib/api/services/yojna_service.dart index 875cecc..9440048 100644 --- a/lib/api/services/yojna_service.dart +++ b/lib/api/services/yojna_service.dart @@ -175,4 +175,39 @@ String? policystatus, ); return response.toString(); } + + Future enquiry({ + required String scheme, + required String action, + required String financialyear, + String? customerno, + }) async { + try { + final response = await _dio.get( + "/api/gov-scheme/enquiry/PMJBY", + queryParameters: { + 'scheme': scheme, + 'action': action, + 'financialyear': financialyear, + 'customerno': customerno, + }, + options: Options( + headers: { + "Content-Type": "application/json", + }, + ), + ); + + log("PMY Details Response: ${response.data}"); + + if (response.statusCode == 200) { + return response.data; + } else { + throw Exception("INTERNAL SERVER ERROR"); + } + } catch (e) { + log("Error fetching PMY details: $e"); + return null; + } + } } \ No newline at end of file diff --git a/lib/features/yojna/screens/apy_screen.dart b/lib/features/yojna/screens/apy_screen.dart index e69de29..fc55650 100644 --- a/lib/features/yojna/screens/apy_screen.dart +++ b/lib/features/yojna/screens/apy_screen.dart @@ -0,0 +1,113 @@ +import 'package:flutter/material.dart'; +import 'package:kmobile/data/models/user.dart'; +import 'package:kmobile/l10n/app_localizations.dart'; + +class APYScreen extends StatefulWidget { + final List users; + final int selectedIndex; + const APYScreen({ + super.key, + required this.users, + required this.selectedIndex, + }); + + @override + State createState() => _APYScreenState(); +} + +class _APYScreenState extends State { + User? _selectedAccount; + List _filteredUsers = []; + + @override + void initState() { + super.initState(); + _filteredUsers = widget.users + .where((user) => ['SA', 'SB', 'CA', 'CC'].contains(user.accountType)) + .toList(); + + // Pre-fill the account number if possible + if (widget.users.isNotEmpty && widget.selectedIndex < widget.users.length) { + if (_filteredUsers.isNotEmpty) { + if (_filteredUsers.contains(widget.users[widget.selectedIndex])) { + _selectedAccount = widget.users[widget.selectedIndex]; + } else { + _selectedAccount = _filteredUsers.first; + } + } else { + _selectedAccount = widget.users[widget.selectedIndex]; + } + } else { + if (_filteredUsers.isNotEmpty) { + _selectedAccount = _filteredUsers.first; + } + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('APY registration'), + centerTitle: false, + ), + body: SingleChildScrollView( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Card( + elevation: 2, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Text( + "Atal Pension Yojana (APY) is a periodic contribution-based pension scheme for citizens of India.", + style: Theme.of(context).textTheme.titleMedium, + ), + ), + ), + const SizedBox(height: 16), + Card( + elevation: 2, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + DropdownButtonFormField( + value: _selectedAccount, + decoration: InputDecoration( + labelText: AppLocalizations.of(context).accountNumber, + border: const OutlineInputBorder(), + contentPadding: const EdgeInsets.symmetric( + vertical: 20, horizontal: 12), + ), + items: _filteredUsers.map((user) { + return DropdownMenuItem( + value: user, + child: Text(user.accountNo.toString()), + ); + }).toList(), + onChanged: (User? newUser) { + setState(() { + _selectedAccount = newUser; + }); + }, + validator: (value) { + if (value == null) { + return AppLocalizations.of(context) + .accountNumberRequired; + } + return null; + }, + ), + ], + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/features/yojna/screens/gov_scheme_screen.dart b/lib/features/yojna/screens/gov_scheme_screen.dart index 8857537..46b7136 100644 --- a/lib/features/yojna/screens/gov_scheme_screen.dart +++ b/lib/features/yojna/screens/gov_scheme_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:kmobile/data/models/user.dart'; +import 'package:kmobile/features/yojna/screens/apy_screen.dart'; import 'package:kmobile/features/yojna/screens/pm_main_screen.dart'; import '../../../l10n/app_localizations.dart'; @@ -51,10 +52,18 @@ class _GovSchemeScreenState extends State { Expanded( child: GovSchemeTile( logoText: "APY", - label: "Atal Pension Yojana", - subtitle: "Secure your future with Atal Pension Yojana (APY) retirement scheme", + label: "Register for Atal Pension Yojana", + subtitle: "Secure your future with Atal Pension Yojana (APY) retirement scheme. Register in a few steps.", onTap: () { - // Action for APY will be added later + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => APYScreen( + users: widget.users, + selectedIndex: widget.selectedIndex, + ), + ), + );// Action for APY will be added later }, ), ), diff --git a/lib/features/yojna/screens/pm_main_screen.dart b/lib/features/yojna/screens/pm_main_screen.dart index a9fefc2..67d6f2f 100644 --- a/lib/features/yojna/screens/pm_main_screen.dart +++ b/lib/features/yojna/screens/pm_main_screen.dart @@ -4,6 +4,8 @@ import 'package:kmobile/data/models/user.dart'; import 'package:kmobile/di/injection.dart'; import 'package:kmobile/features/yojna/screens/pmjjby_screen.dart'; import 'package:kmobile/features/yojna/screens/pmsby_screen.dart'; +import 'package:kmobile/features/yojna/screens/pmjjby_enquiry_screen.dart'; +import 'package:kmobile/features/yojna/screens/pmsby_enquiry_screen.dart'; import 'package:kmobile/l10n/app_localizations.dart'; class PMMainScreen extends StatefulWidget { @@ -132,6 +134,35 @@ class _PMMainScreenState extends State { } } + void _handleEnquiry() { + if (_selectedAccount == null) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Please select account number')), + ); + return; + } + + if (_selectedScheme == null) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Please select a scheme first')), + ); + return; + } + + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + if (_selectedScheme!.contains('PMJJBY')) { + return PMJJBYEnquiryScreen(cifNumber: _selectedAccount!.cifNumber); + } else { + return PMSBYEnquiryScreen(cifNumber: _selectedAccount!.cifNumber); + } + }, + ), + ); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -265,9 +296,7 @@ class _PMMainScreenState extends State { const SizedBox(width: 16), Expanded( child: ElevatedButton( - onPressed: () { - // Action for Enquiry button - }, + onPressed: _handleEnquiry, style: ElevatedButton.styleFrom( backgroundColor: Theme.of(context).colorScheme.primaryContainer, @@ -293,3 +322,4 @@ class _PMMainScreenState extends State { ); } } + diff --git a/lib/features/yojna/screens/pmjjby_enquiry_screen.dart b/lib/features/yojna/screens/pmjjby_enquiry_screen.dart new file mode 100644 index 0000000..2d8de92 --- /dev/null +++ b/lib/features/yojna/screens/pmjjby_enquiry_screen.dart @@ -0,0 +1,215 @@ +import 'package:flutter/material.dart'; +import 'package:kmobile/api/services/yojna_service.dart'; +import 'package:kmobile/di/injection.dart'; + +class PMJJBYEnquiryScreen extends StatefulWidget { + final String? cifNumber; + + const PMJJBYEnquiryScreen({ + super.key, + required this.cifNumber, + }); + + @override + State createState() => _PMJJBYEnquiryScreenState(); +} + +class _PMJJBYEnquiryScreenState extends State { + String? _selectedFinancialYear; + bool _isLoading = false; + Map? _enquiryData; + String? _errorMessage; + + final List _financialYears = [ + '2021-2022', + '2022-2023', + '2023-2024', + '2024-2025', + '2025-2026', + ]; + + @override + void initState() { + super.initState(); + _selectedFinancialYear = null; + } + + Future _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().enquiry( + scheme: '02', + action: 'E', + financialyear: formattedYear, + customerno: widget.cifNumber, + ); + + setState(() { + if (response is Map) { + 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; + } 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('PMJJBY 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( + 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( + 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']), + _buildDetailRow('Account Number', _enquiryData!['accountno']), + _buildDetailRow('Premium Amount', _enquiryData!['preimiumamount']), + _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, + ), + ), + ], + ), + ); + } +} diff --git a/lib/features/yojna/screens/pmjjby_screen.dart b/lib/features/yojna/screens/pmjjby_screen.dart index 0bb726d..80bd008 100644 --- a/lib/features/yojna/screens/pmjjby_screen.dart +++ b/lib/features/yojna/screens/pmjjby_screen.dart @@ -33,6 +33,48 @@ class _PMJJBYScreenState extends State { late final _policyNumberController = TextEditingController(text: widget.initialData?['policynumber']?.toString()); late final _premiumAmountController = TextEditingController(text: widget.initialData?['premiumamount']?.toString()); late final _stateController = TextEditingController(text: widget.initialData?['state']?.toString()); + + // Mapping options + final Map _healthStatusOptions = { + '1': 'Excellent', + '2': 'Good', + '3': 'Bad', + }; + + final Map _relationshipOptions = { + '01': 'Self', + '02': 'Wife', + '03': 'Father', + '04': 'Mother', + '05': 'Son', + '06': 'Daughter', + '07': 'Brother', + '08': 'Sister', + '09': 'Father-in-law', + '10': 'Mother-in-law', + '11': 'Grandson', + '12': 'Granddaughter', + '13': 'Grandfather', + '14': 'Grandmother', + '15': 'Brother-in-law', + '16': 'Sister-in-law', + '17': 'Husband', + '18': 'Guardian', + '99': 'Others', + }; + + final Map _minorOptions = { + 'Y': 'Yes', + 'N': 'No', + }; + + final Map _ruralOptions = { + 'R': 'Rural', + 'U': 'Urban', + 'S': 'Semi-Urban', + 'M': 'Metro', + }; + final _healthStatusController = TextEditingController(); final _collectionChannelController = TextEditingController(); final _nomineeNameController = TextEditingController(); @@ -41,6 +83,26 @@ class _PMJJBYScreenState extends State { final _nomineeMinorController = TextEditingController(); final _ruralCategoryController = TextEditingController(); + @override + void initState() { + super.initState(); + // Initialize dropdown controllers if data exists in initialData + if (widget.initialData != null) { + if (widget.initialData!.containsKey('ruralcategory')) { + _ruralCategoryController.text = widget.initialData!['ruralcategory'].toString(); + } + if (widget.initialData!.containsKey('healthstatus')) { + _healthStatusController.text = widget.initialData!['healthstatus'].toString(); + } + if (widget.initialData!.containsKey('nomineerelationship')) { + _nomineeRelationshipController.text = widget.initialData!['nomineerelationship'].toString(); + } + if (widget.initialData!.containsKey('nomineeminor')) { + _nomineeMinorController.text = widget.initialData!['nomineeminor'].toString(); + } + } + } + @override void dispose() { _aadhaarController.dispose(); @@ -180,22 +242,22 @@ class _PMJJBYScreenState extends State { _buildTextField(_pincodeController, 'Pincode', keyboardType: TextInputType.number, readOnly: _isFetched('pincode')), _buildTextField(_stateController, 'State', readOnly: _isFetched('state')), _buildTextField(_countryController, 'Country', readOnly: _isFetched('country')), - _buildTextField(_ruralCategoryController, 'Rural Category'), + _buildDropdownField(_ruralCategoryController, 'Rural Category', _ruralOptions, readOnly: _isFetched('ruralcategory')), const Divider(height: 32), const Text('Policy Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), _buildTextField(_policyNumberController, 'Policy Number', readOnly: _isFetched('policynumber')), _buildTextField(_premiumAmountController, 'Premium Amount', keyboardType: TextInputType.number, readOnly: _isFetched('premiumamount')), _buildTextField(_financialYearController, 'Financial Year', readOnly: _isFetched('financialyear')), - _buildTextField(_healthStatusController, 'Health Status'), + _buildDropdownField(_healthStatusController, 'Health Status', _healthStatusOptions), _buildTextField(_collectionChannelController, 'Collection Channel'), const Divider(height: 32), const Text('Nominee Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), _buildTextField(_nomineeNameController, 'Nominee Name'), _buildTextField(_nomineeAddressController, 'Nominee Address'), - _buildTextField(_nomineeRelationshipController, 'Nominee Relationship'), - _buildTextField(_nomineeMinorController, 'Nominee Minor (Yes/No)'), + _buildDropdownField(_nomineeRelationshipController, 'Nominee Relationship', _relationshipOptions, readOnly: _isFetched('nomineerelationship')), + _buildDropdownField(_nomineeMinorController, 'Nominee Minor', _minorOptions, readOnly: _isFetched('nomineeminor')), const SizedBox(height: 24), ElevatedButton( onPressed: _handleRegister, @@ -220,6 +282,36 @@ class _PMJJBYScreenState extends State { ); } + Widget _buildDropdownField( + TextEditingController controller, String label, Map options, + {bool readOnly = false}) { + // Determine current value + String? currentValue = options.containsKey(controller.text) ? controller.text : null; + + return Padding( + padding: const EdgeInsets.only(bottom: 16.0), + child: DropdownButtonFormField( + value: currentValue, + onChanged: readOnly ? null : (newValue) { + setState(() { + controller.text = newValue ?? ''; + }); + }, + decoration: InputDecoration( + labelText: label, + border: const OutlineInputBorder(), + contentPadding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12), + ), + items: options.entries.map((entry) { + return DropdownMenuItem( + value: entry.key, + child: Text("${entry.key} - ${entry.value}"), + ); + }).toList(), + ), + ); + } + Widget _buildTextField(TextEditingController controller, String label, {TextInputType keyboardType = TextInputType.text, bool readOnly = false}) { return Padding( padding: const EdgeInsets.only(bottom: 16.0), diff --git a/lib/features/yojna/screens/pmsby_enquiry_screen.dart b/lib/features/yojna/screens/pmsby_enquiry_screen.dart new file mode 100644 index 0000000..63e3a37 --- /dev/null +++ b/lib/features/yojna/screens/pmsby_enquiry_screen.dart @@ -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 createState() => _PMSBYEnquiryScreenState(); +} + +class _PMSBYEnquiryScreenState extends State { + String? _selectedFinancialYear; + bool _isLoading = false; + Map? _enquiryData; + String? _errorMessage; + + final List _financialYears = [ + '2021-2022', + '2022-2023', + '2023-2024', + '2024-2025', + '2025-2026', + ]; + + @override + void initState() { + super.initState(); + _selectedFinancialYear = null; + } + + Future _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().enquiry( + scheme: '01', + action: 'E', + financialyear: formattedYear, + customerno: widget.cifNumber, + ); + + setState(() { + if (response is Map) { + 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; + } 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( + 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( + 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, + ), + ), + ], + ), + ); + } +} diff --git a/lib/features/yojna/screens/pmsby_screen.dart b/lib/features/yojna/screens/pmsby_screen.dart index eca685e..8116cd2 100644 --- a/lib/features/yojna/screens/pmsby_screen.dart +++ b/lib/features/yojna/screens/pmsby_screen.dart @@ -39,6 +39,47 @@ class _PMSBYScreenState extends State { late final _relationWithNomineeController = TextEditingController(text: widget.initialData?['relationwithnominee']?.toString()); late final _policyStatusController = TextEditingController(text: widget.initialData?['policystatus']?.toString()); + // Mapping options + final Map _healthStatusOptions = { + '1': 'Excellent', + '2': 'Good', + '3': 'Bad', + }; + + final Map _relationshipOptions = { + '01': 'Self', + '02': 'Wife', + '03': 'Father', + '04': 'Mother', + '05': 'Son', + '06': 'Daughter', + '07': 'Brother', + '08': 'Sister', + '09': 'Father-in-law', + '10': 'Mother-in-law', + '11': 'Grandson', + '12': 'Granddaughter', + '13': 'Grandfather', + '14': 'Grandmother', + '15': 'Brother-in-law', + '16': 'Sister-in-law', + '17': 'Husband', + '18': 'Guardian', + '99': 'Others', + }; + + final Map _minorOptions = { + 'Y': 'Yes', + 'N': 'No', + }; + + final Map _ruralOptions = { + 'R': 'Rural', + 'U': 'Urban', + 'S': 'Semi-Urban', + 'M': 'Metro', + }; + final _healthStatusController = TextEditingController(); final _collectionChannelController = TextEditingController(); final _nomineeNameController = TextEditingController(); @@ -47,6 +88,26 @@ class _PMSBYScreenState extends State { final _nomineeMinorController = TextEditingController(); final _ruralCategoryController = TextEditingController(); + @override + void initState() { + super.initState(); + // Initialize dropdown controllers if data exists in initialData + if (widget.initialData != null) { + if (widget.initialData!.containsKey('ruralcategory')) { + _ruralCategoryController.text = widget.initialData!['ruralcategory'].toString(); + } + if (widget.initialData!.containsKey('healthstatus')) { + _healthStatusController.text = widget.initialData!['healthstatus'].toString(); + } + if (widget.initialData!.containsKey('relationwithnominee')) { + _nomineeRelationshipController.text = widget.initialData!['relationwithnominee'].toString(); + } + if (widget.initialData!.containsKey('nomineeminor')) { + _nomineeMinorController.text = widget.initialData!['nomineeminor'].toString(); + } + } + } + @override void dispose() { _aadhaarController.dispose(); @@ -196,7 +257,7 @@ class _PMSBYScreenState extends State { _buildTextField(_pincodeController, 'Pincode', keyboardType: TextInputType.number, readOnly: _isFetched('pincode')), _buildTextField(_stateController, 'State', readOnly: _isFetched('state')), _buildTextField(_countryController, 'Country', readOnly: _isFetched('country')), - _buildTextField(_ruralCategoryController, 'Rural Category'), + _buildDropdownField(_ruralCategoryController, 'Rural Category', _ruralOptions, readOnly: _isFetched('ruralcategory')), const Divider(height: 32), const Text('Policy Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), @@ -204,16 +265,16 @@ class _PMSBYScreenState extends State { _buildTextField(_premiumAmountController, 'Premium Amount', keyboardType: TextInputType.number, readOnly: _isFetched('premiumamount')), _buildTextField(_financialYearController, 'Financial Year', readOnly: _isFetched('financialyear')), _buildTextField(_policyStatusController, 'Policy Status', readOnly: _isFetched('policystatus')), - _buildTextField(_healthStatusController, 'Health Status'), + _buildDropdownField(_healthStatusController, 'Health Status', _healthStatusOptions), _buildTextField(_collectionChannelController, 'Collection Channel'), const Divider(height: 32), const Text('Nominee Details', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const SizedBox(height: 16), _buildTextField(_nomineeNameController, 'Nominee Name'), _buildTextField(_nomineeAddressController, 'Nominee Address'), - _buildTextField(_relationWithNomineeController, 'Relation with Nominee', readOnly: _isFetched('relationwithnominee')), + _buildDropdownField(_relationWithNomineeController, 'Relation with Nominee', _relationshipOptions, readOnly: _isFetched('relationwithnominee')), _buildTextField(_nomineeRelationshipController, 'Nominee Relationship'), - _buildTextField(_nomineeMinorController, 'Nominee Minor (Yes/No)'), + _buildDropdownField(_nomineeMinorController, 'Nominee Minor', _minorOptions, readOnly: _isFetched('nomineeminor')), const SizedBox(height: 24), ElevatedButton( onPressed: _handleRegister, @@ -238,6 +299,36 @@ class _PMSBYScreenState extends State { ); } + Widget _buildDropdownField( + TextEditingController controller, String label, Map options, + {bool readOnly = false}) { + // Determine current value + String? currentValue = options.containsKey(controller.text) ? controller.text : null; + + return Padding( + padding: const EdgeInsets.only(bottom: 16.0), + child: DropdownButtonFormField( + value: currentValue, + onChanged: readOnly ? null : (newValue) { + setState(() { + controller.text = newValue ?? ''; + }); + }, + decoration: InputDecoration( + labelText: label, + border: const OutlineInputBorder(), + contentPadding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12), + ), + items: options.entries.map((entry) { + return DropdownMenuItem( + value: entry.key, + child: Text("${entry.key} - ${entry.value}"), + ); + }).toList(), + ), + ); + } + Widget _buildTextField(TextEditingController controller, String label, {TextInputType keyboardType = TextInputType.text, bool readOnly = false}) { return Padding( padding: const EdgeInsets.only(bottom: 16.0),