Cooldown Added in Beneficiary
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/cooldown.dart';
|
||||
import 'package:kmobile/widgets/bank_logos.dart';
|
||||
import 'package:kmobile/data/models/beneficiary.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/fund_transfer_amount_screen.dart';
|
||||
@@ -72,7 +73,8 @@ class _FundTransferBeneficiaryScreenState
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBeneficiaryList() {
|
||||
|
||||
Widget _buildBeneficiaryList() {
|
||||
if (_beneficiaries.isEmpty) {
|
||||
return Center(
|
||||
child: Text(AppLocalizations.of(context).noBeneficiaryFound));
|
||||
@@ -81,43 +83,79 @@ class _FundTransferBeneficiaryScreenState
|
||||
itemCount: _beneficiaries.length,
|
||||
itemBuilder: (context, index) {
|
||||
final beneficiary = _beneficiaries[index];
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
radius: 24,
|
||||
backgroundColor: Colors.transparent,
|
||||
child: getBankLogo(beneficiary.bankName, context),
|
||||
|
||||
// --- Cooldown Logic ---
|
||||
bool isCoolingDown = false;
|
||||
if (beneficiary.createdAt != null) {
|
||||
final sixtyMinutesAgo =
|
||||
DateTime.now().subtract(const Duration(minutes: 60));
|
||||
isCoolingDown = beneficiary.createdAt!.isAfter(sixtyMinutesAgo);
|
||||
}
|
||||
// --- End of Cooldown Logic ---
|
||||
|
||||
// By wrapping the ListTile in an Opacity widget, we can make it look
|
||||
// disabled while ensuring the onTap callback still works.
|
||||
return Opacity(
|
||||
opacity: isCoolingDown ? 0.5 : 1.0,
|
||||
child: ListTile(
|
||||
// REMOVED the 'enabled' property from here.
|
||||
leading: CircleAvatar(
|
||||
radius: 24,
|
||||
backgroundColor: Colors.transparent,
|
||||
child: getBankLogo(beneficiary.bankName, context),
|
||||
),
|
||||
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]),
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: isCoolingDown
|
||||
? CooldownTimer(
|
||||
createdAt: beneficiary.createdAt!,
|
||||
onTimerFinish: () {
|
||||
setState(() {});
|
||||
},
|
||||
)
|
||||
: null,
|
||||
onTap: () {
|
||||
if (isCoolingDown) {
|
||||
// This will now execute correctly on tap
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Beneficiary will be enabled after the cooldown period.'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => FundTransferAmountScreen(
|
||||
debitAccountNo: widget.creditAccountNo,
|
||||
creditBeneficiary: beneficiary,
|
||||
remitterName: widget.remitterName,
|
||||
isOwnBank: widget.isOwnBank,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
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,
|
||||
isOwnBank: widget.isOwnBank,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
||||
Reference in New Issue
Block a user