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(
borderRadius: BorderRadius.circular(20),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ProfileScreen(),
),
);
final authState = context.read<AuthCubit>().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],

View File

@@ -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<TpinOtpScreen> 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,

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 '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<TpinSetupPromptScreen> {
// 3. Add state variables
int selectedAccountIndex = 0;
bool _isLoading = false;
final ChangePasswordService _changePasswordService = getIt<ChangePasswordService>();
Future<void> _getOtp() async {
@@ -21,11 +25,18 @@ class TpinSetupPromptScreen extends StatefulWidget {
});
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) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const TpinOtpScreen()),
MaterialPageRoute(builder: (_) => TpinOtpScreen(mobileNumber: mobileNumberToPass,)),
);
}
} catch (e) {

View File

@@ -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<ChangePasswordScreen> 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,
),
),
);

View File

@@ -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<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
Future<void> _handleLogout(BuildContext context) async {
final auth = getIt<AuthRepository>();
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,
)),
);
},
),

View File

@@ -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",

View File

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