feat: Implement major features and fix theming bug

This commit introduces several new features and a critical bug fix.

- Implemented a full "Quick Pay" flow for both within and outside the bank, including IFSC validation, beneficiary verification, and a TPIN-based payment process.
- Added a date range filter to the Account Statement screen and streamlined the UI by removing the amount filters.
- Fixed a major bug that prevented dynamic theme changes from being applied. The app now correctly switches between color themes.
- Refactored and improved beneficiary management, transaction models, and the fund transfer flow to support NEFT/RTGS.
This commit is contained in:
asif
2025-08-11 04:06:05 +05:30
parent 3024ddef15
commit f91d0f739b
34 changed files with 1638 additions and 911 deletions

View File

@@ -0,0 +1,309 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:kmobile/api/services/neft_service.dart';
import 'package:kmobile/api/services/rtgs_service.dart';
import 'package:kmobile/data/models/beneficiary.dart';
import 'package:kmobile/data/models/neft_transaction.dart';
import 'package:kmobile/data/models/payment_response.dart';
import 'package:kmobile/data/models/rtgs_transaction.dart';
import 'package:kmobile/di/injection.dart';
import 'package:kmobile/features/fund_transfer/screens/payment_animation.dart';
import 'package:kmobile/features/fund_transfer/screens/transaction_pin_screen.dart';
import '../../../l10n/app_localizations.dart';
enum TransactionMode { neft, rtgs }
class FundTransferAmountScreen extends StatefulWidget {
final String debitAccountNo;
final Beneficiary creditBeneficiary;
final String remitterName;
const FundTransferAmountScreen({
super.key,
required this.debitAccountNo,
required this.creditBeneficiary,
required this.remitterName,
});
@override
State<FundTransferAmountScreen> createState() =>
_FundTransferAmountScreenState();
}
class _FundTransferAmountScreenState extends State<FundTransferAmountScreen> {
final _amountController = TextEditingController();
final _formKey = GlobalKey<FormState>();
TransactionMode _selectedMode = TransactionMode.neft;
@override
void dispose() {
_amountController.dispose();
super.dispose();
}
Widget _getBankLogo(String? bankName) {
if (bankName != null && bankName.toLowerCase().contains('state bank of india')) {
return Image.asset(
'assets/images/sbi_logo.png',
width: 40,
height: 40,
);
} else {
return const Icon(
Icons.account_balance,
size: 40,
color: Colors.grey,
);
}
}
void _onProceed() {
if (_formKey.currentState!.validate()) {
final amount = double.tryParse(_amountController.text) ?? 0;
if (_selectedMode == TransactionMode.rtgs && amount < 200000) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Invalid Amount for RTGS'),
content: const Text(
'RTGS transactions require a minimum amount of 200,000. Please enter a higher amount or select NEFT as the transaction mode.'),
actions: [
TextButton(
onPressed: () => Navigator.of(ctx).pop(),
child: const Text('OK'),
),
],
),
);
return; // Stop further execution
}
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TransactionPinScreen(
onPinCompleted: (pinScreenContext, tpin) async {
if (_selectedMode == TransactionMode.neft) {
final neftTx = NeftTransaction(
fromAccount: widget.debitAccountNo,
toAccount: widget.creditBeneficiary.accountNo,
amount: _amountController.text,
ifscCode: widget.creditBeneficiary.ifscCode,
remitterName: widget.remitterName,
beneficiaryName: widget.creditBeneficiary.name,
tpin: tpin,
);
final neftService = getIt<NeftService>();
final completer = Completer<PaymentResponse>();
Navigator.of(pinScreenContext).pushReplacement(
MaterialPageRoute(
builder: (_) => PaymentAnimationScreen(
paymentResponse: completer.future),
),
);
try {
final neftResponse =
await neftService.processNeftTransaction(neftTx);
final paymentResponse = PaymentResponse(
isSuccess: neftResponse.message.toUpperCase() == 'SUCCESS',
date: DateTime.now(),
creditedAccount: neftTx.toAccount,
amount: neftTx.amount,
currency: 'INR',
utr: neftResponse.utr,
);
completer.complete(paymentResponse);
} catch (e) {
final paymentResponse = PaymentResponse(
isSuccess: false,
errorMessage: e.toString(),
);
completer.complete(paymentResponse);
}
} else {
final rtgsTx = RtgsTransaction(
fromAccount: widget.debitAccountNo,
toAccount: widget.creditBeneficiary.accountNo,
amount: _amountController.text,
ifscCode: widget.creditBeneficiary.ifscCode,
remitterName: widget.remitterName,
beneficiaryName: widget.creditBeneficiary.name,
tpin: tpin,
);
final rtgsService = getIt<RtgsService>();
final completer = Completer<PaymentResponse>();
Navigator.of(pinScreenContext).pushReplacement(
MaterialPageRoute(
builder: (_) => PaymentAnimationScreen(
paymentResponse: completer.future),
),
);
try {
final rtgsResponse =
await rtgsService.processRtgsTransaction(rtgsTx);
final paymentResponse = PaymentResponse(
isSuccess: rtgsResponse.message.toUpperCase() == 'SUCCESS',
date: DateTime.now(),
creditedAccount: rtgsTx.toAccount,
amount: rtgsTx.amount,
currency: 'INR',
utr: rtgsResponse.utr,
);
completer.complete(paymentResponse);
} catch (e) {
final paymentResponse = PaymentResponse(
isSuccess: false,
errorMessage: e.toString(),
);
completer.complete(paymentResponse);
}
}
},
),
),
);
}
}
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
title: Text(loc.fundTransfer),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Debit Account (User)
Text(
loc.debitFrom,
style: Theme.of(context).textTheme.titleSmall,
),
Card(
elevation: 0,
margin: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
leading: Image.asset(
'assets/images/logo.png',
width: 40,
height: 40,
),
title: Text(widget.remitterName),
subtitle: Text(widget.debitAccountNo),
),
),
const SizedBox(height: 24),
// Credit Account (Beneficiary)
Text(
"Credit To",
style: Theme.of(context).textTheme.titleSmall,
),
Card(
elevation: 0,
margin: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
leading: _getBankLogo(widget.creditBeneficiary.bankName),
title: Text(widget.creditBeneficiary.name),
subtitle: Text(widget.creditBeneficiary.accountNo),
),
),
const SizedBox(height: 24),
// Transaction Mode Selection
Text(
"Select Transaction Mode",
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 12),
Container(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey.shade300),
),
child: ToggleButtons(
isSelected: [
_selectedMode == TransactionMode.neft,
_selectedMode == TransactionMode.rtgs
],
onPressed: (index) {
setState(() {
_selectedMode = TransactionMode.values[index];
});
},
borderRadius: BorderRadius.circular(10),
selectedColor: Theme.of(context).colorScheme.onPrimary,
fillColor: Theme.of(context).primaryColor,
color: Theme.of(context).colorScheme.onSurface,
borderColor: Colors.transparent,
selectedBorderColor: Colors.transparent,
splashColor: Theme.of(context).primaryColor.withOpacity(0.1),
highlightColor: Theme.of(context).primaryColor.withOpacity(0.05),
children: const [
Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
child: Text('NEFT'),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
child: Text('RTGS'),
),
],
),
),
const SizedBox(height: 24),
// Amount
TextFormField(
controller: _amountController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: loc.amount,
border: const OutlineInputBorder(),
prefixIcon: const Icon(Icons.currency_rupee),
),
validator: (value) {
if (value == null || value.isEmpty) {
return loc.amountRequired;
}
if (double.tryParse(value) == null ||
double.parse(value) <= 0) {
return loc.validAmount;
}
return null;
},
),
const Spacer(),
// Proceed Button
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _onProceed,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
),
child: const Text("Proceed"),
),
),
],
),
),
),
);
}
}

View File

@@ -90,24 +90,26 @@ class _FundTransferBeneficiaryScreen
import 'package:flutter/material.dart';
import 'package:kmobile/data/models/beneficiary.dart';
//import 'package:kmobile/features/beneficiaries/screens/add_beneficiary_screen.dart';
import 'package:kmobile/features/fund_transfer/screens/fund_transfer_amount_screen.dart';
import '../../../l10n/app_localizations.dart';
import '../../../di/injection.dart';
import 'package:kmobile/api/services/beneficiary_service.dart';
import 'package:shimmer/shimmer.dart';
class FundTransferBeneficiaryScreen extends StatefulWidget {
const FundTransferBeneficiaryScreen({super.key});
final String creditAccountNo;
final String remitterName;
const FundTransferBeneficiaryScreen(
{super.key, required this.creditAccountNo, required this.remitterName});
@override
State<FundTransferBeneficiaryScreen> createState() =>
_ManageBeneficiariesScreen();
_FundTransferBeneficiaryScreenState();
}
class _ManageBeneficiariesScreen extends State<FundTransferBeneficiaryScreen> {
class _FundTransferBeneficiaryScreenState
extends State<FundTransferBeneficiaryScreen> {
var service = getIt<BeneficiaryService>();
//final BeneficiaryService _service = BeneficiaryService();
bool _isLoading = true;
List<Beneficiary> _beneficiaries = [];
@@ -120,7 +122,7 @@ class _ManageBeneficiariesScreen extends State<FundTransferBeneficiaryScreen> {
Future<void> _loadBeneficiaries() async {
final data = await service.fetchBeneficiaryList();
setState(() {
_beneficiaries = data ;
_beneficiaries = data;
_isLoading = false;
});
}
@@ -132,7 +134,7 @@ class _ManageBeneficiariesScreen extends State<FundTransferBeneficiaryScreen> {
baseColor: Colors.grey.shade300,
highlightColor: Colors.grey.shade100,
child: ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
radius: 24,
backgroundColor: Colors.white,
),
@@ -151,27 +153,61 @@ class _ManageBeneficiariesScreen extends State<FundTransferBeneficiaryScreen> {
);
}
Widget _getBankLogo(String? bankName) {
if (bankName != null && bankName.toLowerCase().contains('state bank of india')) {
return Image.asset(
'assets/images/sbi_logo.png',
width: 40,
height: 40,
);
} else {
return const Icon(
Icons.account_balance,
size: 40,
color: Colors.grey,
);
}
}
Widget _buildBeneficiaryList() {
if (_beneficiaries.isEmpty) {
return Center(child: Text(AppLocalizations.of(context).noBeneficiaryFound));
return Center(
child: Text(AppLocalizations.of(context).noBeneficiaryFound));
}
return ListView.builder(
itemCount: _beneficiaries.length,
itemBuilder: (context, index) {
final item = _beneficiaries[index];
final beneficiary = _beneficiaries[index];
return ListTile(
leading: CircleAvatar(
radius: 24,
backgroundColor: Theme.of(context).primaryColor.withOpacity(0.2),
child: Text(
item.name.isNotEmpty
? item.name[0].toUpperCase()
: '?',
style: const TextStyle(fontWeight: FontWeight.bold),
),
backgroundColor: Colors.transparent,
child: _getBankLogo(beneficiary.bankName),
),
title: Text(item.name ?? 'Unknown'),
subtitle: Text(item.accountNo ?? 'No account number'),
title: Text(beneficiary.name),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(beneficiary.accountNo),
if (beneficiary.bankName != null && beneficiary.bankName!.isNotEmpty)
Text(
beneficiary.bankName!,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FundTransferAmountScreen(
debitAccountNo: widget.creditAccountNo,
creditBeneficiary: beneficiary,
remitterName: widget.remitterName,
),
),
);
},
);
},
);

View File

@@ -375,6 +375,14 @@ class _PaymentAnimationScreenState extends State<PaymentAnimationScreen> {
"Date: ${response.date!.toLocal().toIso8601String()}",
style: const TextStyle(fontSize: 16),
),
if (response.utr != null && response.utr!.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
'UTR: ${response.utr}',
style: const TextStyle(fontSize: 16),
),
),
],
)
: Column(

View File

@@ -1,27 +1,24 @@
// ignore_for_file: unused_field
import '../../../l10n/app_localizations.dart';
import 'package:flutter/material.dart';
import 'package:kmobile/api/services/auth_service.dart';
import 'package:kmobile/api/services/payment_service.dart';
import 'package:kmobile/data/models/transfer.dart';
import 'package:kmobile/di/injection.dart';
import 'package:kmobile/features/fund_transfer/screens/payment_animation.dart';
import 'package:kmobile/features/fund_transfer/screens/tpin_prompt_screen.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';
import '../../../l10n/app_localizations.dart';
class TransactionPinScreen extends StatefulWidget {
final Transfer transactionData;
const TransactionPinScreen({super.key, required this.transactionData});
final Future<void> Function(BuildContext, String) onPinCompleted;
const TransactionPinScreen({super.key, required this.onPinCompleted});
@override
State<TransactionPinScreen> createState() => _TransactionPinScreen();
State<TransactionPinScreen> createState() => _TransactionPinScreenState();
}
class _TransactionPinScreen extends State<TransactionPinScreen> {
class _TransactionPinScreenState extends State<TransactionPinScreen> {
final List<String> _pin = [];
bool _loading = true;
bool _isSubmitting = false;
@override
void initState() {
@@ -55,6 +52,7 @@ class _TransactionPinScreen extends State<TransactionPinScreen> {
}
void _onKeyPressed(String value) {
if (_isSubmitting) return;
setState(() {
if (value == 'back') {
if (_pin.isNotEmpty) _pin.removeLast();
@@ -64,6 +62,27 @@ class _TransactionPinScreen extends State<TransactionPinScreen> {
});
}
Future<void> _submitPin() async {
if (_isSubmitting) return;
if (_pin.length == 6) {
setState(() => _isSubmitting = true);
try {
await widget.onPinCompleted(context, _pin.join());
} finally {
if (mounted) {
setState(() => _isSubmitting = false);
}
}
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context).enter6DigitTpin),
),
);
}
}
Widget _buildPinIndicators() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
@@ -75,7 +94,9 @@ class _TransactionPinScreen extends State<TransactionPinScreen> {
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Theme.of(context).primaryColor, width: 2),
color: index < _pin.length ? Theme.of(context).primaryColor : Colors.transparent,
color: index < _pin.length
? Theme.of(context).primaryColor
: Colors.transparent,
),
);
}),
@@ -85,30 +106,15 @@ class _TransactionPinScreen extends State<TransactionPinScreen> {
Widget _buildKey(String label, {IconData? icon}) {
return Expanded(
child: InkWell(
onTap: () async {
if (label == 'back') {
_onKeyPressed('back');
} else if (label == 'done') {
// Handle submit if needed
if (_pin.length == 6) {
await sendTransaction();
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context).enter6DigitTpin),
),
);
}
} else {
_onKeyPressed(label);
}
},
onTap: () => label == 'done' ? _submitPin() : _onKeyPressed(label),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Center(
child: icon != null
? Icon(icon, size: 28)
: Text(label, style: const TextStyle(fontSize: 24)),
child: _isSubmitting && label == 'done'
? const CircularProgressIndicator()
: icon != null
? Icon(icon, size: 28)
: Text(label, style: const TextStyle(fontSize: 24)),
),
),
),
@@ -133,30 +139,6 @@ class _TransactionPinScreen extends State<TransactionPinScreen> {
);
}
Future<void> sendTransaction() async {
final paymentService = getIt<PaymentService>();
final transfer = widget.transactionData;
transfer.tpin = _pin.join();
try {
final paymentResponse = paymentService.processQuickPayWithinBank(
transfer,
);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) =>
PaymentAnimationScreen(paymentResponse: paymentResponse),
),
);
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(e.toString())));
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -169,26 +151,28 @@ class _TransactionPinScreen extends State<TransactionPinScreen> {
),
title: Text(
AppLocalizations.of(context).tpin,
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w500),
),
centerTitle: false,
),
body: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: Column(
children: [
const Spacer(),
Text(
AppLocalizations.of(context).enterTpin,
style: TextStyle(fontSize: 18),
body: _loading
? const Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: Column(
children: [
const Spacer(),
Text(
AppLocalizations.of(context).enterTpin,
style: const TextStyle(fontSize: 18),
),
const SizedBox(height: 20),
_buildPinIndicators(),
const Spacer(),
_buildKeypad(),
],
),
),
const SizedBox(height: 20),
_buildPinIndicators(),
const Spacer(),
_buildKeypad(),
],
),
),
);
}
}