diff --git a/lib/features/beneficiaries/screens/add_beneficiary_screen.dart b/lib/features/beneficiaries/screens/add_beneficiary_screen.dart index 725cdb8..4d71f46 100644 --- a/lib/features/beneficiaries/screens/add_beneficiary_screen.dart +++ b/lib/features/beneficiaries/screens/add_beneficiary_screen.dart @@ -28,7 +28,7 @@ class _AddBeneficiaryScreen extends State { final TextEditingController phoneController = TextEditingController(); - bool _isLoading2 = false; + late String accountType; @override @@ -41,46 +41,10 @@ class _AddBeneficiaryScreen extends State { }); } - /*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; -bool _isLoading = false; +bool _isLoading = false; //for validateIFSC() void _validateIFSC() async { var beneficiaryService = getIt(); @@ -114,10 +78,20 @@ bool _isLoading = false; String _selectedAccountType = 'Savings'; // default value - void validateAndAddBeneficiary() async { - setState(() { - _isLoading = true; - }); +void validateAndAddBeneficiary() async { + // Show spinner and disable UI + 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( accountNo: accountNumberController.text.trim(), @@ -125,7 +99,7 @@ bool _isLoading = false; name: nameController.text.trim(), ifscCode: ifscController.text.trim(), ); - + var service = getIt(); try { @@ -133,6 +107,7 @@ bool _isLoading = false; bool isFound = await service.checkIfFound(beneficiary.accountNo); if (context.mounted) { + Navigator.pop(context); // Close the spinner Navigator.push( context, MaterialPageRoute( @@ -141,15 +116,10 @@ bool _isLoading = false; ); } } catch (e) { + Navigator.pop(context); // Close the spinner ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text("Something went wrong during validation.")), ); - } finally { - if (mounted) { - setState(() { - _isLoading2 = false; - }); - } } } @@ -466,7 +436,7 @@ bool _isLoading = false; child: SizedBox( width: 250, child: ElevatedButton( - onPressed: _isLoading2 ? null : + onPressed: validateAndAddBeneficiary, style: ElevatedButton.styleFrom( shape: const StadiumBorder(),