From 8ae26e2f18bdd8549fceef7663780be10533ac6a Mon Sep 17 00:00:00 2001 From: Nilanjan Chakrabarti Date: Mon, 11 Aug 2025 17:03:02 +0530 Subject: [PATCH] Payment Error Message and Beneficiary Page --- lib/api/services/neft_service.dart | 4 +- lib/api/services/rtgs_service.dart | 4 +- lib/app.dart | 1 - .../screens/add_beneficiary_screen.dart | 10 ++-- .../screens/manage_beneficiaries_screen.dart | 13 +++-- .../screens/fund_transfer_amount_screen.dart | 43 +++++++++++++++-- .../fund_transfer_beneficiary_screen.dart | 9 +++- .../screens/payment_animation.dart | 5 +- .../preferences/preference_screen.dart | 48 ++++++++++--------- .../quick_pay_outside_bank_screen.dart | 1 - .../screens/quick_pay_within_bank_screen.dart | 2 - lib/l10n/app_en.arb | 3 +- lib/l10n/app_hi.arb | 3 +- lib/l10n/app_localizations.dart | 6 +++ lib/l10n/app_localizations_en.dart | 3 ++ lib/l10n/app_localizations_hi.dart | 3 ++ 16 files changed, 111 insertions(+), 47 deletions(-) diff --git a/lib/api/services/neft_service.dart b/lib/api/services/neft_service.dart index 1b2a869..2641f2c 100644 --- a/lib/api/services/neft_service.dart +++ b/lib/api/services/neft_service.dart @@ -21,8 +21,8 @@ class NeftService { throw Exception( 'NEFT transaction failed with status code: ${response.statusCode}'); } - } on DioException catch (e) { - throw Exception('Failed to process NEFT transaction: ${e.message}'); + } on DioException { + rethrow; } catch (e) { throw Exception('An unexpected error occurred: ${e.toString()}'); } diff --git a/lib/api/services/rtgs_service.dart b/lib/api/services/rtgs_service.dart index b9014ad..303c325 100644 --- a/lib/api/services/rtgs_service.dart +++ b/lib/api/services/rtgs_service.dart @@ -22,8 +22,8 @@ class RtgsService { throw Exception( 'RTGS transaction failed with status code: ${response.statusCode}'); } - } on DioException catch (e) { - throw Exception('Failed to process RTGS transaction: ${e.message}'); + } on DioException { + rethrow ; } catch (e) { throw Exception('An unexpected error occurred: ${e.toString()}'); } diff --git a/lib/app.dart b/lib/app.dart index 5115ce2..5714d85 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -15,7 +15,6 @@ import 'features/auth/screens/welcome_screen.dart'; import 'features/auth/screens/login_screen.dart'; import 'features/service/screens/service_screen.dart'; import 'features/dashboard/screens/dashboard_screen.dart'; -import 'config/themes.dart'; import 'features/auth/screens/mpin_screen.dart'; import 'package:local_auth/local_auth.dart'; import 'package:shared_preferences/shared_preferences.dart'; diff --git a/lib/features/beneficiaries/screens/add_beneficiary_screen.dart b/lib/features/beneficiaries/screens/add_beneficiary_screen.dart index b5fafa8..f6a8b58 100644 --- a/lib/features/beneficiaries/screens/add_beneficiary_screen.dart +++ b/lib/features/beneficiaries/screens/add_beneficiary_screen.dart @@ -1,10 +1,9 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_svg/svg.dart'; import 'package:kmobile/api/services/beneficiary_service.dart'; -import 'package:kmobile/data/models/ifsc.dart'; import 'package:kmobile/data/models/beneficiary.dart'; -import 'package:kmobile/data/models/user.dart'; import 'beneficiary_result_page.dart'; import 'package:material_symbols_icons/material_symbols_icons.dart'; import '../../../di/injection.dart'; @@ -36,12 +35,11 @@ class _AddBeneficiaryScreen extends State { final TextEditingController phoneController = TextEditingController(); final service = getIt(); - String? _beneficiaryName; bool _isValidating = false; bool _isBeneficiaryValidated = false; + // ignore: unused_field String? _validationError; late String accountType; - final String _selectedAccountType = 'Savings'; // default value @override void initState() { @@ -335,6 +333,10 @@ class _AddBeneficiaryScreen extends State { // ЁЯФ╣ IFSC Code Field TextFormField( controller: ifscController, + maxLength: 11, + inputFormatters: [ + LengthLimitingTextInputFormatter(11), + ], decoration: InputDecoration( labelText: AppLocalizations.of(context).ifscCode, border: const OutlineInputBorder(), diff --git a/lib/features/beneficiaries/screens/manage_beneficiaries_screen.dart b/lib/features/beneficiaries/screens/manage_beneficiaries_screen.dart index 9ab4be6..ba4a6cd 100644 --- a/lib/features/beneficiaries/screens/manage_beneficiaries_screen.dart +++ b/lib/features/beneficiaries/screens/manage_beneficiaries_screen.dart @@ -61,13 +61,20 @@ class _ManageBeneficiariesScreen extends State { } Widget _getBankLogo(String? bankName) { - if (bankName != null && bankName.toLowerCase().contains('state bank of india')) { + if (bankName != null && bankName.toLowerCase().contains('state bank')) { return Image.asset( 'assets/images/sbi_logo.png', width: 40, height: 40, ); } + if (bankName != null && bankName.toLowerCase().contains('kangra central')) { + return Image.asset( + 'assets/images/icon.png', + width: 40, + height: 40, + ); + } if (bankName != null && bankName.toLowerCase().contains('hdfc bank ltd')) { return Image.asset( 'assets/images/hdfc_logo.png', @@ -113,11 +120,11 @@ class _ManageBeneficiariesScreen extends State { backgroundColor: Colors.transparent, child: _getBankLogo(item.bankName), ), - title: Text(item.name ?? 'Unknown'), + title: Text(item.name), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(item.accountNo ?? 'No account number'), + Text(item.accountNo), if (item.bankName != null && item.bankName!.isNotEmpty) Text( item.bankName!, diff --git a/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart b/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart index f3cee23..4367356 100644 --- a/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart +++ b/lib/features/fund_transfer/screens/fund_transfer_amount_screen.dart @@ -1,7 +1,8 @@ import 'dart:async'; +import 'dart:convert'; +import 'package:dio/dio.dart'; 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'; @@ -119,10 +120,28 @@ class _FundTransferAmountScreenState extends State { utr: neftResponse.utr, ); completer.complete(paymentResponse); + } on DioException catch(e) { + print('dio exception'); + print(e.toString()); + + final error = jsonDecode(e.response.toString())['error']; + var errorMessage = + { + "INCORRECT_TPIN" : "Please Enter the correct TPIN", + "INSUFFICIENT_FUNDS": "Your account does not have sufficient balance" + }[error] ?? "Something Went Wrong"; + + final paymentResponse = PaymentResponse( + isSuccess: false, + errorMessage: errorMessage, + ); + completer.complete(paymentResponse); } catch (e) { + print('generic exception'); + print(e.toString()); final paymentResponse = PaymentResponse( isSuccess: false, - errorMessage: e.toString(), + errorMessage: "Something went Wrong", ); completer.complete(paymentResponse); } @@ -158,10 +177,28 @@ class _FundTransferAmountScreenState extends State { utr: rtgsResponse.utr, ); completer.complete(paymentResponse); + } on DioException catch(e) { + print('dio exception'); + print(e.toString()); + + final error = jsonDecode(e.response.toString())['error']; + var errorMessage = + { + "INCORRECT_TPIN" : "Please Enter the correct TPIN", + "INSUFFICIENT_FUNDS": "Your account does not have sufficient balance" + }[error] ?? "Something Went Wrong"; + + final paymentResponse = PaymentResponse( + isSuccess: false, + errorMessage: errorMessage, + ); + completer.complete(paymentResponse); } catch (e) { + print('generic exception'); + print(e.toString()); final paymentResponse = PaymentResponse( isSuccess: false, - errorMessage: e.toString(), + errorMessage: "Something went Wrong", ); completer.complete(paymentResponse); } diff --git a/lib/features/fund_transfer/screens/fund_transfer_beneficiary_screen.dart b/lib/features/fund_transfer/screens/fund_transfer_beneficiary_screen.dart index be9a997..9d18a05 100644 --- a/lib/features/fund_transfer/screens/fund_transfer_beneficiary_screen.dart +++ b/lib/features/fund_transfer/screens/fund_transfer_beneficiary_screen.dart @@ -154,12 +154,19 @@ class _FundTransferBeneficiaryScreenState } Widget _getBankLogo(String? bankName) { - if (bankName != null && bankName.toLowerCase().contains('state bank of india')) { + if (bankName != null && bankName.toLowerCase().contains('state bank ')) { return Image.asset( 'assets/images/sbi_logo.png', width: 40, height: 40, ); + } + if (bankName != null && bankName.toLowerCase().contains('kangra central')) { + return Image.asset( + 'assets/images/icon.png', + width: 40, + height: 40, + ); } if (bankName != null && bankName.toLowerCase().contains('hdfc bank ltd')) { return Image.asset( diff --git a/lib/features/fund_transfer/screens/payment_animation.dart b/lib/features/fund_transfer/screens/payment_animation.dart index 329d3fd..320fd24 100644 --- a/lib/features/fund_transfer/screens/payment_animation.dart +++ b/lib/features/fund_transfer/screens/payment_animation.dart @@ -397,9 +397,8 @@ class _PaymentAnimationScreenState extends State { ), const SizedBox(height: 16), if (response.errorMessage != null) - Text( - response.errorMessage!, - style: const TextStyle(fontSize: 16), + Text(response.errorMessage ?? '', + style: TextStyle(fontSize: 16), ), ], ), diff --git a/lib/features/profile/preferences/preference_screen.dart b/lib/features/profile/preferences/preference_screen.dart index b3bd8ee..e09e49b 100644 --- a/lib/features/profile/preferences/preference_screen.dart +++ b/lib/features/profile/preferences/preference_screen.dart @@ -21,28 +21,6 @@ class PreferenceScreen extends StatelessWidget { builder: (context, state) { return ListView( children: [ - // Theme Mode Switch (Light/Dark) - // ListTile( - // leading: const Icon(Icons.brightness_6), - // title: const Text("Theme Mode"), - // trailing: Switch( - // value: state.isDarkMode, - // onChanged: (val) { - // context.read().toggleDarkMode(val); - // }, - // ), - // ), - //Color_Theme_Selection - ListTile( - leading: const Icon(Icons.color_lens), - title: Text(AppLocalizations.of(context).themeColor), - onTap: () { - showDialog( - context: context, - builder: (_) => const ColorThemeDialog(), - ); - } - ), // Language Selection ListTile( leading: const Icon(Icons.language), @@ -54,7 +32,31 @@ class PreferenceScreen extends StatelessWidget { ); }, ), - ], + //Theme Mode Switch (Light/Dark) + ListTile( + leading: const Icon(Icons.brightness_6), + title: Text(AppLocalizations.of(context).themeMode), + enabled: false, + //trailing: Switch( + // value: state.isDarkMode, + // onChanged: (val) { + // context.read().toggleDarkMode(val); + // }, + //), + ), + //Color_Theme_Selection + ListTile( + leading: const Icon(Icons.color_lens), + title: Text(AppLocalizations.of(context).themeColor), + enabled: false, + onTap: () { + showDialog( + context: context, + builder: (_) => const ColorThemeDialog(), + ); + } + ), + ], ); }, ), diff --git a/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart b/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart index 2c193be..7132450 100644 --- a/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart +++ b/lib/features/quick_pay/screens/quick_pay_outside_bank_screen.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'package:dio/dio.dart'; import 'package:kmobile/api/services/neft_service.dart'; import 'package:kmobile/api/services/rtgs_service.dart'; import 'package:kmobile/data/models/neft_transaction.dart'; diff --git a/lib/features/quick_pay/screens/quick_pay_within_bank_screen.dart b/lib/features/quick_pay/screens/quick_pay_within_bank_screen.dart index d4b3b8e..7e16daa 100644 --- a/lib/features/quick_pay/screens/quick_pay_within_bank_screen.dart +++ b/lib/features/quick_pay/screens/quick_pay_within_bank_screen.dart @@ -4,14 +4,12 @@ import 'package:flutter_svg/svg.dart'; import 'package:flutter_swipe_button/flutter_swipe_button.dart'; import 'package:kmobile/api/services/beneficiary_service.dart'; import 'package:kmobile/api/services/payment_service.dart'; -import 'package:kmobile/data/models/payment_response.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:material_symbols_icons/material_symbols_icons.dart'; import '../../../l10n/app_localizations.dart'; import '../../fund_transfer/screens/transaction_pin_screen.dart'; -//import 'package:flutter_neumorphic/flutter_neumorphic.dart'; class QuickPayWithinBankScreen extends StatefulWidget { final String debitAccount; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index d2d55e3..8827f35 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -230,6 +230,7 @@ "beneficiaryAdditionFailed": "Beneficiary Addition Failed", "noBeneficiaryFound": "No beneficiaries found", "beneficiaryName": "Beneficiary Name", - "validateBeneficiary": "Validate Beneficiary" + "validateBeneficiary": "Validate Beneficiary", + "themeMode": "Theme Mode" } diff --git a/lib/l10n/app_hi.arb b/lib/l10n/app_hi.arb index 68b0420..91a3d8f 100644 --- a/lib/l10n/app_hi.arb +++ b/lib/l10n/app_hi.arb @@ -230,5 +230,6 @@ "beneficiaryAdditionFailed": "рд▓рд╛рднрд╛рд░реНрдереА рдЬреЛрдбрд╝рдиреЗ рдореЗрдВ рд╡рд┐рдлрд▓", "noBeneficiaryFound": "рдХреЛрдИ рд▓рд╛рднрд╛рд░реНрдереА рдирд╣реАрдВ рдорд┐рд▓рд╛", "beneficiaryName": "рд▓рд╛рднрд╛рд░реНрдереА рдирд╛рдо", - "validateBeneficiary": "рд▓рд╛рднрд╛рд░реНрдереА рдХреЛ рд╕рддреНрдпрд╛рдкрд┐рдд рдХрд░реЗрдВ" + "validateBeneficiary": "рд▓рд╛рднрд╛рд░реНрдереА рдХреЛ рд╕рддреНрдпрд╛рдкрд┐рдд рдХрд░реЗрдВ", + "themeMode": "рдереАрдо рдореЛрдб" } diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index cb05464..16b428d 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -1408,6 +1408,12 @@ abstract class AppLocalizations { /// In en, this message translates to: /// **'Validate Beneficiary'** String get validateBeneficiary; + + /// No description provided for @themeMode. + /// + /// In en, this message translates to: + /// **'Theme Mode'** + String get themeMode; } class _AppLocalizationsDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 645907e..3b8c685 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -664,4 +664,7 @@ class AppLocalizationsEn extends AppLocalizations { @override String get validateBeneficiary => 'Validate Beneficiary'; + + @override + String get themeMode => 'Theme Mode'; } diff --git a/lib/l10n/app_localizations_hi.dart b/lib/l10n/app_localizations_hi.dart index 1528854..92f98cc 100644 --- a/lib/l10n/app_localizations_hi.dart +++ b/lib/l10n/app_localizations_hi.dart @@ -664,4 +664,7 @@ class AppLocalizationsHi extends AppLocalizations { @override String get validateBeneficiary => 'рд▓рд╛рднрд╛рд░реНрдереА рдХреЛ рд╕рддреНрдпрд╛рдкрд┐рдд рдХрд░реЗрдВ'; + + @override + String get themeMode => 'рдереАрдо рдореЛрдб'; }