Manage Beneficiary UI

This commit is contained in:
2025-08-08 23:37:16 +05:30
parent 763c101f58
commit dbc61abf00
11 changed files with 249 additions and 145 deletions

View File

@@ -27,7 +27,10 @@ class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
final TextEditingController ifscController = TextEditingController();
final TextEditingController phoneController = TextEditingController();
String? _beneficiaryName;
bool _isValidating = false;
bool _isBeneficiaryValidated = false;
String? _validationError;
late String accountType;
@@ -75,6 +78,30 @@ bool _isLoading = false; //for validateIFSC()
}
}
Future<void> _validateBeneficiary() async {
var beneficiaryService = getIt<BeneficiaryService>();
setState(() {
_isValidating = true;
_validationError = null;
});
try {
final name = await beneficiaryService
.validateBeneficiaryWithinBank(accountNumberController.text);
setState(() {
_beneficiaryName = name;
_isBeneficiaryValidated = true;
_isValidating = false;
});
} catch (e) {
setState(() {
_validationError = "Account Number not from KCCB";
_isValidating = false;
_isBeneficiaryValidated = false;
_beneficiaryName = null;
});
}
}
String _selectedAccountType = 'Savings'; // default value
@@ -239,32 +266,6 @@ void validateAndAddBeneficiary() async {
return null;
},
),
const SizedBox(height: 24),
TextFormField(
controller: nameController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).name,
// prefixIcon: Icon(Icons.person),
border: OutlineInputBorder(),
isDense: true,
filled: true,
fillColor: Theme.of(context).dialogBackgroundColor,
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 2,
),
),
),
textInputAction: TextInputAction.next,
validator: (value) => value == null || value.isEmpty
? AppLocalizations.of(context).nameRequired
: null,
),
const SizedBox(height: 24),
// 🔹 IFSC Code Field
TextFormField(
@@ -347,10 +348,10 @@ void validateAndAddBeneficiary() async {
isDense: true,
filled: true,
fillColor: Theme.of(context).dialogBackgroundColor,
enabledBorder: OutlineInputBorder(
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
),
focusedBorder: OutlineInputBorder(
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 2,
@@ -359,20 +360,80 @@ void validateAndAddBeneficiary() async {
),
),
//validate Beneficiary Button
if (!_isBeneficiaryValidated)
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isValidating
? null
: () {
if (accountNumberController.text.length == 11 &&
confirmAccountNumberController.text ==
accountNumberController.text) {
_validateBeneficiary();
} else {
setState(() {
_validationError =
'Please enter a valid and matching account number.';
});
}
},
child: _isValidating
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Validate Beneficiary'),
),
),
),
//Beneficiary Name (Disabled)
const SizedBox(height: 24),
TextFormField(
controller: nameController,
enabled: false,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).beneficiaryName,
// prefixIcon: Icon(Icons.person),
border: const OutlineInputBorder(),
isDense: true,
filled: true,
fillColor: Theme.of(context).dialogBackgroundColor,
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 2,
),
),
),
textInputAction: TextInputAction.next,
validator: (value) => value == null || value.isEmpty
? AppLocalizations.of(context).nameRequired
: null,
),
const SizedBox(height: 24),
// 🔹 Account Type Dropdown
DropdownButtonFormField<String>(
value: accountType,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).accountType,
border: OutlineInputBorder(),
border: const OutlineInputBorder(),
isDense: true,
filled: true,
fillColor: Theme.of(context).scaffoldBackgroundColor,
enabledBorder: OutlineInputBorder(
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
),
focusedBorder: OutlineInputBorder(
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 2,
@@ -404,15 +465,15 @@ void validateAndAddBeneficiary() async {
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).phone,
prefixIcon: Icon(Icons.phone),
border: OutlineInputBorder(),
prefixIcon: const Icon(Icons.phone),
border: const OutlineInputBorder(),
isDense: true,
filled: true,
fillColor: Theme.of(context).scaffoldBackgroundColor,
enabledBorder: OutlineInputBorder(
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
),
focusedBorder: OutlineInputBorder(
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 2,

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:confetti/confetti.dart';
import 'dart:math';
import '../../../app.dart';
import '../../../l10n/app_localizations.dart';
class BeneficiaryResultPage extends StatefulWidget {
@@ -65,6 +66,34 @@ class _BeneficiaryResultPageState extends State<BeneficiaryResultPage> {
),
],
),
Positioned(
bottom: 20, // keep it slightly above the very bottom
left: 16,
right: 16,
child: SizedBox(
height: 56, // larger button height
child: ElevatedButton(
onPressed: () {
Navigator.pushReplacement( // ensures back goes to ScaffoldScreen
context,
MaterialPageRoute(
builder: (context) => const NavigationScaffold(),
),
);
},
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 12),
backgroundColor: Theme.of(context).primaryColorDark,
foregroundColor: Theme.of(context).scaffoldBackgroundColor,
),
child: Text(
AppLocalizations.of(context).done,
style: const TextStyle(fontSize: 18), // slightly bigger text
),
),
),
),
if (widget.isSuccess)
Align(
alignment: Alignment.topCenter,

View File

@@ -15,89 +15,6 @@ class ManageBeneficiariesScreen extends StatefulWidget {
_ManageBeneficiariesScreen();
}
/*class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
final List<Map<String, String>> beneficiaries = [
{'bank': 'State Bank Of India', 'name': 'Trina Bakshi'},
{'bank': 'State Bank Of India', 'name': 'Sheetal Rao'},
{'bank': 'Punjab National Bank', 'name': 'Manoj Kumar'},
{'bank': 'State Bank Of India', 'name': 'Rohit Mehra'},
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Symbols.arrow_back_ios_new),
onPressed: () {
Navigator.pop(context);
},
),
title: Text(
AppLocalizations.of(context).beneficiaries,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
),
centerTitle: false,
actions: [
Padding(
padding: const EdgeInsets.only(right: 10.0),
child: CircleAvatar(
backgroundColor: Colors.grey[200],
radius: 20,
child: SvgPicture.asset(
'assets/images/avatar_male.svg',
width: 40,
height: 40,
fit: BoxFit.cover,
),
),
),
],
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: beneficiaries.length,
itemBuilder: (context, index) {
final beneficiary = beneficiaries[index];
return ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context).primaryColor,
child: Text('A'),
),
title: Text(beneficiary['name']!),
subtitle: Text(beneficiary['bank']!),
trailing: IconButton(
icon: const Icon(Symbols.delete_forever, color: Colors.red),
onPressed: () {
// Delete action
},
),
);
},
),
),
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),
),
),
);
}
}
*/
class _ManageBeneficiariesScreen extends State<ManageBeneficiariesScreen> {
var service = getIt<BeneficiaryService>();
//final BeneficiaryService _service = BeneficiaryService();