From 82e057d804d5198ca4a0f6779c4c6cd8da746b17 Mon Sep 17 00:00:00 2001 From: Nilanjan Chakrabarti Date: Thu, 11 Sep 2025 18:13:39 +0530 Subject: [PATCH] Mobile Number Implemented in OTP --- .../dashboard/screens/dashboard_screen.dart | 21 +++++++++++++------ .../screens/tpin_otp_screen.dart | 7 +++---- .../screens/tpin_prompt_screen.dart | 17 ++++++++++++--- .../change_password_screen.dart | 8 +++---- lib/features/profile/profile_screen.dart | 15 +++++++++---- lib/l10n/app_en.arb | 2 +- lib/l10n/app_hi.arb | 2 +- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/lib/features/dashboard/screens/dashboard_screen.dart b/lib/features/dashboard/screens/dashboard_screen.dart index 1ad530c..b3c9eb7 100644 --- a/lib/features/dashboard/screens/dashboard_screen.dart +++ b/lib/features/dashboard/screens/dashboard_screen.dart @@ -226,12 +226,21 @@ class _DashboardScreenState extends State { child: InkWell( borderRadius: BorderRadius.circular(20), onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const ProfileScreen(), - ), - ); + final authState = context.read().state; + String mobileNumberToPass = ''; + + if (authState is Authenticated) { + if (selectedAccountIndex >= 0 && selectedAccountIndex < authState.users.length) { + mobileNumberToPass = authState.users[selectedAccountIndex].mobileNo ?? ''; + } + } + + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ProfileScreen(mobileNumber: mobileNumberToPass), + ), + ); }, child: CircleAvatar( backgroundColor: Colors.grey[200], diff --git a/lib/features/fund_transfer/screens/tpin_otp_screen.dart b/lib/features/fund_transfer/screens/tpin_otp_screen.dart index 859608e..b26b10b 100644 --- a/lib/features/fund_transfer/screens/tpin_otp_screen.dart +++ b/lib/features/fund_transfer/screens/tpin_otp_screen.dart @@ -5,7 +5,8 @@ import 'package:kmobile/api/services/change_password_service.dart'; import 'package:kmobile/di/injection.dart'; class TpinOtpScreen extends StatefulWidget { - const TpinOtpScreen({super.key}); + final String mobileNumber; + const TpinOtpScreen({super.key, required this.mobileNumber}); @override State createState() => _TpinOtpScreenState(); @@ -49,10 +50,9 @@ void _verifyOtp() async { }); try { - // IMPORTANT: You may need to pass the mobile number here as well await _changePasswordService.validateOtp( otp: _enteredOtp, - mobileNumber: '8981274001', // Replace with actual mobile number + mobileNumber: widget.mobileNumber, ); if (mounted) { @@ -151,7 +151,6 @@ void _verifyOtp() async { ), const SizedBox(height: 32), ElevatedButton.icon( - // Update icon to show a loading indicator icon: _isLoading ? const SizedBox( width: 20, diff --git a/lib/features/fund_transfer/screens/tpin_prompt_screen.dart b/lib/features/fund_transfer/screens/tpin_prompt_screen.dart index b546b9e..0af4331 100644 --- a/lib/features/fund_transfer/screens/tpin_prompt_screen.dart +++ b/lib/features/fund_transfer/screens/tpin_prompt_screen.dart @@ -1,3 +1,7 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:kmobile/features/auth/controllers/auth_cubit.dart'; +import 'package:kmobile/features/auth/controllers/auth_state.dart'; + import '../../../l10n/app_localizations.dart'; import 'package:flutter/material.dart'; import 'package:kmobile/features/fund_transfer/screens/tpin_otp_screen.dart'; @@ -12,7 +16,7 @@ class TpinSetupPromptScreen extends StatefulWidget { } class _TpinSetupPromptScreenState extends State { - // 3. Add state variables + int selectedAccountIndex = 0; bool _isLoading = false; final ChangePasswordService _changePasswordService = getIt(); Future _getOtp() async { @@ -21,11 +25,18 @@ class TpinSetupPromptScreen extends StatefulWidget { }); try { - await _changePasswordService.getOtp(mobileNumber: '8981274001'); + final authState = context.read().state; + String mobileNumberToPass = ''; + if (authState is Authenticated) { + if (selectedAccountIndex >= 0 && selectedAccountIndex < authState.users.length) { + mobileNumberToPass = authState.users[selectedAccountIndex].mobileNo ?? ''; + } + } + await _changePasswordService.getOtp(mobileNumber: mobileNumberToPass); if (mounted) { Navigator.pushReplacement( context, - MaterialPageRoute(builder: (_) => const TpinOtpScreen()), + MaterialPageRoute(builder: (_) => TpinOtpScreen(mobileNumber: mobileNumberToPass,)), ); } } catch (e) { diff --git a/lib/features/profile/change_password/change_password_screen.dart b/lib/features/profile/change_password/change_password_screen.dart index 2f5992c..0f0c880 100644 --- a/lib/features/profile/change_password/change_password_screen.dart +++ b/lib/features/profile/change_password/change_password_screen.dart @@ -7,7 +7,8 @@ import '../../../l10n/app_localizations.dart'; import 'change_password_otp_screen.dart'; class ChangePasswordScreen extends StatefulWidget { - const ChangePasswordScreen(); + final String mobileNumber; + const ChangePasswordScreen({super.key, required this.mobileNumber}); @override State createState() => _ChangePasswordScreenState(); @@ -61,8 +62,7 @@ void _proceed() async { try { - const mobileNumber = "8981274001"; // Replace with actual mobile number - await _changePasswordService.getOtp(mobileNumber: mobileNumber); + await _changePasswordService.getOtp(mobileNumber: widget.mobileNumber); Navigator.push( @@ -72,7 +72,7 @@ void _proceed() async { currentPassword: currentPasswordController.text, newPassword: newPasswordController.text, confirmPassword: confirmPasswordController.text, - mobileNumber: mobileNumber, + mobileNumber: widget.mobileNumber, ), ), ); diff --git a/lib/features/profile/profile_screen.dart b/lib/features/profile/profile_screen.dart index 2bd271e..a50238b 100644 --- a/lib/features/profile/profile_screen.dart +++ b/lib/features/profile/profile_screen.dart @@ -7,10 +7,15 @@ import '../../di/injection.dart'; import '../../l10n/app_localizations.dart'; import 'package:kmobile/features/profile/preferences/preference_screen.dart'; -class ProfileScreen extends StatelessWidget { - const ProfileScreen({super.key}); - +class ProfileScreen extends StatefulWidget { + final String mobileNumber; + const ProfileScreen({super.key, required this.mobileNumber}); + @override + State createState() => _ProfileScreenState(); +} + +class _ProfileScreenState extends State { Future _handleLogout(BuildContext context) async { final auth = getIt(); final prefs = await SharedPreferences.getInstance(); @@ -47,7 +52,9 @@ class ProfileScreen extends StatelessWidget { onTap: () { Navigator.push( context, - MaterialPageRoute(builder: (context) => const ChangePasswordScreen()), + MaterialPageRoute(builder: (context) => ChangePasswordScreen( + mobileNumber: widget.mobileNumber, + )), ); }, ), diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index c7b8f45..deb13e8 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -169,7 +169,7 @@ "invalidOtp": "Invalid OTP", "enterOtp": "Enter OTP", "otpVerification": "OTP Verification", -"otpSentMessage": "Enter the 4-digit OTP sent to your mobile number", +"otpSentMessage": "Enter the 6-digit OTP sent to your mobile number", "verifyOtp": "Verify OTP", "otpResent": "OTP Resent", "resendOtp": "Resend OTP", diff --git a/lib/l10n/app_hi.arb b/lib/l10n/app_hi.arb index 759007d..71b69aa 100644 --- a/lib/l10n/app_hi.arb +++ b/lib/l10n/app_hi.arb @@ -170,7 +170,7 @@ "invalidOtp": "अमान्य ओटीपी", "enterOtp": "ओटीपी दर्ज करें", "otpVerification": "ओटीपी सत्यापन", -"otpSentMessage": "अपने मोबाइल नंबर पर भेजा गया 4-अंकों का ओटीपी दर्ज करें", +"otpSentMessage": "अपने मोबाइल नंबर पर भेजा गया 6-अंकों का ओटीपी दर्ज करें", "verifyOtp": "ओटीपी सत्यापित करें", "otpResent": "ओटीपी पुनः भेजा गया", "resendOtp": "ओटीपी पुनः भेजें",