mpin add and 2026-04-19 updates

This commit is contained in:
MAGESHWARAN 2026-04-19 21:44:01 +05:30
parent 41d7cfa8c6
commit 7d25e77138
15 changed files with 2555 additions and 1643 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get/get.dart';
import 'package:taxglide/consts/app_asstes.dart';
@ -12,6 +13,7 @@ import 'package:taxglide/consts/responsive_helper.dart';
import 'package:taxglide/consts/validation_popup.dart';
import 'package:taxglide/controller/api_contoller.dart';
import 'package:taxglide/router/consts_routers.dart';
import 'package:taxglide/view/Main_controller/main_controller.dart';
class EmployeeLoginScreen extends ConsumerStatefulWidget {
const EmployeeLoginScreen({super.key});
@ -23,46 +25,100 @@ class EmployeeLoginScreen extends ConsumerStatefulWidget {
class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
final ValidationPopup _validationPopup = ValidationPopup();
final TextEditingController _mobileController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
// Multi-box PIN logic
final int pinLength = 4;
final List<TextEditingController> _pinControllers = [];
final List<FocusNode> _pinFocusNodes = [];
String pinValue = '';
// Error states
bool _emailHasError = false;
bool _pinHasError = false;
@override
void initState() {
super.initState();
// Initialize PIN controllers and focus nodes
for (int i = 0; i < pinLength; i++) {
_pinControllers.add(TextEditingController());
_pinFocusNodes.add(FocusNode());
}
final args = Get.arguments;
if (args != null && args is Map<String, dynamic>) {
final mobile = args['mobile'] ?? '';
if (mobile.isNotEmpty) {
_mobileController.text = mobile;
final email = args['email'] ?? '';
if (email.isNotEmpty) {
_emailController.text = email;
}
}
}
@override
void dispose() {
_mobileController.dispose();
_emailController.dispose();
for (var controller in _pinControllers) {
controller.dispose();
}
for (var node in _pinFocusNodes) {
node.dispose();
}
super.dispose();
}
Future<void> _handleLogin() async {
final mobile = _mobileController.text.trim();
void _onPinChange(int index, String value) {
if (_pinHasError) {
setState(() => _pinHasError = false);
}
if (value.isNotEmpty && index < pinLength - 1) {
_pinFocusNodes[index + 1].requestFocus();
}
if (value.isEmpty && index > 0) {
_pinFocusNodes[index - 1].requestFocus();
}
setState(() {
pinValue = _pinControllers.map((c) => c.text).join();
});
}
if (!_validationPopup.validateMobileNumber(context, mobile)) {
Future<void> _handleLogin() async {
final email = _emailController.text.trim();
final pin = pinValue.trim();
setState(() {
_emailHasError = false;
_pinHasError = false;
});
if (!_validationPopup.validateEmail(context, email)) {
setState(() => _emailHasError = true);
return;
}
if (!_validationPopup.validatePin(context, pin)) {
setState(() => _pinHasError = true);
return;
}
await ref.read(employeeloginProvider.notifier).login(mobile);
await ref.read(employeeloginProvider.notifier).loginWithPin(email, pin);
final state = ref.read(employeeloginProvider);
state.when(
data: (data) {
if (data['success'] == true) {
Get.toNamed(ConstRouters.employeeotp, arguments: {'mobile': mobile});
_validationPopup.showSuccessMessage(
context,
"OTP sent successfully!",
"Login Successful!",
);
Future.delayed(const Duration(seconds: 1), () {
Get.offAll(() => const MainController());
});
} else if (data['error'] != null) {
_validationPopup.showErrorMessage(context, data['error'].toString());
setState(() {
_emailHasError = true;
_pinHasError = true;
});
}
},
loading: () {},
@ -80,22 +136,20 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
final r = ResponsiveUtils(context);
// Responsive values
final logoWidth = r.getValue<double>(
mobile: 120,
tablet: 141,
desktop: 160,
);
final logoHeight = r.getValue<double>(
mobile: 85,
tablet: 100,
desktop: 115,
);
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
final linkFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
final pinBoxWidth = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
final pinBoxHeight = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
final pinFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
final pinBoxMargin = r.getValue<double>(mobile: 8, tablet: 6, desktop: 8);
final pinBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
final spacingMD = r.spacing(mobile: 20, tablet: 20, desktop: 24);
@ -146,12 +200,10 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
// Login Title
Text(
"Login",
"Employee Login",
textAlign: TextAlign.center,
style: AppTextStyles.bold.copyWith(
fontSize: titleFontSize,
height: 1.3,
letterSpacing: 0.01 * titleFontSize,
color: AppColors.authheading,
),
),
@ -159,24 +211,123 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
// Subtitle
Text(
"Enter your registered Mobile Number",
"Enter your Email and PIN",
textAlign: TextAlign.center,
style: AppTextStyles.bold.copyWith(
fontSize: subtitleFontSize,
height: 1.4,
letterSpacing: 0.03 * subtitleFontSize,
color: AppColors.authleading,
),
),
SizedBox(height: spacingLG),
// Mobile Number Input
// Email Input
CommanTextFormField(
controller: _mobileController,
hintText: 'Enter your Mobile Number',
keyboardType: TextInputType.phone,
prefixIcon: Icons.phone_android,
controller: _emailController,
hintText: 'Enter your Email',
keyboardType: TextInputType.emailAddress,
prefixIcon: Icons.email_outlined,
hasError: _emailHasError,
onChanged: (value) {
if (_emailHasError) {
setState(() => _emailHasError = false);
}
},
),
SizedBox(height: spacingMD),
// PIN Boxes
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(pinLength, (index) {
bool isFilled = _pinControllers[index].text.isNotEmpty;
return Container(
margin: EdgeInsets.symmetric(horizontal: pinBoxMargin),
width: pinBoxWidth,
height: pinBoxHeight,
decoration: BoxDecoration(
color: isFilled ? AppColors.commanbutton : Colors.white,
borderRadius: BorderRadius.circular(pinBoxRadius),
border: Border.all(
color: _pinHasError
? Colors.red
: const Color(0xFFDFDFDF),
width: _pinHasError ? 1.5 : 1.0,
),
boxShadow: [
BoxShadow(
color: _pinHasError
? Colors.red.withOpacity(0.1)
: const Color(0xFFBDBDBD).withOpacity(0.25),
blurRadius: 7,
offset: const Offset(0, 1),
),
],
),
child: Center(
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey ==
LogicalKeyboardKey.backspace) {
if (_pinControllers[index]
.text
.isEmpty &&
index > 0) {
_pinFocusNodes[index - 1]
.requestFocus();
}
}
},
child: TextField(
controller: _pinControllers[index],
focusNode: _pinFocusNodes[index],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 1,
obscureText: true,
enabled: !loginState.isLoading,
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w400,
fontSize: pinFontSize,
color: isFilled
? Colors.white
: Colors.black,
),
decoration: const InputDecoration(
counterText: '',
border: InputBorder.none,
),
onChanged: (value) =>
_onPinChange(index, value),
),
),
),
);
}),
),
SizedBox(height: spacingXS),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () {
Get.toNamed(
ConstRouters.forgotPassword,
arguments: {'isEmployee': true},
);
},
child: Text(
"Forgot Password?",
style: AppTextStyles.bold.copyWith(
fontSize: linkFontSize,
color: AppColors.authchange,
),
),
),
),
SizedBox(height: spacingLG),
// Terms and Conditions
@ -185,8 +336,6 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
text: "By signing up, you agree to the ",
style: AppTextStyles.medium.copyWith(
fontSize: termsFontSize,
height: 1.8,
letterSpacing: 0.01,
color: AppColors.authleading,
),
children: [
@ -194,8 +343,6 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
text: "Terms of Service ",
style: AppTextStyles.bold.copyWith(
fontSize: termsFontSize,
height: 1.8,
letterSpacing: 0.01,
color: AppColors.authtermsandcondition,
),
),
@ -203,8 +350,6 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
text: "and ",
style: AppTextStyles.medium.copyWith(
fontSize: termsFontSize,
height: 1.8,
letterSpacing: 0.01,
color: AppColors.authleading,
),
),
@ -212,8 +357,6 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
text: "Data Processing Agreement",
style: AppTextStyles.bold.copyWith(
fontSize: termsFontSize,
height: 1.8,
letterSpacing: 0.01,
color: AppColors.authtermsandcondition,
),
),
@ -239,8 +382,6 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
fontSize: otherLoginFontSize,
height: 1.8,
letterSpacing: 0.13,
color: AppColors.authleading,
),
),

View File

@ -10,9 +10,9 @@ import 'package:taxglide/consts/comman_container_auth.dart';
import 'package:taxglide/consts/responsive_helper.dart';
import 'package:taxglide/consts/validation_popup.dart';
import 'package:taxglide/controller/api_contoller.dart';
import 'package:taxglide/view/Main_controller/main_controller.dart';
import '../router/consts_routers.dart';
import 'package:taxglide/router/consts_routers.dart';
import 'package:flutter/services.dart';
import 'package:taxglide/consts/app_style.dart';
class EmployeeOtpScreen extends ConsumerStatefulWidget {
const EmployeeOtpScreen({super.key});
@ -32,13 +32,16 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
int _remainingSeconds = 600;
bool _canResend = false;
late String mobile;
late String _identifier;
bool _fromForgot = false;
bool _isEmployee = true;
@override
void initState() {
super.initState();
final args = Get.arguments as Map<String, dynamic>?;
mobile = args?['mobile'] ?? '';
final args = Get.arguments as Map<String, dynamic>? ?? {};
_fromForgot = args['fromForgot'] ?? false;
_identifier = args['email'] ?? args['mobile'] ?? '';
for (int i = 0; i < otpLength; i++) {
_controllers.add(TextEditingController());
@ -75,87 +78,89 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
}
Future<void> _resendOtp() async {
void _resendOtp() async {
if (!_canResend) return;
for (var controller in _controllers) controller.clear();
setState(() => otpValue = '');
_focusNodes[0].requestFocus();
try {
await ref.read(employeeloginProvider.notifier).login(mobile);
final loginState = ref.read(employeeloginProvider);
loginState.when(
if (_fromForgot) {
await ref.read(forgotPasswordProvider.notifier).requestOtp(_identifier, _isEmployee);
final state = ref.read(forgotPasswordProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(
context,
"OTP has been resent successfully!",
);
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
_startTimer();
} else {
_validationPopup.showErrorMessage(
context,
result['error'] ?? "Failed to resend OTP",
);
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
}
},
loading: () {},
error: (error, _) {
_validationPopup.showErrorMessage(
context,
"Failed to resend OTP. Please try again.",
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
);
} else {
await ref.read(employeeloginProvider.notifier).login(_identifier);
final state = ref.read(employeeloginProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
_startTimer();
} else {
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
}
},
);
} catch (e) {
_validationPopup.showErrorMessage(
context,
"An error occurred. Please try again.",
loading: () {},
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
);
}
}
Future<void> _verifyOtp() async {
void _verifyOtp() async {
if (otpValue.length != otpLength) {
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
return;
}
await ref.read(employeeloginProvider.notifier).verifyOtp(mobile, otpValue);
final loginState = ref.read(employeeloginProvider);
loginState.when(
if (_fromForgot) {
await ref.read(forgotPasswordProvider.notifier).verifyOtp(_identifier, otpValue);
final state = ref.read(forgotPasswordProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(
context,
"OTP Verified Successfully!",
);
Future.delayed(const Duration(seconds: 1), () {
Get.offAll(() => const MainController());
});
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
Get.toNamed(ConstRouters.mpinSet);
} else {
_validationPopup.showErrorMessage(
context,
result['error'] ?? "Invalid OTP. Please try again.",
);
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
}
},
loading: () {},
error: (error, _) {
_validationPopup.showErrorMessage(
context,
"Failed to verify OTP. Please try again.",
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
);
} else {
await ref.read(employeeloginProvider.notifier).verifyOtp(_identifier, otpValue);
final state = ref.read(employeeloginProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
Get.offAllNamed(ConstRouters.mpinSet);
} else {
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
}
},
loading: () {},
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
);
}
}
void _onOtpChange(int index, String value) {
if (value.isNotEmpty && index < otpLength - 1) {
_focusNodes[index + 1].requestFocus();
} else if (value.isEmpty && index > 0) {
}
if (value.isEmpty && index > 0) {
_focusNodes[index - 1].requestFocus();
}
setState(() {
@ -165,40 +170,25 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
@override
Widget build(BuildContext context) {
final loginState = ref.watch(employeeloginProvider);
final isLoading = loginState.isLoading;
final isLoading = _fromForgot
? ref.watch(forgotPasswordProvider).isLoading
: ref.watch(employeeloginProvider).isLoading;
// Initialize responsive utils
final r = ResponsiveUtils(context);
// Responsive values
final logoWidth = r.getValue<double>(
mobile: 120,
tablet: 141,
desktop: 160,
);
final logoHeight = r.getValue<double>(
mobile: 85,
tablet: 100,
desktop: 115,
);
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final mobileFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
final resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
final otpBoxHeight = r.getValue<double>(
mobile: 48,
tablet: 56,
desktop: 64,
);
final otpBoxHeight = r.getValue<double>(mobile: 48, tablet: 56, desktop: 64);
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final otpBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
@ -206,7 +196,6 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
return Scaffold(
body: Stack(
children: [
// Gradient background
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
@ -222,8 +211,6 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
),
),
),
// Scrollable content
SingleChildScrollView(
child: SizedBox(
height: r.screenHeight,
@ -231,9 +218,7 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
child: CommonContainerAuth(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Logo
Image.asset(
AppAssets.taxgildelogoauth,
width: logoWidth,
@ -241,104 +226,56 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
fit: BoxFit.contain,
),
SizedBox(height: spacingSM),
// Title
Text(
"Enter OTP",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: "Gilroy",
"Enter Staff OTP",
style: AppTextStyles.bold.copyWith(
fontSize: titleFontSize,
fontWeight: FontWeight.w600,
height: 1.3,
letterSpacing: 0.01 * titleFontSize,
color: AppColors.authheading,
),
),
SizedBox(height: spacingSM),
// Subtitle
Text(
"OTP has been sent to your registered mobile number",
"OTP has been sent to ${_identifier}",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: "Gilroy",
style: AppTextStyles.medium.copyWith(
fontSize: subtitleFontSize,
fontWeight: FontWeight.w600,
height: 1.4,
letterSpacing: 0.03 * subtitleFontSize,
color: AppColors.authleading,
),
),
SizedBox(height: spacingMD),
// Mobile + Change Number
Text.rich(
TextSpan(
text: mobile,
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w500,
fontSize: mobileFontSize,
height: 1.8,
letterSpacing: 0.01,
color: AppColors.authleading,
),
children: [
TextSpan(
text: " ( Change Number )",
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w800,
fontSize: mobileFontSize,
height: 1.8,
letterSpacing: 0.04,
color: AppColors.authchange,
),
recognizer: TapGestureRecognizer()
..onTap = () {
Get.offNamed(
ConstRouters.employeelogin,
arguments: {'mobile': mobile},
);
},
),
],
),
textAlign: TextAlign.center,
),
SizedBox(height: spacingLG),
// OTP Input Fields
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(otpLength, (index) {
bool isFilled = _controllers[index].text.isNotEmpty;
return Container(
margin: EdgeInsets.symmetric(
horizontal: otpBoxMargin,
),
margin: EdgeInsets.symmetric(horizontal: otpBoxMargin),
width: otpBoxWidth,
height: otpBoxHeight,
decoration: BoxDecoration(
color: isFilled
? AppColors.commanbutton
: Colors.white,
color: isFilled ? AppColors.commanbutton : Colors.white,
borderRadius: BorderRadius.circular(otpBoxRadius),
border: Border.all(
color: const Color(0xFFDFDFDF),
),
border: Border.all(color: const Color(0xFFDFDFDF)),
boxShadow: [
BoxShadow(
color: const Color(
0xFFBDBDBD,
).withOpacity(0.25),
color: const Color(0xFFBDBDBD).withOpacity(0.25),
blurRadius: 7,
offset: const Offset(0, 1),
),
],
),
child: Center(
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey ==
LogicalKeyboardKey.backspace) {
if (_controllers[index].text.isEmpty &&
index > 0) {
_focusNodes[index - 1].requestFocus();
}
}
},
child: TextField(
controller: _controllers[index],
focusNode: _focusNodes[index],
@ -350,7 +287,6 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
fontFamily: "Gilroy",
fontWeight: FontWeight.w400,
fontSize: otpFontSize,
letterSpacing: 0.03 * otpFontSize,
color: isFilled ? Colors.white : Colors.black,
),
decoration: const InputDecoration(
@ -361,25 +297,19 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
_onOtpChange(index, value),
),
),
),
);
}),
),
SizedBox(height: spacingXS),
// Resend OTP
SizedBox(height: spacingSM),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: _canResend && !isLoading ? _resendOtp : null,
child: Text(
"Resend",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w500,
style: AppTextStyles.medium.copyWith(
fontSize: resendFontSize,
height: 1.4,
letterSpacing: 0.02 * resendFontSize,
color: _canResend && !isLoading
? AppColors.authchange
: Colors.grey,
@ -388,22 +318,14 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
),
),
SizedBox(height: spacingSM),
// Timer
Text(
_formatTime(_remainingSeconds),
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w600,
style: AppTextStyles.semiBold.copyWith(
fontSize: timerFontSize,
color: _remainingSeconds > 0
? AppColors.authheading
: Colors.red,
color: _remainingSeconds > 0 ? AppColors.authheading : Colors.red,
),
),
SizedBox(height: spacingLG),
// Verify Button
isLoading
? const CircularProgressIndicator()
: CommanButton(text: "Verify", onPressed: _verifyOtp),

168
lib/auth/forgot_screen.dart Normal file
View File

@ -0,0 +1,168 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get/get.dart';
import 'package:taxglide/consts/app_asstes.dart';
import 'package:taxglide/consts/app_colors.dart';
import 'package:taxglide/consts/app_style.dart';
import 'package:taxglide/consts/comman_button.dart';
import 'package:taxglide/consts/comman_container_auth.dart';
import 'package:taxglide/consts/comman_textformfileds.dart';
import 'package:taxglide/consts/responsive_helper.dart';
import 'package:taxglide/consts/validation_popup.dart';
import 'package:taxglide/controller/api_contoller.dart';
import 'package:taxglide/router/consts_routers.dart';
class ForgotScreen extends ConsumerStatefulWidget {
const ForgotScreen({super.key});
@override
ConsumerState<ForgotScreen> createState() => _ForgotScreenState();
}
class _ForgotScreenState extends ConsumerState<ForgotScreen> {
final TextEditingController _emailController = TextEditingController();
final ValidationPopup _validationPopup = ValidationPopup();
bool _isEmployee = false;
@override
void initState() {
super.initState();
final args = Get.arguments;
if (args != null && args is Map<String, dynamic>) {
_isEmployee = args['isEmployee'] ?? false;
}
}
@override
void dispose() {
_emailController.dispose();
super.dispose();
}
Future<void> _handleForgotRequest() async {
final email = _emailController.text.trim();
if (!_validationPopup.validateEmail(context, email)) {
return;
}
await ref.read(forgotPasswordProvider.notifier).requestOtp(email, _isEmployee);
final state = ref.read(forgotPasswordProvider);
state.when(
data: (data) {
if (data['success'] == true) {
_validationPopup.showSuccessMessage(
context,
"OTP sent to your email!",
);
Get.toNamed(
_isEmployee ? ConstRouters.employeeotp : ConstRouters.otp,
arguments: {
'email': email,
'isEmployee': _isEmployee,
'fromForgot': true,
},
);
} else if (data['error'] != null) {
_validationPopup.showErrorMessage(context, data['error'].toString());
}
},
loading: () {},
error: (err, _) {
_validationPopup.showErrorMessage(context, "Error: $err");
},
);
}
@override
Widget build(BuildContext context) {
final forgotState = ref.watch(forgotPasswordProvider);
final r = ResponsiveUtils(context);
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
final spacingMD = r.spacing(mobile: 20, tablet: 22, desktop: 26);
final spacingLG = r.spacing(mobile: 20, tablet: 22, desktop: 28);
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFFFFF8F0),
Color(0xFFEBC894),
Color(0xFFE8DAF2),
Color(0xFFB49EF4),
],
stops: [0.0, 0.3, 0.6, 1.0],
),
),
child: Center(
child: SingleChildScrollView(
child: CommonContainerAuth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
AppAssets.taxgildelogoauth,
width: logoWidth,
height: logoHeight,
),
SizedBox(height: spacingSM),
Text(
"Forgot Password",
style: AppTextStyles.bold.copyWith(
fontSize: titleFontSize,
color: AppColors.authheading,
),
),
SizedBox(height: spacingSM),
Text(
"Enter your email to receive an OTP",
textAlign: TextAlign.center,
style: AppTextStyles.medium.copyWith(
fontSize: subtitleFontSize,
color: AppColors.authleading,
),
),
SizedBox(height: spacingLG),
CommanTextFormField(
controller: _emailController,
hintText: 'Enter your Email',
keyboardType: TextInputType.emailAddress,
prefixIcon: Icons.email_outlined,
),
SizedBox(height: spacingLG),
forgotState.isLoading
? const CircularProgressIndicator()
: CommanButton(
text: "Send OTP",
onPressed: _handleForgotRequest,
),
SizedBox(height: spacingMD),
TextButton(
onPressed: () => Get.back(),
child: Text(
"Back to Login",
style: AppTextStyles.semiBold.copyWith(
color: AppColors.authsignup,
),
),
),
],
),
),
),
),
),
);
}
}

View File

@ -1,5 +1,6 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get/get.dart';
import 'package:taxglide/consts/app_asstes.dart';
@ -13,6 +14,7 @@ import 'package:taxglide/consts/validation_popup.dart';
import 'package:taxglide/controller/api_contoller.dart';
import 'package:taxglide/router/consts_routers.dart';
import 'package:taxglide/consts/app_style.dart';
import 'package:taxglide/view/Main_controller/main_controller.dart';
class LoginScreen extends ConsumerStatefulWidget {
const LoginScreen({super.key});
@ -22,47 +24,101 @@ class LoginScreen extends ConsumerStatefulWidget {
}
class _LoginScreenState extends ConsumerState<LoginScreen> {
final TextEditingController _mobileController = TextEditingController();
final TextEditingController _emailController = TextEditingController();
final ValidationPopup _validationPopup = ValidationPopup();
// Multi-box PIN logic
final int pinLength = 4;
final List<TextEditingController> _pinControllers = [];
final List<FocusNode> _pinFocusNodes = [];
String pinValue = '';
// Error states
bool _emailHasError = false;
bool _pinHasError = false;
@override
void initState() {
super.initState();
// Initialize PIN controllers and focus nodes
for (int i = 0; i < pinLength; i++) {
_pinControllers.add(TextEditingController());
_pinFocusNodes.add(FocusNode());
}
final args = Get.arguments;
if (args != null && args is Map<String, dynamic>) {
final mobile = args['mobile'] ?? '';
if (mobile.isNotEmpty) {
_mobileController.text = mobile;
final email = args['email'] ?? '';
if (email.isNotEmpty) {
_emailController.text = email;
}
}
}
@override
void dispose() {
_mobileController.dispose();
_emailController.dispose();
for (var controller in _pinControllers) {
controller.dispose();
}
for (var node in _pinFocusNodes) {
node.dispose();
}
super.dispose();
}
Future<void> _handleLogin() async {
final mobile = _mobileController.text.trim();
void _onPinChange(int index, String value) {
if (_pinHasError) {
setState(() => _pinHasError = false);
}
if (value.isNotEmpty && index < pinLength - 1) {
_pinFocusNodes[index + 1].requestFocus();
}
if (value.isEmpty && index > 0) {
_pinFocusNodes[index - 1].requestFocus();
}
setState(() {
pinValue = _pinControllers.map((c) => c.text).join();
});
}
if (!_validationPopup.validateMobileNumber(context, mobile)) {
Future<void> _handleLogin() async {
final email = _emailController.text.trim();
final pin = pinValue.trim();
setState(() {
_emailHasError = false;
_pinHasError = false;
});
if (!_validationPopup.validateEmail(context, email)) {
setState(() => _emailHasError = true);
return;
}
if (!_validationPopup.validatePin(context, pin)) {
setState(() => _pinHasError = true);
return;
}
await ref.read(loginProvider.notifier).login(mobile);
await ref.read(loginProvider.notifier).loginWithPin(email, pin);
final state = ref.read(loginProvider);
state.when(
data: (data) {
if (data['success'] == true) {
Get.toNamed(ConstRouters.otp, arguments: {'mobile': mobile});
_validationPopup.showSuccessMessage(
context,
"OTP sent successfully!",
"Login Successful!",
);
Future.delayed(const Duration(seconds: 1), () {
Get.offAll(() => const MainController());
});
} else if (data['error'] != null) {
_validationPopup.showErrorMessage(context, data['error'].toString());
setState(() {
_emailHasError = true;
_pinHasError = true;
});
}
},
loading: () {},
@ -78,26 +134,22 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
final policyAsync = ref.watch(policyProvider);
final termsAsync = ref.watch(termsProvider);
// Initialize responsive utils
final r = ResponsiveUtils(context);
// Responsive values
final logoWidth = r.getValue<double>(
mobile: 120,
tablet: 141,
desktop: 160,
);
final logoHeight = r.getValue<double>(
mobile: 85,
tablet: 100,
desktop: 115,
);
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
final signupFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
final pinBoxWidth = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
final pinBoxHeight = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
final pinFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
final pinBoxMargin = r.getValue<double>(mobile: 8, tablet: 6, desktop: 8);
final pinBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final spacingXS = r.spacing(mobile: 10, tablet: 15, desktop: 18);
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
final spacingMD = r.spacing(mobile: 20, tablet: 22, desktop: 26);
@ -105,9 +157,6 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
return PopScope(
canPop: true,
onPopInvokedWithResult: (didPop, result) {
// Handle custom behavior here if needed in the future
},
child: Scaffold(
resizeToAvoidBottomInset: true,
body: Container(
@ -136,15 +185,12 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Logo
Image.asset(
AppAssets.taxgildelogoauth,
width: logoWidth,
height: logoHeight,
),
SizedBox(height: spacingSM),
// Title
Text(
"Login",
style: AppTextStyles.semiBold.copyWith(
@ -153,10 +199,8 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
),
),
SizedBox(height: spacingSM),
// Subtitle
Text(
"Enter your Mobile Number",
"Enter your Email and PIN",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
fontSize: subtitleFontSize,
@ -164,17 +208,114 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
),
),
SizedBox(height: spacingLG),
// Mobile TextField
CommanTextFormField(
controller: _mobileController,
hintText: 'Enter your Mobile Number',
keyboardType: TextInputType.phone,
prefixIcon: Icons.mobile_screen_share,
controller: _emailController,
hintText: 'Enter your Email',
keyboardType: TextInputType.emailAddress,
prefixIcon: Icons.email_outlined,
hasError: _emailHasError,
onChanged: (value) {
if (_emailHasError) {
setState(() => _emailHasError = false);
}
},
),
SizedBox(height: spacingLG),
SizedBox(height: spacingMD),
// Terms and Policy
// PIN Boxes
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(pinLength, (index) {
bool isFilled = _pinControllers[index].text.isNotEmpty;
return Container(
margin: EdgeInsets.symmetric(horizontal: pinBoxMargin),
width: pinBoxWidth,
height: pinBoxHeight,
decoration: BoxDecoration(
color: isFilled ? AppColors.commanbutton : Colors.white,
borderRadius: BorderRadius.circular(pinBoxRadius),
border: Border.all(
color: _pinHasError
? Colors.red
: const Color(0xFFDFDFDF),
width: _pinHasError ? 1.5 : 1.0,
),
boxShadow: [
BoxShadow(
color: _pinHasError
? Colors.red.withOpacity(0.1)
: const Color(0xFFBDBDBD).withOpacity(0.25),
blurRadius: 7,
offset: const Offset(0, 1),
),
],
),
child: Center(
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey ==
LogicalKeyboardKey.backspace) {
if (_pinControllers[index]
.text
.isEmpty &&
index > 0) {
_pinFocusNodes[index - 1]
.requestFocus();
}
}
},
child: TextField(
controller: _pinControllers[index],
focusNode: _pinFocusNodes[index],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 1,
obscureText: true,
enabled: !loginState.isLoading,
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w400,
fontSize: pinFontSize,
color: isFilled
? Colors.white
: Colors.black,
),
decoration: const InputDecoration(
counterText: '',
border: InputBorder.none,
),
onChanged: (value) =>
_onPinChange(index, value),
),
),
),
);
}),
),
SizedBox(height: spacingXS),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () {
Get.toNamed(
ConstRouters.forgotPassword,
arguments: {'isEmployee': false},
);
},
child: Text(
"Forgot Password?",
style: AppTextStyles.bold.copyWith(
fontSize: signupFontSize,
color: AppColors.authchange,
),
),
),
),
SizedBox(height: spacingLG),
Text.rich(
TextSpan(
text: "By signing up, you agree to the ",
@ -195,26 +336,12 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
data: (terms) {
CommonInfoPopup.show(
context: context,
title:
terms.data?.title ??
"Terms of Service",
content:
terms.data?.content ??
"No terms found.",
);
},
loading: () {
_validationPopup.showErrorMessage(
context,
"Loading Terms...",
);
},
error: (err, _) {
_validationPopup.showErrorMessage(
context,
"Failed to load Terms",
title: terms.data?.title ?? "Terms of Service",
content: terms.data?.content ?? "No terms found.",
);
},
loading: () => _validationPopup.showErrorMessage(context, "Loading Terms..."),
error: (err, _) => _validationPopup.showErrorMessage(context, "Failed to load Terms"),
);
},
),
@ -232,26 +359,12 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
data: (policy) {
CommonInfoPopup.show(
context: context,
title:
policy.data?.title ??
"Data Processing Agreement",
content:
policy.data?.content ??
"No policy found.",
);
},
loading: () {
_validationPopup.showErrorMessage(
context,
"Loading Policy...",
);
},
error: (err, _) {
_validationPopup.showErrorMessage(
context,
"Failed to load Policy",
title: policy.data?.title ?? "Data Processing Agreement",
content: policy.data?.content ?? "No policy found.",
);
},
loading: () => _validationPopup.showErrorMessage(context, "Loading Policy..."),
error: (err, _) => _validationPopup.showErrorMessage(context, "Failed to load Policy"),
);
},
),
@ -259,15 +372,12 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
),
textAlign: TextAlign.center,
),
SizedBox(height: spacingSM),
Text("Or", style: AppTextStyles.medium.copyWith(
fontSize: spacingSM,
fontSize: 14,
color: AppColors.authleading,
),),
)),
SizedBox(height: spacingSM),
// Sign up
Text.rich(
TextSpan(
text: "Didn't Have account? ",
@ -291,30 +401,22 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
),
),
SizedBox(height: spacingLG),
// Login Button
loginState.isLoading
? const CircularProgressIndicator()
: CommanButton(
text: "Login",
onPressed: _handleLogin,
),
SizedBox(height: spacingMD),
Text(
"Other Login",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
fontSize: otherLoginFontSize,
height: 1.8,
letterSpacing: 0.13,
color: AppColors.authleading,
),
),
SizedBox(height: spacingXS),
Text.rich(
TextSpan(
text: "Staff Login? ",

View File

@ -0,0 +1,252 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:get/get.dart';
import 'package:taxglide/consts/app_asstes.dart';
import 'package:taxglide/consts/app_colors.dart';
import 'package:taxglide/consts/comman_button.dart';
import 'package:taxglide/consts/comman_container_auth.dart';
import 'package:taxglide/consts/responsive_helper.dart';
import 'package:taxglide/consts/validation_popup.dart';
import 'package:taxglide/controller/api_contoller.dart';
import 'package:taxglide/view/Main_controller/main_controller.dart';
import 'package:taxglide/consts/app_style.dart';
class MpinSetScreen extends ConsumerStatefulWidget {
const MpinSetScreen({super.key});
@override
ConsumerState<MpinSetScreen> createState() => _MpinSetScreenState();
}
class _MpinSetScreenState extends ConsumerState<MpinSetScreen> {
final ValidationPopup _validationPopup = ValidationPopup();
final int pinLength = 4;
final List<TextEditingController> _controllers = [];
final List<FocusNode> _focusNodes = [];
String pinValue = '';
@override
void initState() {
super.initState();
_initControllers();
}
void _initControllers() {
for (var c in _controllers) c.dispose();
for (var f in _focusNodes) f.dispose();
_controllers.clear();
_focusNodes.clear();
pinValue = '';
for (int i = 0; i < pinLength; i++) {
_controllers.add(TextEditingController());
_focusNodes.add(FocusNode());
}
}
@override
void dispose() {
for (var c in _controllers) c.dispose();
for (var f in _focusNodes) f.dispose();
super.dispose();
}
void _handleAction() async {
if (pinValue.length != pinLength) {
_validationPopup.showErrorMessage(context, "Please enter all 4 digits");
return;
}
// Call API to set/change PIN
await ref.read(changePinProvider.notifier).changePin(pinValue);
final state = ref.read(changePinProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(
context,
"MPIN Set Successfully!",
);
Future.delayed(const Duration(seconds: 1), () {
Get.offAll(() => const MainController());
});
} else {
_validationPopup.showErrorMessage(
context,
result['error'] ?? "Failed to set MPIN. Please try again.",
);
}
},
loading: () {},
error: (error, stack) {
_validationPopup.showErrorMessage(
context,
"Failed to set MPIN. Please try again.",
);
},
);
}
void _onPinChange(int index, String value) {
if (value.isNotEmpty && index < pinLength - 1) {
_focusNodes[index + 1].requestFocus();
}
if (value.isEmpty && index > 0) {
_focusNodes[index - 1].requestFocus();
}
setState(() {
pinValue = _controllers.map((c) => c.text).join();
});
}
@override
Widget build(BuildContext context) {
final pinState = ref.watch(changePinProvider);
final isLoading = pinState is AsyncLoading;
final r = ResponsiveUtils(context);
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final boxWidth = r.getValue<double>(mobile: 57, tablet: 60, desktop: 68);
final boxHeight = r.getValue<double>(mobile: 57, tablet: 56, desktop: 64);
final pinFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
final boxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final boxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
final spacingLG = r.spacing(mobile: 50, tablet: 50, desktop: 50);
return Scaffold(
body: Stack(
children: [
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xFFFFF8F0),
Color(0xFFEBC894),
Color(0xFFE8DAF2),
Color(0xFFB49EF4),
],
stops: [0.0, 0.3, 0.6, 1.0],
),
),
),
SingleChildScrollView(
child: SizedBox(
height: r.screenHeight,
child: Center(
child: CommonContainerAuth(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
AppAssets.taxgildelogoauth,
width: logoWidth,
height: logoHeight,
fit: BoxFit.contain,
),
SizedBox(height: spacingSM),
Text(
"Set New MPIN",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
fontSize: titleFontSize,
color: AppColors.authheading,
),
),
SizedBox(height: spacingSM),
Text(
"Set a 4-digit security PIN for your account",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
fontSize: subtitleFontSize,
color: AppColors.authleading,
),
),
SizedBox(height: spacingLG),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(pinLength, (index) {
bool isFilled = _controllers[index].text.isNotEmpty;
return Container(
margin: EdgeInsets.symmetric(horizontal: boxMargin),
width: boxWidth,
height: boxHeight,
decoration: BoxDecoration(
color: isFilled ? AppColors.commanbutton : Colors.white,
borderRadius: BorderRadius.circular(boxRadius),
border: Border.all(color: const Color(0xFFDFDFDF)),
boxShadow: [
BoxShadow(
color: const Color(0xFFBDBDBD).withOpacity(0.25),
blurRadius: 7,
offset: const Offset(0, 1),
),
],
),
child: Center(
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey ==
LogicalKeyboardKey.backspace) {
if (_controllers[index].text.isEmpty &&
index > 0) {
_focusNodes[index - 1].requestFocus();
}
}
},
child: TextField(
controller: _controllers[index],
focusNode: _focusNodes[index],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 1,
obscureText: true,
enabled: !isLoading,
style: TextStyle(
fontFamily: "Gilroy",
fontWeight: FontWeight.w400,
fontSize: pinFontSize,
color: isFilled ? Colors.white : Colors.black,
),
decoration: const InputDecoration(
counterText: '',
border: InputBorder.none,
),
onChanged: (value) =>
_onPinChange(index, value),
),
),
),
);
}),
),
SizedBox(height: spacingLG),
isLoading
? const CircularProgressIndicator()
: CommanButton(
text: "Set PIN",
onPressed: _handleAction,
),
],
),
),
),
),
),
],
),
);
}
}

View File

@ -11,8 +11,7 @@ import 'package:taxglide/consts/responsive_helper.dart';
import 'package:taxglide/consts/validation_popup.dart';
import 'package:taxglide/controller/api_contoller.dart';
import 'package:taxglide/router/consts_routers.dart';
import 'package:taxglide/view/Main_controller/main_controller.dart';
import 'package:flutter/services.dart';
import 'package:taxglide/consts/app_style.dart';
class OtpScreen extends ConsumerStatefulWidget {
@ -33,13 +32,17 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
int _remainingSeconds = 600;
bool _canResend = false;
late String mobile;
late String _identifier; // Email or Mobile
bool _fromForgot = false;
bool _isEmployee = false;
@override
void initState() {
super.initState();
final args = Get.arguments as Map<String, dynamic>;
mobile = args['mobile'] ?? '';
final args = Get.arguments as Map<String, dynamic>? ?? {};
_fromForgot = args['fromForgot'] ?? false;
_isEmployee = args['isEmployee'] ?? false;
_identifier = args['email'] ?? args['mobile'] ?? '';
for (int i = 0; i < otpLength; i++) {
_controllers.add(TextEditingController());
@ -82,38 +85,36 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
setState(() => otpValue = '');
_focusNodes[0].requestFocus();
try {
await ref.read(loginProvider.notifier).login(mobile);
if (_fromForgot) {
await ref.read(forgotPasswordProvider.notifier).requestOtp(_identifier, _isEmployee);
final state = ref.read(forgotPasswordProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
_startTimer();
} else {
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
}
},
loading: () {},
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
);
} else {
// Original mobile login resend (if still needed)
await ref.read(loginProvider.notifier).login(_identifier);
final loginState = ref.read(loginProvider);
loginState.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(
context,
"OTP has been resent successfully!",
);
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
_startTimer();
for (var controller in _controllers) controller.clear();
setState(() => otpValue = '');
} else {
_validationPopup.showErrorMessage(
context,
result['error'] ?? "Failed to resend OTP",
);
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
}
},
loading: () {},
error: (error, stack) {
_validationPopup.showErrorMessage(
context,
"Failed to resend OTP. Please try again.",
);
},
);
} catch (e) {
_validationPopup.showErrorMessage(
context,
"An error occurred. Please try again.",
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
);
}
}
@ -124,35 +125,39 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
return;
}
await ref.read(loginProvider.notifier).verifyOtp(mobile, otpValue);
final loginState = ref.read(loginProvider);
loginState.when(
if (_fromForgot) {
await ref.read(forgotPasswordProvider.notifier).verifyOtp(_identifier, otpValue);
final state = ref.read(forgotPasswordProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(
context,
"OTP Verified Successfully!",
);
Future.delayed(const Duration(seconds: 1), () {
Get.offAll(() => MainController());
});
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
Get.toNamed(ConstRouters.mpinSet);
} else {
_validationPopup.showErrorMessage(
context,
result['error'] ?? "Invalid OTP. Please try again.",
);
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
}
},
loading: () {},
error: (error, stack) {
_validationPopup.showErrorMessage(
context,
"Failed to verify OTP. Please try again.",
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
);
} else {
// Original mobile login verify
await ref.read(loginProvider.notifier).verifyOtp(_identifier, otpValue);
final state = ref.read(loginProvider);
state.when(
data: (result) {
if (result['success'] == true) {
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
Get.offAllNamed(ConstRouters.mpinSet);
} else {
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
}
},
loading: () {},
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
);
}
}
void _onOtpChange(int index, String value) {
if (value.isNotEmpty && index < otpLength - 1) {
@ -168,40 +173,25 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
@override
Widget build(BuildContext context) {
final loginState = ref.watch(loginProvider);
final isLoading = loginState is AsyncLoading;
final isLoading = _fromForgot
? ref.watch(forgotPasswordProvider).isLoading
: ref.watch(loginProvider).isLoading;
// Initialize responsive utils
final r = ResponsiveUtils(context);
// Responsive values
final logoWidth = r.getValue<double>(
mobile: 120,
tablet: 141,
desktop: 160,
);
final logoHeight = r.getValue<double>(
mobile: 85,
tablet: 100,
desktop: 115,
);
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final mobileFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
final resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
final otpBoxHeight = r.getValue<double>(
mobile: 48,
tablet: 56,
desktop: 64,
);
final otpBoxHeight = r.getValue<double>(mobile: 48, tablet: 56, desktop: 64);
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final otpBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
@ -209,7 +199,6 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
return Scaffold(
body: Stack(
children: [
// Background gradient
Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
@ -225,8 +214,6 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
),
),
),
// Scrollable content
SingleChildScrollView(
child: SizedBox(
height: r.screenHeight,
@ -234,9 +221,7 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
child: CommonContainerAuth(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Logo
Image.asset(
AppAssets.taxgildelogoauth,
width: logoWidth,
@ -244,96 +229,56 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
fit: BoxFit.contain,
),
SizedBox(height: spacingSM),
// Title
Text(
"Enter OTP",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
style: AppTextStyles.bold.copyWith(
fontSize: titleFontSize,
height: 1.3,
letterSpacing: 0.01 * titleFontSize,
color: AppColors.authheading,
),
),
SizedBox(height: spacingSM),
// Subtitle
Text(
"OTP has been sent to your registered mobile number",
"OTP has been sent to ${_identifier}",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
style: AppTextStyles.medium.copyWith(
fontSize: subtitleFontSize,
height: 1.4,
letterSpacing: 0.03 * subtitleFontSize,
color: AppColors.authleading,
),
),
SizedBox(height: spacingMD),
// Mobile number + Change
Text.rich(
TextSpan(
text: mobile,
style: AppTextStyles.medium.copyWith(
fontSize: mobileFontSize,
height: 1.8,
letterSpacing: 0.01,
color: AppColors.authleading,
),
children: [
TextSpan(
text: " ( Change Number )",
style: AppTextStyles.extraBold.copyWith(
fontSize: mobileFontSize,
height: 1.8,
letterSpacing: 0.04,
color: AppColors.authchange,
),
recognizer: TapGestureRecognizer()
..onTap = () {
Get.offNamed(
ConstRouters.login,
arguments: {'mobile': mobile},
);
},
),
],
),
textAlign: TextAlign.center,
),
SizedBox(height: spacingLG),
// OTP Boxes
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(otpLength, (index) {
bool isFilled = _controllers[index].text.isNotEmpty;
return Container(
margin: EdgeInsets.symmetric(
horizontal: otpBoxMargin,
),
margin: EdgeInsets.symmetric(horizontal: otpBoxMargin),
width: otpBoxWidth,
height: otpBoxHeight,
decoration: BoxDecoration(
color: isFilled
? AppColors.commanbutton
: Colors.white,
color: isFilled ? AppColors.commanbutton : Colors.white,
borderRadius: BorderRadius.circular(otpBoxRadius),
border: Border.all(
color: const Color(0xFFDFDFDF),
),
border: Border.all(color: const Color(0xFFDFDFDF)),
boxShadow: [
BoxShadow(
color: const Color(
0xFFBDBDBD,
).withOpacity(0.25),
color: const Color(0xFFBDBDBD).withOpacity(0.25),
blurRadius: 7,
offset: const Offset(0, 1),
),
],
),
child: Center(
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey ==
LogicalKeyboardKey.backspace) {
if (_controllers[index].text.isEmpty &&
index > 0) {
_focusNodes[index - 1].requestFocus();
}
}
},
child: TextField(
controller: _controllers[index],
focusNode: _focusNodes[index],
@ -345,7 +290,6 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
fontFamily: "Gilroy",
fontWeight: FontWeight.w400,
fontSize: otpFontSize,
letterSpacing: 0.03 * otpFontSize,
color: isFilled ? Colors.white : Colors.black,
),
decoration: const InputDecoration(
@ -356,23 +300,19 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
_onOtpChange(index, value),
),
),
),
);
}),
),
SizedBox(height: spacingXS),
// Resend
SizedBox(height: spacingSM),
Align(
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: _canResend && !isLoading ? _resendOtp : null,
child: Text(
"Resend",
textAlign: TextAlign.center,
style: AppTextStyles.medium.copyWith(
fontSize: resendFontSize,
height: 1.4,
letterSpacing: 0.02 * resendFontSize,
color: _canResend && !isLoading
? AppColors.authchange
: Colors.grey,
@ -381,20 +321,14 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
),
),
SizedBox(height: spacingSM),
// Timer
Text(
_formatTime(_remainingSeconds),
style: AppTextStyles.semiBold.copyWith(
fontSize: timerFontSize,
color: _remainingSeconds > 0
? AppColors.authheading
: Colors.red,
color: _remainingSeconds > 0 ? AppColors.authheading : Colors.red,
),
),
SizedBox(height: spacingLG),
// Verify Button
isLoading
? const CircularProgressIndicator()
: CommanButton(text: "Verify", onPressed: _verifyOtp),

View File

@ -2,7 +2,9 @@ import 'dart:async';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:taxglide/auth/mpin_set_screen.dart';
import 'package:taxglide/consts/app_asstes.dart';
import 'package:taxglide/consts/app_colors.dart';
import 'package:taxglide/consts/comman_button.dart';
@ -155,7 +157,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
}
// Call verify OTP API for signup
await ref.read(signupProvider.notifier).verifySignupOtp(mobile, otpValue);
await ref.read(signupProvider.notifier).verifySignupOtp(email, otpValue);
final signupState = ref.read(signupProvider);
@ -169,7 +171,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
// Navigate to main screen after successful verification
Future.delayed(const Duration(seconds: 1), () {
Get.offAll(() => MainController());
Get.offAll(() => MpinSetScreen());
});
} else {
_validationPopup.showErrorMessage(
@ -208,7 +210,20 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
final signupState = ref.watch(signupProvider);
final isLoading = signupState is AsyncLoading;
return Scaffold(
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) {
if (didPop) return;
Get.offNamed(
ConstRouters.signup,
arguments: {
'name': name,
'email': email,
'mobile': mobile,
},
);
},
child: Scaffold(
body: Stack(
children: [
// Background gradient
@ -257,10 +272,10 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
),
const SizedBox(height: 20),
Text(
"OTP has been sent to your registered mobile number",
"OTP has been sent to your registered mail id",
textAlign: TextAlign.center,
style: AppTextStyles.semiBold.copyWith(
fontSize: 14,
fontSize: 12,
height: 1.4,
letterSpacing: 0.03 * 14,
color: AppColors.authleading,
@ -269,7 +284,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
const SizedBox(height: 22),
Text.rich(
TextSpan(
text: mobile,
text: email,
style: AppTextStyles.medium.copyWith(
fontSize: 13,
height: 1.8,
@ -278,7 +293,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
),
children: [
TextSpan(
text: " ( Change Number )",
text: " ( Change mail id )",
style: AppTextStyles.extraBold.copyWith(
fontSize: 13,
height: 1.8,
@ -331,6 +346,18 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
],
),
child: Center(
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey ==
LogicalKeyboardKey.backspace) {
if (_controllers[index].text.isEmpty &&
index > 0) {
_focusNodes[index - 1].requestFocus();
}
}
},
child: TextField(
controller: _controllers[index],
focusNode: _focusNodes[index],
@ -353,6 +380,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
_onOtpChange(index, value),
),
),
),
);
}),
),
@ -403,6 +431,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
),
],
),
)
);
}
}

View File

@ -80,8 +80,12 @@ class ValidationPopup {
return true;
}
// Add this method to your ValidationPopup class
// Validate Email
bool validateEmail(BuildContext context, String email) {
if (email.isEmpty) {
showErrorMessage(context, "Please enter your email address");
return false;
}
// Email regex pattern
final emailRegex = RegExp(
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
@ -94,6 +98,23 @@ class ValidationPopup {
return true;
}
// Validate PIN
bool validatePin(BuildContext context, String pin) {
if (pin.isEmpty) {
showErrorMessage(context, "Please enter your 4-digit PIN");
return false;
}
if (pin.length != 4) {
showErrorMessage(context, "PIN must be 4 digits");
return false;
}
if (!RegExp(r'^[0-9]+$').hasMatch(pin)) {
showErrorMessage(context, "PIN must contain only digits");
return false;
}
return true;
}
// Show success message
void showSuccessMessage(BuildContext context, String msg) {
_showSnackBar(context, msg, isError: false);

View File

@ -2,7 +2,7 @@ class ConstsApi {
static const String baseUrl = "https://www.taxglide.amrithaa.net";
static const String login = "$baseUrl/api/otp/sms/request";
static const String verifyOtp = "$baseUrl/api/otp/sms/verify";
static const String verifyOtp = "$baseUrl/api/otp/email/verify";
static const String signup = "$baseUrl/api/register";
static const String terms = "$baseUrl/api/get_terms_conditions";
static const String policy = "$baseUrl/api/get_privacy_policy";
@ -28,4 +28,10 @@ class ConstsApi {
static const String dashboard = "$baseUrl/api/get_dashboard_data";
static const String proformaaccept = "$baseUrl/api/proforma/accept";
static const String payNow = "$baseUrl/api/pay_now";
static const String changePin = "$baseUrl/api/change_pin";
static const String loginWithPin = "$baseUrl/api/login";
static const String employeeLoginWithPin = "$baseUrl/api/employee/login";
static const String forgotPassword = "$baseUrl/api/otp/email/request";
static const String employeeForgotPassword = "$baseUrl/api/otp/employee/email/request";
}

View File

@ -33,6 +33,17 @@ class LoginNotifier extends StateNotifier<AsyncValue<Map<String, dynamic>>> {
LoginNotifier(this._apiRepository) : super(const AsyncValue.data({}));
Future<void> loginWithPin(String email, String pin) async {
if (!mounted) return;
state = const AsyncValue.loading();
try {
final result = await _apiRepository.loginWithPin(email, pin);
if (mounted) state = AsyncValue.data(result);
} catch (e, st) {
if (mounted) state = AsyncValue.error(e, st);
}
}
Future<void> login(String mobile) async {
if (!mounted) return;
state = const AsyncValue.loading();
@ -86,11 +97,11 @@ class SignupNotifier extends StateNotifier<AsyncValue<Map<String, dynamic>>> {
}
// Verify OTP for signup
Future<void> verifySignupOtp(String mobile, String otp) async {
Future<void> verifySignupOtp(String email, String otp) async {
if (!mounted) return;
state = const AsyncValue.loading();
try {
final result = await _apiRepository.verifySignupOtp(mobile, otp);
final result = await _apiRepository.verifySignupOtp(email, otp);
if (mounted) state = AsyncValue.data(result);
} catch (e, st) {
if (mounted) state = AsyncValue.error(e, st);
@ -115,6 +126,17 @@ class EmployeeLoginNotifier
EmployeeLoginNotifier(this._apiRepository) : super(const AsyncValue.data({}));
Future<void> loginWithPin(String email, String pin) async {
if (!mounted) return;
state = const AsyncValue.loading();
try {
final result = await _apiRepository.employeeLoginWithPin(email, pin);
if (mounted) state = AsyncValue.data(result);
} catch (e, st) {
if (mounted) state = AsyncValue.error(e, st);
}
}
Future<void> login(String mobile) async {
if (!mounted) return;
state = const AsyncValue.loading();
@ -137,6 +159,77 @@ class EmployeeLoginNotifier
if (mounted) state = AsyncValue.error(e, st);
}
}
void reset() {
state = const AsyncValue.data({});
}
}
final forgotPasswordProvider =
StateNotifierProvider<
ForgotPasswordNotifier,
AsyncValue<Map<String, dynamic>>
>((ref) => ForgotPasswordNotifier(ref.read(apiRepositoryProvider)));
class ForgotPasswordNotifier
extends StateNotifier<AsyncValue<Map<String, dynamic>>> {
final ApiRepository _apiRepository;
ForgotPasswordNotifier(this._apiRepository)
: super(const AsyncValue.data({}));
Future<void> requestOtp(String email, bool isEmployee) async {
if (!mounted) return;
state = const AsyncValue.loading();
try {
final result = await _apiRepository.requestForgotPasswordOtp(
email,
isEmployee,
);
if (mounted) state = AsyncValue.data(result);
} catch (e, st) {
if (mounted) state = AsyncValue.error(e, st);
}
}
Future<void> verifyOtp(String email, String otp) async {
if (!mounted) return;
state = const AsyncValue.loading();
try {
final result = await _apiRepository.verifyEmailOtp(email, otp);
if (mounted) state = AsyncValue.data(result);
} catch (e, st) {
if (mounted) state = AsyncValue.error(e, st);
}
}
void reset() {
state = const AsyncValue.data({});
}
}
// PIN controller
final changePinProvider =
StateNotifierProvider<PinNotifier, AsyncValue<Map<String, dynamic>>>(
(ref) => PinNotifier(ref.read(apiRepositoryProvider)),
);
class PinNotifier extends StateNotifier<AsyncValue<Map<String, dynamic>>> {
final ApiRepository _apiRepository;
PinNotifier(this._apiRepository) : super(const AsyncValue.data({}));
Future<void> changePin(String pinOrOtp) async {
if (!mounted) return;
state = const AsyncValue.loading();
try {
final result = await _apiRepository.changePin(pinOrOtp);
if (mounted) state = AsyncValue.data(result);
} catch (e, st) {
if (mounted) state = AsyncValue.error(e, st);
}
}
}
final termsProvider = FutureProvider<TermsModel>((ref) async {

View File

@ -159,6 +159,54 @@ class ApiRepository {
}
}
// 🔹 DIRECT LOGIN (Email + PIN) - Regenerates FCM token
Future<Map<String, dynamic>> loginWithPin(String email, String pin) async {
try {
final params = {'email': email, 'pin': pin};
// Regenerate FCM and APNS tokens on every login
final tokens = await _regenerateFcmToken();
final fcmToken = tokens['fcm_token'];
final apnsToken = tokens['apns_token'];
if (fcmToken != null && fcmToken.isNotEmpty) {
params['fcm_token'] = fcmToken;
}
if (apnsToken != null && apnsToken.isNotEmpty) {
params['apns_token'] = apnsToken;
}
if (params['fcm_token'] == null) {
debugPrint('⚠️ Failed to generate FCM token, trying fallback...');
final fallbackToken = await _getFreshFcmToken();
if (fallbackToken != null && fallbackToken.isNotEmpty) {
params['fcm_token'] = fallbackToken;
}
}
final uri = Uri.parse(ConstsApi.loginWithPin).replace(
queryParameters: params.map(
(key, value) => MapEntry(key, value.toString()),
),
);
final response = await http.post(uri, headers: _baseHeaders);
final data = jsonDecode(response.body);
if (response.statusCode == 200 || response.statusCode == 201) {
await _localStore.saveLoginData(data);
return {'success': true, 'data': data};
} else {
return {'success': false, 'error': _extractErrorMessage(data)};
}
} catch (e) {
return {
'success': false,
'error': 'Connection error. Please check your internet.',
};
}
}
// 🔹 VERIFY OTP (LOGIN) - Regenerates FCM token
Future<Map<String, dynamic>> verifyOtp(LoginModel model) async {
try {
@ -230,6 +278,143 @@ class ApiRepository {
}
}
// 🔹 EMPLOYEE LOGIN (Email + PIN) - Regenerates FCM token
Future<Map<String, dynamic>> employeeLoginWithPin(
String email,
String pin,
) async {
try {
final params = {'email': email, 'pin': pin};
// Regenerate FCM and APNS tokens on every login
final tokens = await _regenerateFcmToken();
final fcmToken = tokens['fcm_token'];
final apnsToken = tokens['apns_token'];
if (fcmToken != null && fcmToken.isNotEmpty) {
params['fcm_token'] = fcmToken;
}
if (apnsToken != null && apnsToken.isNotEmpty) {
params['apns_token'] = apnsToken;
}
if (params['fcm_token'] == null) {
debugPrint('⚠️ Failed to generate FCM token, trying fallback...');
final fallbackToken = await _getFreshFcmToken();
if (fallbackToken != null && fallbackToken.isNotEmpty) {
params['fcm_token'] = fallbackToken;
}
}
final uri = Uri.parse(ConstsApi.employeeLoginWithPin).replace(
queryParameters: params.map(
(key, value) => MapEntry(key, value.toString()),
),
);
final response = await http.post(uri, headers: _baseHeaders);
final data = jsonDecode(response.body);
if (response.statusCode == 200 || response.statusCode == 201) {
await _localStore.saveLoginData(data);
return {'success': true, 'data': data};
} else {
return {'success': false, 'error': _extractErrorMessage(data)};
}
} catch (e) {
return {
'success': false,
'error': 'Connection error. Please check your internet.',
};
}
}
// 🔹 FORGOT PASSWORD REQUEST (Email OTP)
Future<Map<String, dynamic>> requestForgotPasswordOtp(
String email,
bool isEmployee,
) async {
try {
final endpoint = isEmployee
? ConstsApi.employeeForgotPassword
: ConstsApi.forgotPassword;
final uri = Uri.parse(endpoint).replace(queryParameters: {'email': email});
final response = await http.post(uri, headers: _baseHeaders);
final data = jsonDecode(response.body);
if (response.statusCode == 200 || response.statusCode == 201) {
return {'success': true, 'data': data};
} else {
return {'success': false, 'error': _extractErrorMessage(data)};
}
} catch (e) {
return {
'success': false,
'error': 'Connection error. Please check your internet.',
};
}
}
// 🔹 VERIFY EMAIL OTP (Generic)
Future<Map<String, dynamic>> verifyEmailOtp(String email, String otp) async {
try {
final fcmToken = await _getFreshFcmToken();
final uri = Uri.parse(ConstsApi.verifyOtp).replace(
queryParameters: {
'email': email,
'otp': otp,
if (fcmToken != null) 'fcm_token': fcmToken,
},
);
final response = await http.post(uri, headers: _baseHeaders);
final data = jsonDecode(response.body);
if (response.statusCode == 200 || response.statusCode == 201) {
// CRITICAL: Save login data to get the token for subsequent requests (like set_pin)
await _localStore.saveLoginData(data);
return {'success': true, 'data': data};
} else {
return {'success': false, 'error': _extractErrorMessage(data)};
}
} catch (e) {
return {
'success': false,
'error': 'Connection error. Please check your internet.',
};
}
}
// 🔹 CHANGE/SET PIN
Future<Map<String, dynamic>> changePin(String pin) async {
try {
final token = await _localStore.getToken();
final uri = Uri.parse(ConstsApi.changePin).replace(
queryParameters: {'otp': pin},
);
final response = await http.post(
uri,
headers: {
'Authorization': 'Bearer $token',
'Accept': 'application/json',
},
);
final data = jsonDecode(response.body);
if (response.statusCode == 200 || response.statusCode == 201) {
return {'success': true, 'data': data};
} else {
return {'success': false, 'error': _extractErrorMessage(data)};
}
} catch (e) {
return {
'success': false,
'error': 'Connection error. Please check your internet.',
};
}
}
// 🔹 SIGNUP API
Future<Map<String, dynamic>> signupUser(SignupModel model) async {
try {
@ -258,7 +443,7 @@ class ApiRepository {
// 🔹 VERIFY OTP (SIGNUP) - Regenerates FCM token
Future<Map<String, dynamic>> verifySignupOtp(
String mobile,
String email,
String otp,
) async {
try {
@ -267,7 +452,7 @@ class ApiRepository {
final fcmToken = tokens['fcm_token'];
final apnsToken = tokens['apns_token'];
final params = {'mobile': mobile, 'otp': otp};
final params = {'email': email, 'otp': otp};
if (fcmToken != null && fcmToken.isNotEmpty) {
params['fcm_token'] = fcmToken;
@ -946,6 +1131,41 @@ debugPrint('📦 KYC Response Body: ${response.body}');
}
}
// // 🔹 CHANGE PIN (Verify OTP)
// Future<Map<String, dynamic>> changePin(String otp) async {
// try {
// final token = await _localStore.getToken();
// final uri = Uri.parse(ConstsApi.changePin).replace(
// queryParameters: {'otp': otp},
// );
// final response = await http.post(
// uri,
// headers: {
// 'Authorization': 'Bearer $token',
// 'Accept': 'application/json',
// },
// );
// final data = jsonDecode(response.body);
// debugPrint("🚀 Change Pin (Verify) API Response: $data");
// if (response.statusCode == 200 || response.statusCode == 201) {
// return {'success': true, 'data': data};
// } else {
// return {'success': false, 'error': _extractErrorMessage(data)};
// }
// } catch (e) {
// debugPrint('❌ Change Pin API Error: $e');
// return {
// 'success': false,
// 'error': 'Connection error. Please try again.',
// };
// }
// }
// 🔹 LOGOUT - Deletes FCM token
Future<void> logout() async {
try {

View File

@ -1,23 +1,38 @@
// login_model.dart
class LoginModel {
String? email;
String? pin;
String? mobile;
String? otp;
LoginModel({this.mobile, this.otp});
LoginModel({this.email, this.pin, this.mobile, this.otp});
// For sending mobile number to request OTP
// For sending mobile number to request OTP (Legacy)
Map<String, dynamic> toJsonMobile() {
return {'mobile': mobile};
}
// For sending mobile + OTP for verification
// For sending mobile + OTP for verification (Legacy)
Map<String, dynamic> toJsonOtp() {
return {'mobile': mobile, 'otp': otp};
}
// For Email + PIN Login
Map<String, dynamic> toJsonEmailPin() {
return {
'email': email,
'pin': pin,
};
}
// Response from API
factory LoginModel.fromJson(Map<String, dynamic> json) {
return LoginModel(mobile: json['mobile'], otp: json['otp']);
return LoginModel(
email: json['email'],
pin: json['pin'],
mobile: json['mobile'],
otp: json['otp'],
);
}
}

View File

@ -13,4 +13,6 @@ class ConstRouters {
static const String servicerequest = '/servicerequest';
static const String staff = '/staff';
static const String employeekycdetailslist = '/employeekycdetailslist';
static const String mpinSet = '/mpinSet';
static const String forgotPassword = '/forgotPassword';
}

View File

@ -1,7 +1,9 @@
import 'package:get/get.dart';
import 'package:taxglide/auth/employee_login_screen.dart';
import 'package:taxglide/auth/employee_otp_screen.dart';
import 'package:taxglide/auth/forgot_screen.dart';
import 'package:taxglide/auth/login_screen.dart';
import 'package:taxglide/auth/mpin_set_screen.dart';
import 'package:taxglide/auth/otp_screen.dart';
import 'package:taxglide/auth/register_otp_screen.dart';
import 'package:taxglide/auth/signup_screen.dart';
@ -50,5 +52,10 @@ class AppRoutes {
),
GetPage(name: ConstRouters.policy, page: () => const PolicyScreen()),
GetPage(name: ConstRouters.staff, page: () => const StaffListScreen()),
GetPage(name: ConstRouters.mpinSet, page: () => const MpinSetScreen()),
GetPage(
name: ConstRouters.forgotPassword,
page: () => const ForgotScreen(),
),
];
}

View File

@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "8d7ff3948166b8ec5da0fbb5962000926b8e02f2ed9b3e51d1738905fbd4c98d"
sha256: da0d9209ca76bde579f2da330aeb9df62b6319c834fa7baae052021b0462401f
url: "https://pub.dev"
source: hosted
version: "93.0.0"
version: "85.0.0"
_flutterfire_internals:
dependency: transitive
description:
@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: analyzer
sha256: de7148ed2fcec579b19f122c1800933dfa028f6d9fd38a152b04b1516cec120b
sha256: "974859dc0ff5f37bc4313244b3218c791810d03ab3470a579580279ba971a48d"
url: "https://pub.dev"
source: hosted
version: "10.0.1"
version: "7.7.1"
animated_notch_bottom_bar:
dependency: "direct main"
description:
@ -101,10 +101,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
version: "1.4.1"
version: "1.4.0"
checked_yaml:
dependency: transitive
description:
@ -724,26 +724,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev"
source: hosted
version: "0.12.18"
version: "0.12.17"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.13.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.16.0"
mime:
dependency: transitive
description:
@ -1137,26 +1137,26 @@ packages:
dependency: transitive
description:
name: test
sha256: "54c516bbb7cee2754d327ad4fca637f78abfc3cbcc5ace83b3eda117e42cd71a"
sha256: "65e29d831719be0591f7b3b1a32a3cda258ec98c58c7b25f7b84241bc31215bb"
url: "https://pub.dev"
source: hosted
version: "1.29.0"
version: "1.26.2"
test_api:
dependency: transitive
description:
name: test_api
sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
url: "https://pub.dev"
source: hosted
version: "0.7.9"
version: "0.7.6"
test_core:
dependency: transitive
description:
name: test_core
sha256: "394f07d21f0f2255ec9e3989f21e54d3c7dc0e6e9dbce160e5a9c1a6be0e2943"
sha256: "80bf5a02b60af04b09e14f6fe68b921aad119493e26e490deaca5993fef1b05a"
url: "https://pub.dev"
source: hosted
version: "0.6.15"
version: "0.6.11"
timezone:
dependency: transitive
description: