114 lines
3.6 KiB
Dart
114 lines
3.6 KiB
Dart
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<User> users;
|
|
final int selectedIndex;
|
|
const APYScreen({
|
|
super.key,
|
|
required this.users,
|
|
required this.selectedIndex,
|
|
});
|
|
|
|
@override
|
|
State<APYScreen> createState() => _APYScreenState();
|
|
}
|
|
|
|
class _APYScreenState extends State<APYScreen> {
|
|
User? _selectedAccount;
|
|
List<User> _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<User>(
|
|
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<User>(
|
|
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;
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|