Add Beneficiary Animations

This commit is contained in:
2025-08-07 21:07:32 +05:30
parent 2dd7f4079b
commit a1365b19d5

View File

@@ -28,7 +28,7 @@ class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
final TextEditingController phoneController = TextEditingController(); final TextEditingController phoneController = TextEditingController();
bool _isLoading2 = false;
late String accountType; late String accountType;
@override @override
@@ -41,46 +41,10 @@ class _AddBeneficiaryScreen extends State<AddBeneficiaryScreen> {
}); });
} }
/*void _submitForm() {
if (_formKey.currentState!.validate()) {
// Handle successful submission
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.grey[900],
behavior: SnackBarBehavior.floating,
margin: const EdgeInsets.all(12),
duration: const Duration(seconds: 5),
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
AppLocalizations.of(context).beneficiaryAdded,
style: TextStyle(color: Theme.of(context).dialogBackgroundColor),
),
),
TextButton(
onPressed: () {
// Navigate to Payment Screen or do something
},
style: TextButton.styleFrom(foregroundColor: Theme.of(context).primaryColorLight),
child: Text(AppLocalizations.of(context).payNow),
),
IconButton(
icon: Icon(Icons.close, color: Theme.of(context).scaffoldBackgroundColor),
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
],
),
),
);
}
}*/
ifsc? _ifscData; ifsc? _ifscData;
bool _isLoading = false; bool _isLoading = false; //for validateIFSC()
void _validateIFSC() async { void _validateIFSC() async {
var beneficiaryService = getIt<BeneficiaryService>(); var beneficiaryService = getIt<BeneficiaryService>();
@@ -114,10 +78,20 @@ bool _isLoading = false;
String _selectedAccountType = 'Savings'; // default value String _selectedAccountType = 'Savings'; // default value
void validateAndAddBeneficiary() async { void validateAndAddBeneficiary() async {
setState(() { // Show spinner and disable UI
_isLoading = true; showDialog(
}); context: context,
barrierDismissible: false, // Prevent dismiss on tap outside
builder: (BuildContext context) {
return WillPopScope(
onWillPop: () async => false, // Disable back button
child: const Center(
child: CircularProgressIndicator(),
),
);
},
);
final beneficiary = Beneficiary( final beneficiary = Beneficiary(
accountNo: accountNumberController.text.trim(), accountNo: accountNumberController.text.trim(),
@@ -133,6 +107,7 @@ bool _isLoading = false;
bool isFound = await service.checkIfFound(beneficiary.accountNo); bool isFound = await service.checkIfFound(beneficiary.accountNo);
if (context.mounted) { if (context.mounted) {
Navigator.pop(context); // Close the spinner
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
@@ -141,15 +116,10 @@ bool _isLoading = false;
); );
} }
} catch (e) { } catch (e) {
Navigator.pop(context); // Close the spinner
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Something went wrong during validation.")), const SnackBar(content: Text("Something went wrong during validation.")),
); );
} finally {
if (mounted) {
setState(() {
_isLoading2 = false;
});
}
} }
} }
@@ -466,7 +436,7 @@ bool _isLoading = false;
child: SizedBox( child: SizedBox(
width: 250, width: 250,
child: ElevatedButton( child: ElevatedButton(
onPressed: _isLoading2 ? null : onPressed:
validateAndAddBeneficiary, validateAndAddBeneficiary,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
shape: const StadiumBorder(), shape: const StadiumBorder(),