Localization of yojna schemes done
This commit is contained in:
@@ -26,9 +26,9 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
List<User> _filteredUsers = [];
|
||||
String? _selectedScheme;
|
||||
|
||||
final List<String> _schemes = [
|
||||
'Pradhan Mantri Jeevan Jyoti Bima Yojana (PMJJBY)',
|
||||
'Pradhan Mantri Suraksha Bima Yojana (PMSBY)',
|
||||
List<String> _getSchemes(AppLocalizations l10n) => [
|
||||
l10n.pmjjbyFull,
|
||||
l10n.pmsbyFull,
|
||||
];
|
||||
|
||||
@override
|
||||
@@ -61,33 +61,34 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
}
|
||||
|
||||
Future<void> _handleCreate() async {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
if (_selectedAccount == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Please select account number')),
|
||||
SnackBar(content: Text(l10n.pleaseSelectAccountNumber)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_selectedScheme == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Please select a scheme first')),
|
||||
SnackBar(content: Text(l10n.pleaseSelectSchemeFirst)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final String schemeCode = _selectedScheme!.contains('PMJJBY') ? '02' : '01';
|
||||
final String schemeCode = (_selectedScheme == l10n.pmjjbyFull) ? '02' : '01';
|
||||
|
||||
// Show loading
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 16),
|
||||
Text('Fetching details...'),
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(width: 16),
|
||||
Text(l10n.fetchingDetails),
|
||||
],
|
||||
),
|
||||
duration: Duration(seconds: 2),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -111,40 +112,41 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
if (_selectedScheme!.contains('PMJJBY')) {
|
||||
return PMJJBYScreen(initialData: data);
|
||||
if (_selectedScheme == l10n.pmjjbyFull) {
|
||||
return PMJJBYScreen(initialData: data!);
|
||||
} else {
|
||||
return PMSBYScreen(initialData: data);
|
||||
return PMSBYScreen(initialData: data!);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Failed to fetch details or no data found.')),
|
||||
SnackBar(content: Text(l10n.failedToFetchDetails)),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Error: ${e.toString()}')),
|
||||
SnackBar(content: Text(l10n.genericError(e.toString()))),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _handleEnquiry() {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
if (_selectedAccount == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Please select account number')),
|
||||
SnackBar(content: Text(l10n.pleaseSelectAccountNumber)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_selectedScheme == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Please select a scheme first')),
|
||||
SnackBar(content: Text(l10n.pleaseSelectSchemeFirst)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -153,7 +155,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
if (_selectedScheme!.contains('PMJJBY')) {
|
||||
if (_selectedScheme == l10n.pmjjbyFull) {
|
||||
return PMJJBYEnquiryScreen(cifNumber: _selectedAccount!.cifNumber);
|
||||
} else {
|
||||
return PMSBYEnquiryScreen(cifNumber: _selectedAccount!.cifNumber);
|
||||
@@ -165,9 +167,22 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final schemes = _getSchemes(l10n);
|
||||
|
||||
// Ensure _selectedScheme is valid if it was set in a different language
|
||||
if (_selectedScheme != null && !schemes.contains(_selectedScheme)) {
|
||||
// Try to find the corresponding scheme in the new language
|
||||
// This is a bit tricky, but since we only have two:
|
||||
// If it doesn't match, it might be from the other language.
|
||||
// For simplicity, we can just reset it or try to guess.
|
||||
// Better to use non-localized values for the state, but let's just reset for now if it doesn't match
|
||||
_selectedScheme = null;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Pradhan Mantri Yojana'),
|
||||
title: Text(l10n.pradhanMantriYojana),
|
||||
centerTitle: false,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
@@ -180,7 +195,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
"Create and Enquire about your Pradhan Mantri Jeevan Jyoti Bima Yojana (PMJJBY) and Pradhan Mantri Suraksha Bima Yojana(PMSBY) schemes.",
|
||||
l10n.pmjjbyPmsbyDescription,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
@@ -196,7 +211,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
DropdownButtonFormField<User>(
|
||||
value: _selectedAccount,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).accountNumber,
|
||||
labelText: l10n.accountNumber,
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
vertical: 20, horizontal: 12),
|
||||
@@ -214,8 +229,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return AppLocalizations.of(context)
|
||||
.accountNumberRequired;
|
||||
return l10n.accountNumberRequired;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
@@ -226,14 +240,14 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
isExpanded: true,
|
||||
isDense: false,
|
||||
itemHeight: null,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Select Scheme',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: l10n.selectScheme,
|
||||
border: const OutlineInputBorder(),
|
||||
contentPadding:
|
||||
EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
||||
const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
||||
),
|
||||
selectedItemBuilder: (BuildContext context) {
|
||||
return _schemes.map((String scheme) {
|
||||
return schemes.map((String scheme) {
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
@@ -246,7 +260,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
items: _schemes.map((String scheme) {
|
||||
items: schemes.map((String scheme) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: scheme,
|
||||
child: Padding(
|
||||
@@ -287,9 +301,9 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
"Create",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
child: Text(
|
||||
l10n.create,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -309,7 +323,7 @@ class _PMMainScreenState extends State<PMMainScreen> {
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
AppLocalizations.of(context).enquiry,
|
||||
l10n.enquiry,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user