Mobile Number Implemented in OTP

This commit is contained in:
2025-09-11 18:13:39 +05:30
parent 0f205873a9
commit 82e057d804
7 changed files with 49 additions and 23 deletions

View File

@@ -226,12 +226,21 @@ class _DashboardScreenState extends State<DashboardScreen> {
child: InkWell( child: InkWell(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
onTap: () { onTap: () {
Navigator.push( final authState = context.read<AuthCubit>().state;
context, String mobileNumberToPass = '';
MaterialPageRoute(
builder: (context) => const ProfileScreen(), 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( child: CircleAvatar(
backgroundColor: Colors.grey[200], backgroundColor: Colors.grey[200],

View File

@@ -5,7 +5,8 @@ import 'package:kmobile/api/services/change_password_service.dart';
import 'package:kmobile/di/injection.dart'; import 'package:kmobile/di/injection.dart';
class TpinOtpScreen extends StatefulWidget { class TpinOtpScreen extends StatefulWidget {
const TpinOtpScreen({super.key}); final String mobileNumber;
const TpinOtpScreen({super.key, required this.mobileNumber});
@override @override
State<TpinOtpScreen> createState() => _TpinOtpScreenState(); State<TpinOtpScreen> createState() => _TpinOtpScreenState();
@@ -49,10 +50,9 @@ void _verifyOtp() async {
}); });
try { try {
// IMPORTANT: You may need to pass the mobile number here as well
await _changePasswordService.validateOtp( await _changePasswordService.validateOtp(
otp: _enteredOtp, otp: _enteredOtp,
mobileNumber: '8981274001', // Replace with actual mobile number mobileNumber: widget.mobileNumber,
); );
if (mounted) { if (mounted) {
@@ -151,7 +151,6 @@ void _verifyOtp() async {
), ),
const SizedBox(height: 32), const SizedBox(height: 32),
ElevatedButton.icon( ElevatedButton.icon(
// Update icon to show a loading indicator
icon: _isLoading icon: _isLoading
? const SizedBox( ? const SizedBox(
width: 20, width: 20,

View File

@@ -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 '../../../l10n/app_localizations.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:kmobile/features/fund_transfer/screens/tpin_otp_screen.dart'; import 'package:kmobile/features/fund_transfer/screens/tpin_otp_screen.dart';
@@ -12,7 +16,7 @@ class TpinSetupPromptScreen extends StatefulWidget {
} }
class _TpinSetupPromptScreenState extends State<TpinSetupPromptScreen> { class _TpinSetupPromptScreenState extends State<TpinSetupPromptScreen> {
// 3. Add state variables int selectedAccountIndex = 0;
bool _isLoading = false; bool _isLoading = false;
final ChangePasswordService _changePasswordService = getIt<ChangePasswordService>(); final ChangePasswordService _changePasswordService = getIt<ChangePasswordService>();
Future<void> _getOtp() async { Future<void> _getOtp() async {
@@ -21,11 +25,18 @@ class TpinSetupPromptScreen extends StatefulWidget {
}); });
try { try {
await _changePasswordService.getOtp(mobileNumber: '8981274001'); final authState = context.read<AuthCubit>().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) { if (mounted) {
Navigator.pushReplacement( Navigator.pushReplacement(
context, context,
MaterialPageRoute(builder: (_) => const TpinOtpScreen()), MaterialPageRoute(builder: (_) => TpinOtpScreen(mobileNumber: mobileNumberToPass,)),
); );
} }
} catch (e) { } catch (e) {

View File

@@ -7,7 +7,8 @@ import '../../../l10n/app_localizations.dart';
import 'change_password_otp_screen.dart'; import 'change_password_otp_screen.dart';
class ChangePasswordScreen extends StatefulWidget { class ChangePasswordScreen extends StatefulWidget {
const ChangePasswordScreen(); final String mobileNumber;
const ChangePasswordScreen({super.key, required this.mobileNumber});
@override @override
State<ChangePasswordScreen> createState() => _ChangePasswordScreenState(); State<ChangePasswordScreen> createState() => _ChangePasswordScreenState();
@@ -61,8 +62,7 @@ void _proceed() async {
try { try {
const mobileNumber = "8981274001"; // Replace with actual mobile number await _changePasswordService.getOtp(mobileNumber: widget.mobileNumber);
await _changePasswordService.getOtp(mobileNumber: mobileNumber);
Navigator.push( Navigator.push(
@@ -72,7 +72,7 @@ void _proceed() async {
currentPassword: currentPasswordController.text, currentPassword: currentPasswordController.text,
newPassword: newPasswordController.text, newPassword: newPasswordController.text,
confirmPassword: confirmPasswordController.text, confirmPassword: confirmPasswordController.text,
mobileNumber: mobileNumber, mobileNumber: widget.mobileNumber,
), ),
), ),
); );

View File

@@ -7,10 +7,15 @@ import '../../di/injection.dart';
import '../../l10n/app_localizations.dart'; import '../../l10n/app_localizations.dart';
import 'package:kmobile/features/profile/preferences/preference_screen.dart'; import 'package:kmobile/features/profile/preferences/preference_screen.dart';
class ProfileScreen extends StatelessWidget { class ProfileScreen extends StatefulWidget {
const ProfileScreen({super.key}); final String mobileNumber;
const ProfileScreen({super.key, required this.mobileNumber});
@override
State<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
Future<void> _handleLogout(BuildContext context) async { Future<void> _handleLogout(BuildContext context) async {
final auth = getIt<AuthRepository>(); final auth = getIt<AuthRepository>();
final prefs = await SharedPreferences.getInstance(); final prefs = await SharedPreferences.getInstance();
@@ -47,7 +52,9 @@ class ProfileScreen extends StatelessWidget {
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => const ChangePasswordScreen()), MaterialPageRoute(builder: (context) => ChangePasswordScreen(
mobileNumber: widget.mobileNumber,
)),
); );
}, },
), ),

View File

@@ -169,7 +169,7 @@
"invalidOtp": "Invalid OTP", "invalidOtp": "Invalid OTP",
"enterOtp": "Enter OTP", "enterOtp": "Enter OTP",
"otpVerification": "OTP Verification", "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", "verifyOtp": "Verify OTP",
"otpResent": "OTP Resent", "otpResent": "OTP Resent",
"resendOtp": "Resend OTP", "resendOtp": "Resend OTP",

View File

@@ -170,7 +170,7 @@
"invalidOtp": "अमान्य ओटीपी", "invalidOtp": "अमान्य ओटीपी",
"enterOtp": "ओटीपी दर्ज करें", "enterOtp": "ओटीपी दर्ज करें",
"otpVerification": "ओटीपी सत्यापन", "otpVerification": "ओटीपी सत्यापन",
"otpSentMessage": "अपने मोबाइल नंबर पर भेजा गया 4-अंकों का ओटीपी दर्ज करें", "otpSentMessage": "अपने मोबाइल नंबर पर भेजा गया 6-अंकों का ओटीपी दर्ज करें",
"verifyOtp": "ओटीपी सत्यापित करें", "verifyOtp": "ओटीपी सत्यापित करें",
"otpResent": "ओटीपी पुनः भेजा गया", "otpResent": "ओटीपी पुनः भेजा गया",
"resendOtp": "ओटीपी पुनः भेजें", "resendOtp": "ओटीपी पुनः भेजें",