mpin add and 2026-04-19 updates
This commit is contained in:
parent
41d7cfa8c6
commit
7d25e77138
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:taxglide/consts/app_asstes.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/consts/validation_popup.dart';
|
||||||
import 'package:taxglide/controller/api_contoller.dart';
|
import 'package:taxglide/controller/api_contoller.dart';
|
||||||
import 'package:taxglide/router/consts_routers.dart';
|
import 'package:taxglide/router/consts_routers.dart';
|
||||||
|
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
||||||
|
|
||||||
class EmployeeLoginScreen extends ConsumerStatefulWidget {
|
class EmployeeLoginScreen extends ConsumerStatefulWidget {
|
||||||
const EmployeeLoginScreen({super.key});
|
const EmployeeLoginScreen({super.key});
|
||||||
@ -23,46 +25,100 @@ class EmployeeLoginScreen extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
||||||
final ValidationPopup _validationPopup = ValidationPopup();
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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;
|
final args = Get.arguments;
|
||||||
if (args != null && args is Map<String, dynamic>) {
|
if (args != null && args is Map<String, dynamic>) {
|
||||||
final mobile = args['mobile'] ?? '';
|
final email = args['email'] ?? '';
|
||||||
if (mobile.isNotEmpty) {
|
if (email.isNotEmpty) {
|
||||||
_mobileController.text = mobile;
|
_emailController.text = email;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_mobileController.dispose();
|
_emailController.dispose();
|
||||||
|
for (var controller in _pinControllers) {
|
||||||
|
controller.dispose();
|
||||||
|
}
|
||||||
|
for (var node in _pinFocusNodes) {
|
||||||
|
node.dispose();
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleLogin() async {
|
void _onPinChange(int index, String value) {
|
||||||
final mobile = _mobileController.text.trim();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ref.read(employeeloginProvider.notifier).login(mobile);
|
await ref.read(employeeloginProvider.notifier).loginWithPin(email, pin);
|
||||||
final state = ref.read(employeeloginProvider);
|
final state = ref.read(employeeloginProvider);
|
||||||
|
|
||||||
state.when(
|
state.when(
|
||||||
data: (data) {
|
data: (data) {
|
||||||
if (data['success'] == true) {
|
if (data['success'] == true) {
|
||||||
Get.toNamed(ConstRouters.employeeotp, arguments: {'mobile': mobile});
|
|
||||||
_validationPopup.showSuccessMessage(
|
_validationPopup.showSuccessMessage(
|
||||||
context,
|
context,
|
||||||
"OTP sent successfully!",
|
"Login Successful!",
|
||||||
);
|
);
|
||||||
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
|
Get.offAll(() => const MainController());
|
||||||
|
});
|
||||||
} else if (data['error'] != null) {
|
} else if (data['error'] != null) {
|
||||||
_validationPopup.showErrorMessage(context, data['error'].toString());
|
_validationPopup.showErrorMessage(context, data['error'].toString());
|
||||||
|
setState(() {
|
||||||
|
_emailHasError = true;
|
||||||
|
_pinHasError = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loading: () {},
|
loading: () {},
|
||||||
@ -80,22 +136,20 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
|||||||
final r = ResponsiveUtils(context);
|
final r = ResponsiveUtils(context);
|
||||||
|
|
||||||
// Responsive values
|
// Responsive values
|
||||||
final logoWidth = r.getValue<double>(
|
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
|
||||||
mobile: 120,
|
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
|
||||||
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 titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||||
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
||||||
final linkFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
final linkFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||||
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
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 spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
|
||||||
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
||||||
final spacingMD = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
final spacingMD = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||||
@ -108,168 +162,256 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
|||||||
Get.offAllNamed(ConstRouters.login);
|
Get.offAllNamed(ConstRouters.login);
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
resizeToAvoidBottomInset: true,
|
resizeToAvoidBottomInset: true,
|
||||||
body: Container(
|
body: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
colors: [
|
colors: [
|
||||||
Color(0xFFFFF8F0),
|
Color(0xFFFFF8F0),
|
||||||
Color(0xFFEBC894),
|
Color(0xFFEBC894),
|
||||||
Color(0xFFE8DAF2),
|
Color(0xFFE8DAF2),
|
||||||
Color(0xFFB49EF4),
|
Color(0xFFB49EF4),
|
||||||
],
|
],
|
||||||
stops: [0.0, 0.3, 0.6, 1.0],
|
stops: [0.0, 0.3, 0.6, 1.0],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
child: SingleChildScrollView(
|
||||||
child: SingleChildScrollView(
|
child: ConstrainedBox(
|
||||||
child: ConstrainedBox(
|
constraints: BoxConstraints(minHeight: r.screenHeight),
|
||||||
constraints: BoxConstraints(minHeight: r.screenHeight),
|
child: IntrinsicHeight(
|
||||||
child: IntrinsicHeight(
|
child: Center(
|
||||||
child: Center(
|
child: CommonContainerAuth(
|
||||||
child: CommonContainerAuth(
|
child: Column(
|
||||||
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
||||||
children: [
|
// Logo
|
||||||
// Logo
|
Image.asset(
|
||||||
Image.asset(
|
AppAssets.taxgildelogoauth,
|
||||||
AppAssets.taxgildelogoauth,
|
width: logoWidth,
|
||||||
width: logoWidth,
|
height: logoHeight,
|
||||||
height: logoHeight,
|
fit: BoxFit.contain,
|
||||||
fit: BoxFit.contain,
|
|
||||||
),
|
|
||||||
SizedBox(height: spacingMD),
|
|
||||||
|
|
||||||
// Login Title
|
|
||||||
Text(
|
|
||||||
"Login",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: AppTextStyles.bold.copyWith(
|
|
||||||
fontSize: titleFontSize,
|
|
||||||
height: 1.3,
|
|
||||||
letterSpacing: 0.01 * titleFontSize,
|
|
||||||
color: AppColors.authheading,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: spacingMD),
|
||||||
SizedBox(height: spacingMD),
|
|
||||||
|
|
||||||
// Subtitle
|
// Login Title
|
||||||
Text(
|
Text(
|
||||||
"Enter your registered Mobile Number",
|
"Employee Login",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: AppTextStyles.bold.copyWith(
|
style: AppTextStyles.bold.copyWith(
|
||||||
fontSize: subtitleFontSize,
|
fontSize: titleFontSize,
|
||||||
height: 1.4,
|
color: AppColors.authheading,
|
||||||
letterSpacing: 0.03 * subtitleFontSize,
|
),
|
||||||
color: AppColors.authleading,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: spacingMD),
|
||||||
SizedBox(height: spacingLG),
|
|
||||||
|
|
||||||
// Mobile Number Input
|
// Subtitle
|
||||||
CommanTextFormField(
|
Text(
|
||||||
controller: _mobileController,
|
"Enter your Email and PIN",
|
||||||
hintText: 'Enter your Mobile Number',
|
textAlign: TextAlign.center,
|
||||||
keyboardType: TextInputType.phone,
|
style: AppTextStyles.bold.copyWith(
|
||||||
prefixIcon: Icons.phone_android,
|
fontSize: subtitleFontSize,
|
||||||
),
|
|
||||||
SizedBox(height: spacingLG),
|
|
||||||
|
|
||||||
// Terms and Conditions
|
|
||||||
Text.rich(
|
|
||||||
TextSpan(
|
|
||||||
text: "By signing up, you agree to the ",
|
|
||||||
style: AppTextStyles.medium.copyWith(
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
height: 1.8,
|
|
||||||
letterSpacing: 0.01,
|
|
||||||
color: AppColors.authleading,
|
color: AppColors.authleading,
|
||||||
),
|
),
|
||||||
children: [
|
|
||||||
TextSpan(
|
|
||||||
text: "Terms of Service ",
|
|
||||||
style: AppTextStyles.bold.copyWith(
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
height: 1.8,
|
|
||||||
letterSpacing: 0.01,
|
|
||||||
color: AppColors.authtermsandcondition,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextSpan(
|
|
||||||
text: "and ",
|
|
||||||
style: AppTextStyles.medium.copyWith(
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
height: 1.8,
|
|
||||||
letterSpacing: 0.01,
|
|
||||||
color: AppColors.authleading,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TextSpan(
|
|
||||||
text: "Data Processing Agreement",
|
|
||||||
style: AppTextStyles.bold.copyWith(
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
height: 1.8,
|
|
||||||
letterSpacing: 0.01,
|
|
||||||
color: AppColors.authtermsandcondition,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
SizedBox(height: spacingLG),
|
||||||
),
|
|
||||||
|
|
||||||
SizedBox(height: spacingLG),
|
// Email Input
|
||||||
|
CommanTextFormField(
|
||||||
// Login Button or Loading
|
controller: _emailController,
|
||||||
loginState.isLoading
|
hintText: 'Enter your Email',
|
||||||
? const CircularProgressIndicator()
|
keyboardType: TextInputType.emailAddress,
|
||||||
: CommanButton(
|
prefixIcon: Icons.email_outlined,
|
||||||
text: "Login",
|
hasError: _emailHasError,
|
||||||
onPressed: _handleLogin,
|
onChanged: (value) {
|
||||||
),
|
if (_emailHasError) {
|
||||||
|
setState(() => _emailHasError = false);
|
||||||
SizedBox(height: spacingSM),
|
}
|
||||||
|
},
|
||||||
Text(
|
|
||||||
"Other Login",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
|
||||||
fontSize: otherLoginFontSize,
|
|
||||||
height: 1.8,
|
|
||||||
letterSpacing: 0.13,
|
|
||||||
color: AppColors.authleading,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: spacingMD),
|
||||||
|
|
||||||
SizedBox(height: spacingXS),
|
// 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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
Text.rich(
|
SizedBox(height: spacingXS),
|
||||||
TextSpan(
|
Align(
|
||||||
text: "User Login? ",
|
alignment: Alignment.centerRight,
|
||||||
style: AppTextStyles.bold.copyWith(
|
child: GestureDetector(
|
||||||
fontSize: linkFontSize,
|
onTap: () {
|
||||||
color: AppColors.black,
|
Get.toNamed(
|
||||||
),
|
ConstRouters.forgotPassword,
|
||||||
children: [
|
arguments: {'isEmployee': true},
|
||||||
TextSpan(
|
);
|
||||||
text: "Click Here",
|
},
|
||||||
|
child: Text(
|
||||||
|
"Forgot Password?",
|
||||||
style: AppTextStyles.bold.copyWith(
|
style: AppTextStyles.bold.copyWith(
|
||||||
fontSize: linkFontSize,
|
fontSize: linkFontSize,
|
||||||
color: AppColors.authsignup,
|
color: AppColors.authchange,
|
||||||
),
|
),
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () {
|
|
||||||
Get.offNamed(ConstRouters.login);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
SizedBox(height: spacingLG),
|
||||||
|
|
||||||
|
// Terms and Conditions
|
||||||
|
Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
text: "By signing up, you agree to the ",
|
||||||
|
style: AppTextStyles.medium.copyWith(
|
||||||
|
fontSize: termsFontSize,
|
||||||
|
color: AppColors.authleading,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: "Terms of Service ",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: termsFontSize,
|
||||||
|
color: AppColors.authtermsandcondition,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
text: "and ",
|
||||||
|
style: AppTextStyles.medium.copyWith(
|
||||||
|
fontSize: termsFontSize,
|
||||||
|
color: AppColors.authleading,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
text: "Data Processing Agreement",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: termsFontSize,
|
||||||
|
color: AppColors.authtermsandcondition,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: spacingLG),
|
||||||
|
|
||||||
|
// Login Button or Loading
|
||||||
|
loginState.isLoading
|
||||||
|
? const CircularProgressIndicator()
|
||||||
|
: CommanButton(
|
||||||
|
text: "Login",
|
||||||
|
onPressed: _handleLogin,
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
|
Text(
|
||||||
|
"Other Login",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
|
fontSize: otherLoginFontSize,
|
||||||
|
color: AppColors.authleading,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
SizedBox(height: spacingXS),
|
||||||
|
|
||||||
|
Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
text: "User Login? ",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: linkFontSize,
|
||||||
|
color: AppColors.black,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: "Click Here",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: linkFontSize,
|
||||||
|
color: AppColors.authsignup,
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
Get.offNamed(ConstRouters.login);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -277,7 +419,6 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,9 @@ import 'package:taxglide/consts/comman_container_auth.dart';
|
|||||||
import 'package:taxglide/consts/responsive_helper.dart';
|
import 'package:taxglide/consts/responsive_helper.dart';
|
||||||
import 'package:taxglide/consts/validation_popup.dart';
|
import 'package:taxglide/consts/validation_popup.dart';
|
||||||
import 'package:taxglide/controller/api_contoller.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 '../router/consts_routers.dart';
|
import 'package:taxglide/consts/app_style.dart';
|
||||||
|
|
||||||
class EmployeeOtpScreen extends ConsumerStatefulWidget {
|
class EmployeeOtpScreen extends ConsumerStatefulWidget {
|
||||||
const EmployeeOtpScreen({super.key});
|
const EmployeeOtpScreen({super.key});
|
||||||
@ -32,13 +32,16 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
int _remainingSeconds = 600;
|
int _remainingSeconds = 600;
|
||||||
bool _canResend = false;
|
bool _canResend = false;
|
||||||
|
|
||||||
late String mobile;
|
late String _identifier;
|
||||||
|
bool _fromForgot = false;
|
||||||
|
bool _isEmployee = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final args = Get.arguments as Map<String, dynamic>?;
|
final args = Get.arguments as Map<String, dynamic>? ?? {};
|
||||||
mobile = args?['mobile'] ?? '';
|
_fromForgot = args['fromForgot'] ?? false;
|
||||||
|
_identifier = args['email'] ?? args['mobile'] ?? '';
|
||||||
|
|
||||||
for (int i = 0; i < otpLength; i++) {
|
for (int i = 0; i < otpLength; i++) {
|
||||||
_controllers.add(TextEditingController());
|
_controllers.add(TextEditingController());
|
||||||
@ -75,87 +78,89 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
|
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _resendOtp() async {
|
void _resendOtp() async {
|
||||||
if (!_canResend) return;
|
if (!_canResend) return;
|
||||||
|
|
||||||
for (var controller in _controllers) controller.clear();
|
for (var controller in _controllers) controller.clear();
|
||||||
setState(() => otpValue = '');
|
setState(() => otpValue = '');
|
||||||
_focusNodes[0].requestFocus();
|
_focusNodes[0].requestFocus();
|
||||||
|
|
||||||
try {
|
if (_fromForgot) {
|
||||||
await ref.read(employeeloginProvider.notifier).login(mobile);
|
await ref.read(forgotPasswordProvider.notifier).requestOtp(_identifier, _isEmployee);
|
||||||
final loginState = ref.read(employeeloginProvider);
|
final state = ref.read(forgotPasswordProvider);
|
||||||
loginState.when(
|
state.when(
|
||||||
data: (result) {
|
data: (result) {
|
||||||
if (result['success'] == true) {
|
if (result['success'] == true) {
|
||||||
_validationPopup.showSuccessMessage(
|
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
|
||||||
context,
|
|
||||||
"OTP has been resent successfully!",
|
|
||||||
);
|
|
||||||
_startTimer();
|
_startTimer();
|
||||||
} else {
|
} else {
|
||||||
_validationPopup.showErrorMessage(
|
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
|
||||||
context,
|
|
||||||
result['error'] ?? "Failed to resend OTP",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loading: () {},
|
loading: () {},
|
||||||
error: (error, _) {
|
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
|
||||||
_validationPopup.showErrorMessage(
|
|
||||||
context,
|
|
||||||
"Failed to resend OTP. Please try again.",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} else {
|
||||||
_validationPopup.showErrorMessage(
|
await ref.read(employeeloginProvider.notifier).login(_identifier);
|
||||||
context,
|
final state = ref.read(employeeloginProvider);
|
||||||
"An error occurred. Please try again.",
|
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"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _verifyOtp() async {
|
void _verifyOtp() async {
|
||||||
if (otpValue.length != otpLength) {
|
if (otpValue.length != otpLength) {
|
||||||
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
|
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ref.read(employeeloginProvider.notifier).verifyOtp(mobile, otpValue);
|
if (_fromForgot) {
|
||||||
final loginState = ref.read(employeeloginProvider);
|
await ref.read(forgotPasswordProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||||
|
final state = ref.read(forgotPasswordProvider);
|
||||||
loginState.when(
|
state.when(
|
||||||
data: (result) {
|
data: (result) {
|
||||||
if (result['success'] == true) {
|
if (result['success'] == true) {
|
||||||
_validationPopup.showSuccessMessage(
|
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||||
context,
|
Get.toNamed(ConstRouters.mpinSet);
|
||||||
"OTP Verified Successfully!",
|
} else {
|
||||||
);
|
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
}
|
||||||
Get.offAll(() => const MainController());
|
},
|
||||||
});
|
loading: () {},
|
||||||
} else {
|
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||||
_validationPopup.showErrorMessage(
|
);
|
||||||
context,
|
} else {
|
||||||
result['error'] ?? "Invalid OTP. Please try again.",
|
await ref.read(employeeloginProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||||
);
|
final state = ref.read(employeeloginProvider);
|
||||||
}
|
state.when(
|
||||||
},
|
data: (result) {
|
||||||
loading: () {},
|
if (result['success'] == true) {
|
||||||
error: (error, _) {
|
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||||
_validationPopup.showErrorMessage(
|
Get.offAllNamed(ConstRouters.mpinSet);
|
||||||
context,
|
} else {
|
||||||
"Failed to verify OTP. Please try again.",
|
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||||
);
|
}
|
||||||
},
|
},
|
||||||
);
|
loading: () {},
|
||||||
|
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onOtpChange(int index, String value) {
|
void _onOtpChange(int index, String value) {
|
||||||
if (value.isNotEmpty && index < otpLength - 1) {
|
if (value.isNotEmpty && index < otpLength - 1) {
|
||||||
_focusNodes[index + 1].requestFocus();
|
_focusNodes[index + 1].requestFocus();
|
||||||
} else if (value.isEmpty && index > 0) {
|
}
|
||||||
|
if (value.isEmpty && index > 0) {
|
||||||
_focusNodes[index - 1].requestFocus();
|
_focusNodes[index - 1].requestFocus();
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -165,40 +170,25 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final loginState = ref.watch(employeeloginProvider);
|
final isLoading = _fromForgot
|
||||||
final isLoading = loginState.isLoading;
|
? ref.watch(forgotPasswordProvider).isLoading
|
||||||
|
: ref.watch(employeeloginProvider).isLoading;
|
||||||
|
|
||||||
// Initialize responsive utils
|
|
||||||
final r = ResponsiveUtils(context);
|
final r = ResponsiveUtils(context);
|
||||||
|
|
||||||
// Responsive values
|
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
|
||||||
final logoWidth = r.getValue<double>(
|
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
|
||||||
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 titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
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 resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||||
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
||||||
|
|
||||||
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
||||||
final otpBoxHeight = r.getValue<double>(
|
final otpBoxHeight = r.getValue<double>(mobile: 48, tablet: 56, desktop: 64);
|
||||||
mobile: 48,
|
|
||||||
tablet: 56,
|
|
||||||
desktop: 64,
|
|
||||||
);
|
|
||||||
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||||
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||||
final otpBoxRadius = 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 spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||||
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
||||||
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
||||||
@ -206,7 +196,6 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
// Gradient background
|
|
||||||
Container(
|
Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
@ -222,8 +211,6 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Scrollable content
|
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: r.screenHeight,
|
height: r.screenHeight,
|
||||||
@ -231,9 +218,7 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
child: CommonContainerAuth(
|
child: CommonContainerAuth(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
// Logo
|
|
||||||
Image.asset(
|
Image.asset(
|
||||||
AppAssets.taxgildelogoauth,
|
AppAssets.taxgildelogoauth,
|
||||||
width: logoWidth,
|
width: logoWidth,
|
||||||
@ -241,145 +226,90 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingSM),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Title
|
|
||||||
Text(
|
Text(
|
||||||
"Enter OTP",
|
"Enter Staff OTP",
|
||||||
textAlign: TextAlign.center,
|
style: AppTextStyles.bold.copyWith(
|
||||||
style: TextStyle(
|
|
||||||
fontFamily: "Gilroy",
|
|
||||||
fontSize: titleFontSize,
|
fontSize: titleFontSize,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
height: 1.3,
|
|
||||||
letterSpacing: 0.01 * titleFontSize,
|
|
||||||
color: AppColors.authheading,
|
color: AppColors.authheading,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingSM),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Subtitle
|
|
||||||
Text(
|
Text(
|
||||||
"OTP has been sent to your registered mobile number",
|
"OTP has been sent to ${_identifier}",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: AppTextStyles.medium.copyWith(
|
||||||
fontFamily: "Gilroy",
|
|
||||||
fontSize: subtitleFontSize,
|
fontSize: subtitleFontSize,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
height: 1.4,
|
|
||||||
letterSpacing: 0.03 * subtitleFontSize,
|
|
||||||
color: AppColors.authleading,
|
color: AppColors.authleading,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingMD),
|
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(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: List.generate(otpLength, (index) {
|
children: List.generate(otpLength, (index) {
|
||||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.symmetric(
|
margin: EdgeInsets.symmetric(horizontal: otpBoxMargin),
|
||||||
horizontal: otpBoxMargin,
|
|
||||||
),
|
|
||||||
width: otpBoxWidth,
|
width: otpBoxWidth,
|
||||||
height: otpBoxHeight,
|
height: otpBoxHeight,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isFilled
|
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||||
? AppColors.commanbutton
|
|
||||||
: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(otpBoxRadius),
|
borderRadius: BorderRadius.circular(otpBoxRadius),
|
||||||
border: Border.all(
|
border: Border.all(color: const Color(0xFFDFDFDF)),
|
||||||
color: const Color(0xFFDFDFDF),
|
|
||||||
),
|
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: const Color(
|
color: const Color(0xFFBDBDBD).withOpacity(0.25),
|
||||||
0xFFBDBDBD,
|
|
||||||
).withOpacity(0.25),
|
|
||||||
blurRadius: 7,
|
blurRadius: 7,
|
||||||
offset: const Offset(0, 1),
|
offset: const Offset(0, 1),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: TextField(
|
child: KeyboardListener(
|
||||||
controller: _controllers[index],
|
focusNode: FocusNode(),
|
||||||
focusNode: _focusNodes[index],
|
onKeyEvent: (event) {
|
||||||
textAlign: TextAlign.center,
|
if (event is KeyDownEvent &&
|
||||||
keyboardType: TextInputType.number,
|
event.logicalKey ==
|
||||||
maxLength: 1,
|
LogicalKeyboardKey.backspace) {
|
||||||
enabled: !isLoading,
|
if (_controllers[index].text.isEmpty &&
|
||||||
style: TextStyle(
|
index > 0) {
|
||||||
fontFamily: "Gilroy",
|
_focusNodes[index - 1].requestFocus();
|
||||||
fontWeight: FontWeight.w400,
|
}
|
||||||
fontSize: otpFontSize,
|
}
|
||||||
letterSpacing: 0.03 * otpFontSize,
|
},
|
||||||
color: isFilled ? Colors.white : Colors.black,
|
child: TextField(
|
||||||
),
|
controller: _controllers[index],
|
||||||
decoration: const InputDecoration(
|
focusNode: _focusNodes[index],
|
||||||
counterText: '',
|
textAlign: TextAlign.center,
|
||||||
border: InputBorder.none,
|
keyboardType: TextInputType.number,
|
||||||
),
|
maxLength: 1,
|
||||||
onChanged: (value) =>
|
enabled: !isLoading,
|
||||||
_onOtpChange(index, value),
|
style: TextStyle(
|
||||||
),
|
fontFamily: "Gilroy",
|
||||||
),
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: otpFontSize,
|
||||||
|
color: isFilled ? Colors.white : Colors.black,
|
||||||
|
),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
counterText: '',
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
onChanged: (value) =>
|
||||||
|
_onOtpChange(index, value),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingXS),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Resend OTP
|
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _canResend && !isLoading ? _resendOtp : null,
|
onTap: _canResend && !isLoading ? _resendOtp : null,
|
||||||
child: Text(
|
child: Text(
|
||||||
"Resend",
|
"Resend",
|
||||||
textAlign: TextAlign.center,
|
style: AppTextStyles.medium.copyWith(
|
||||||
style: TextStyle(
|
|
||||||
fontFamily: "Gilroy",
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: resendFontSize,
|
fontSize: resendFontSize,
|
||||||
height: 1.4,
|
|
||||||
letterSpacing: 0.02 * resendFontSize,
|
|
||||||
color: _canResend && !isLoading
|
color: _canResend && !isLoading
|
||||||
? AppColors.authchange
|
? AppColors.authchange
|
||||||
: Colors.grey,
|
: Colors.grey,
|
||||||
@ -388,22 +318,14 @@ class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingSM),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Timer
|
|
||||||
Text(
|
Text(
|
||||||
_formatTime(_remainingSeconds),
|
_formatTime(_remainingSeconds),
|
||||||
style: TextStyle(
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
fontFamily: "Gilroy",
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
fontSize: timerFontSize,
|
fontSize: timerFontSize,
|
||||||
color: _remainingSeconds > 0
|
color: _remainingSeconds > 0 ? AppColors.authheading : Colors.red,
|
||||||
? AppColors.authheading
|
|
||||||
: Colors.red,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingLG),
|
SizedBox(height: spacingLG),
|
||||||
|
|
||||||
// Verify Button
|
|
||||||
isLoading
|
isLoading
|
||||||
? const CircularProgressIndicator()
|
? const CircularProgressIndicator()
|
||||||
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
||||||
|
|||||||
168
lib/auth/forgot_screen.dart
Normal file
168
lib/auth/forgot_screen.dart
Normal 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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:taxglide/consts/app_asstes.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/controller/api_contoller.dart';
|
||||||
import 'package:taxglide/router/consts_routers.dart';
|
import 'package:taxglide/router/consts_routers.dart';
|
||||||
import 'package:taxglide/consts/app_style.dart';
|
import 'package:taxglide/consts/app_style.dart';
|
||||||
|
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
||||||
|
|
||||||
class LoginScreen extends ConsumerStatefulWidget {
|
class LoginScreen extends ConsumerStatefulWidget {
|
||||||
const LoginScreen({super.key});
|
const LoginScreen({super.key});
|
||||||
@ -22,47 +24,101 @@ class LoginScreen extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||||
final TextEditingController _mobileController = TextEditingController();
|
final TextEditingController _emailController = TextEditingController();
|
||||||
final ValidationPopup _validationPopup = ValidationPopup();
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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;
|
final args = Get.arguments;
|
||||||
if (args != null && args is Map<String, dynamic>) {
|
if (args != null && args is Map<String, dynamic>) {
|
||||||
final mobile = args['mobile'] ?? '';
|
final email = args['email'] ?? '';
|
||||||
if (mobile.isNotEmpty) {
|
if (email.isNotEmpty) {
|
||||||
_mobileController.text = mobile;
|
_emailController.text = email;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_mobileController.dispose();
|
_emailController.dispose();
|
||||||
|
for (var controller in _pinControllers) {
|
||||||
|
controller.dispose();
|
||||||
|
}
|
||||||
|
for (var node in _pinFocusNodes) {
|
||||||
|
node.dispose();
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleLogin() async {
|
void _onPinChange(int index, String value) {
|
||||||
final mobile = _mobileController.text.trim();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ref.read(loginProvider.notifier).login(mobile);
|
await ref.read(loginProvider.notifier).loginWithPin(email, pin);
|
||||||
final state = ref.read(loginProvider);
|
final state = ref.read(loginProvider);
|
||||||
|
|
||||||
state.when(
|
state.when(
|
||||||
data: (data) {
|
data: (data) {
|
||||||
if (data['success'] == true) {
|
if (data['success'] == true) {
|
||||||
Get.toNamed(ConstRouters.otp, arguments: {'mobile': mobile});
|
|
||||||
_validationPopup.showSuccessMessage(
|
_validationPopup.showSuccessMessage(
|
||||||
context,
|
context,
|
||||||
"OTP sent successfully!",
|
"Login Successful!",
|
||||||
);
|
);
|
||||||
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
|
Get.offAll(() => const MainController());
|
||||||
|
});
|
||||||
} else if (data['error'] != null) {
|
} else if (data['error'] != null) {
|
||||||
_validationPopup.showErrorMessage(context, data['error'].toString());
|
_validationPopup.showErrorMessage(context, data['error'].toString());
|
||||||
|
setState(() {
|
||||||
|
_emailHasError = true;
|
||||||
|
_pinHasError = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loading: () {},
|
loading: () {},
|
||||||
@ -78,26 +134,22 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
|||||||
final policyAsync = ref.watch(policyProvider);
|
final policyAsync = ref.watch(policyProvider);
|
||||||
final termsAsync = ref.watch(termsProvider);
|
final termsAsync = ref.watch(termsProvider);
|
||||||
|
|
||||||
// Initialize responsive utils
|
|
||||||
final r = ResponsiveUtils(context);
|
final r = ResponsiveUtils(context);
|
||||||
|
|
||||||
// Responsive values
|
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
|
||||||
final logoWidth = r.getValue<double>(
|
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
|
||||||
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 titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||||
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
||||||
final signupFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
final signupFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||||
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
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 spacingXS = r.spacing(mobile: 10, tablet: 15, desktop: 18);
|
||||||
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
||||||
final spacingMD = r.spacing(mobile: 20, tablet: 22, desktop: 26);
|
final spacingMD = r.spacing(mobile: 20, tablet: 22, desktop: 26);
|
||||||
@ -105,239 +157,290 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
|||||||
|
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: true,
|
canPop: true,
|
||||||
onPopInvokedWithResult: (didPop, result) {
|
|
||||||
// Handle custom behavior here if needed in the future
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
resizeToAvoidBottomInset: true,
|
resizeToAvoidBottomInset: true,
|
||||||
body: Container(
|
body: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
colors: [
|
colors: [
|
||||||
Color(0xFFFFF8F0),
|
Color(0xFFFFF8F0),
|
||||||
Color(0xFFEBC894),
|
Color(0xFFEBC894),
|
||||||
Color(0xFFE8DAF2),
|
Color(0xFFE8DAF2),
|
||||||
Color(0xFFB49EF4),
|
Color(0xFFB49EF4),
|
||||||
],
|
],
|
||||||
stops: [0.0, 0.3, 0.6, 1.0],
|
stops: [0.0, 0.3, 0.6, 1.0],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
child: SingleChildScrollView(
|
||||||
child: SingleChildScrollView(
|
child: ConstrainedBox(
|
||||||
child: ConstrainedBox(
|
constraints: BoxConstraints(minHeight: r.screenHeight),
|
||||||
constraints: BoxConstraints(minHeight: r.screenHeight),
|
child: IntrinsicHeight(
|
||||||
child: IntrinsicHeight(
|
child: Center(
|
||||||
child: Center(
|
child: CommonContainerAuth(
|
||||||
child: CommonContainerAuth(
|
child: Column(
|
||||||
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
||||||
children: [
|
Image.asset(
|
||||||
// Logo
|
AppAssets.taxgildelogoauth,
|
||||||
Image.asset(
|
width: logoWidth,
|
||||||
AppAssets.taxgildelogoauth,
|
height: logoHeight,
|
||||||
width: logoWidth,
|
|
||||||
height: logoHeight,
|
|
||||||
),
|
|
||||||
SizedBox(height: spacingSM),
|
|
||||||
|
|
||||||
// Title
|
|
||||||
Text(
|
|
||||||
"Login",
|
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
|
||||||
fontSize: titleFontSize,
|
|
||||||
color: AppColors.authheading,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: spacingSM),
|
||||||
SizedBox(height: spacingSM),
|
Text(
|
||||||
|
"Login",
|
||||||
// Subtitle
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
Text(
|
fontSize: titleFontSize,
|
||||||
"Enter your Mobile Number",
|
color: AppColors.authheading,
|
||||||
textAlign: TextAlign.center,
|
),
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
|
||||||
fontSize: subtitleFontSize,
|
|
||||||
color: AppColors.authleading,
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: spacingSM),
|
||||||
SizedBox(height: spacingLG),
|
Text(
|
||||||
|
"Enter your Email and PIN",
|
||||||
// Mobile TextField
|
textAlign: TextAlign.center,
|
||||||
CommanTextFormField(
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
controller: _mobileController,
|
fontSize: subtitleFontSize,
|
||||||
hintText: 'Enter your Mobile Number',
|
|
||||||
keyboardType: TextInputType.phone,
|
|
||||||
prefixIcon: Icons.mobile_screen_share,
|
|
||||||
),
|
|
||||||
SizedBox(height: spacingLG),
|
|
||||||
|
|
||||||
// Terms and Policy
|
|
||||||
Text.rich(
|
|
||||||
TextSpan(
|
|
||||||
text: "By signing up, you agree to the ",
|
|
||||||
style: AppTextStyles.medium.copyWith(
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
color: AppColors.authleading,
|
color: AppColors.authleading,
|
||||||
),
|
),
|
||||||
children: [
|
|
||||||
TextSpan(
|
|
||||||
text: "Terms of Service ",
|
|
||||||
style: AppTextStyles.bold.copyWith(
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
color: AppColors.authtermsandcondition,
|
|
||||||
),
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () {
|
|
||||||
termsAsync.when(
|
|
||||||
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",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const TextSpan(text: "and "),
|
|
||||||
TextSpan(
|
|
||||||
text: "Data Processing Agreement",
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: FontWeight.w700,
|
|
||||||
fontSize: termsFontSize,
|
|
||||||
color: AppColors.authtermsandcondition,
|
|
||||||
),
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () {
|
|
||||||
policyAsync.when(
|
|
||||||
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",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
SizedBox(height: spacingLG),
|
||||||
),
|
CommanTextFormField(
|
||||||
|
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),
|
||||||
|
|
||||||
SizedBox(height: spacingSM),
|
// PIN Boxes
|
||||||
Text("Or",style: AppTextStyles.medium.copyWith(
|
Row(
|
||||||
fontSize: spacingSM,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
color: AppColors.authleading,
|
children: List.generate(pinLength, (index) {
|
||||||
),),
|
bool isFilled = _pinControllers[index].text.isNotEmpty;
|
||||||
SizedBox(height: spacingSM),
|
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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
|
||||||
// Sign up
|
SizedBox(height: spacingXS),
|
||||||
Text.rich(
|
Align(
|
||||||
TextSpan(
|
alignment: Alignment.centerRight,
|
||||||
text: "Didn't Have account? ",
|
child: GestureDetector(
|
||||||
style: AppTextStyles.bold.copyWith(
|
onTap: () {
|
||||||
fontSize: signupFontSize,
|
Get.toNamed(
|
||||||
color: AppColors.black,
|
ConstRouters.forgotPassword,
|
||||||
),
|
arguments: {'isEmployee': false},
|
||||||
children: [
|
);
|
||||||
TextSpan(
|
},
|
||||||
text: "Sign Up",
|
child: Text(
|
||||||
|
"Forgot Password?",
|
||||||
style: AppTextStyles.bold.copyWith(
|
style: AppTextStyles.bold.copyWith(
|
||||||
fontSize: signupFontSize,
|
fontSize: signupFontSize,
|
||||||
color: AppColors.authsignup,
|
color: AppColors.authchange,
|
||||||
),
|
),
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () {
|
|
||||||
Get.offNamed(ConstRouters.signup);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
SizedBox(height: spacingLG),
|
|
||||||
|
|
||||||
// Login Button
|
SizedBox(height: spacingLG),
|
||||||
loginState.isLoading
|
Text.rich(
|
||||||
? const CircularProgressIndicator()
|
TextSpan(
|
||||||
: CommanButton(
|
text: "By signing up, you agree to the ",
|
||||||
text: "Login",
|
style: AppTextStyles.medium.copyWith(
|
||||||
onPressed: _handleLogin,
|
fontSize: termsFontSize,
|
||||||
|
color: AppColors.authleading,
|
||||||
),
|
),
|
||||||
|
children: [
|
||||||
SizedBox(height: spacingMD),
|
TextSpan(
|
||||||
|
text: "Terms of Service ",
|
||||||
Text(
|
style: AppTextStyles.bold.copyWith(
|
||||||
"Other Login",
|
fontSize: termsFontSize,
|
||||||
textAlign: TextAlign.center,
|
color: AppColors.authtermsandcondition,
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
),
|
||||||
fontSize: otherLoginFontSize,
|
recognizer: TapGestureRecognizer()
|
||||||
height: 1.8,
|
..onTap = () {
|
||||||
letterSpacing: 0.13,
|
termsAsync.when(
|
||||||
|
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"),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const TextSpan(text: "and "),
|
||||||
|
TextSpan(
|
||||||
|
text: "Data Processing Agreement",
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.w700,
|
||||||
|
fontSize: termsFontSize,
|
||||||
|
color: AppColors.authtermsandcondition,
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
policyAsync.when(
|
||||||
|
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"),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
SizedBox(height: spacingSM),
|
||||||
|
Text("Or", style: AppTextStyles.medium.copyWith(
|
||||||
|
fontSize: 14,
|
||||||
color: AppColors.authleading,
|
color: AppColors.authleading,
|
||||||
),
|
)),
|
||||||
),
|
SizedBox(height: spacingSM),
|
||||||
|
Text.rich(
|
||||||
SizedBox(height: spacingXS),
|
TextSpan(
|
||||||
|
text: "Didn't Have account? ",
|
||||||
Text.rich(
|
style: AppTextStyles.bold.copyWith(
|
||||||
TextSpan(
|
fontSize: signupFontSize,
|
||||||
text: "Staff Login? ",
|
color: AppColors.black,
|
||||||
style: AppTextStyles.bold.copyWith(
|
|
||||||
fontSize: signupFontSize,
|
|
||||||
color: AppColors.black,
|
|
||||||
),
|
|
||||||
children: [
|
|
||||||
TextSpan(
|
|
||||||
text: "Click Here",
|
|
||||||
style: AppTextStyles.bold.copyWith(
|
|
||||||
fontSize: signupFontSize,
|
|
||||||
color: AppColors.authsignup,
|
|
||||||
),
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () {
|
|
||||||
Get.offNamed(ConstRouters.employeelogin);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: "Sign Up",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: signupFontSize,
|
||||||
|
color: AppColors.authsignup,
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
Get.offNamed(ConstRouters.signup);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: spacingLG),
|
||||||
],
|
loginState.isLoading
|
||||||
|
? const CircularProgressIndicator()
|
||||||
|
: CommanButton(
|
||||||
|
text: "Login",
|
||||||
|
onPressed: _handleLogin,
|
||||||
|
),
|
||||||
|
SizedBox(height: spacingMD),
|
||||||
|
Text(
|
||||||
|
"Other Login",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
|
fontSize: otherLoginFontSize,
|
||||||
|
color: AppColors.authleading,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: spacingXS),
|
||||||
|
Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
text: "Staff Login? ",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: signupFontSize,
|
||||||
|
color: AppColors.black,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: "Click Here",
|
||||||
|
style: AppTextStyles.bold.copyWith(
|
||||||
|
fontSize: signupFontSize,
|
||||||
|
color: AppColors.authsignup,
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
Get.offNamed(ConstRouters.employeelogin);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -345,7 +448,6 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
252
lib/auth/mpin_set_screen.dart
Normal file
252
lib/auth/mpin_set_screen.dart
Normal 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,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,8 +11,7 @@ import 'package:taxglide/consts/responsive_helper.dart';
|
|||||||
import 'package:taxglide/consts/validation_popup.dart';
|
import 'package:taxglide/consts/validation_popup.dart';
|
||||||
import 'package:taxglide/controller/api_contoller.dart';
|
import 'package:taxglide/controller/api_contoller.dart';
|
||||||
import 'package:taxglide/router/consts_routers.dart';
|
import 'package:taxglide/router/consts_routers.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
|
||||||
import 'package:taxglide/consts/app_style.dart';
|
import 'package:taxglide/consts/app_style.dart';
|
||||||
|
|
||||||
class OtpScreen extends ConsumerStatefulWidget {
|
class OtpScreen extends ConsumerStatefulWidget {
|
||||||
@ -33,13 +32,17 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
int _remainingSeconds = 600;
|
int _remainingSeconds = 600;
|
||||||
bool _canResend = false;
|
bool _canResend = false;
|
||||||
|
|
||||||
late String mobile;
|
late String _identifier; // Email or Mobile
|
||||||
|
bool _fromForgot = false;
|
||||||
|
bool _isEmployee = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final args = Get.arguments as Map<String, dynamic>;
|
final args = Get.arguments as Map<String, dynamic>? ?? {};
|
||||||
mobile = args['mobile'] ?? '';
|
_fromForgot = args['fromForgot'] ?? false;
|
||||||
|
_isEmployee = args['isEmployee'] ?? false;
|
||||||
|
_identifier = args['email'] ?? args['mobile'] ?? '';
|
||||||
|
|
||||||
for (int i = 0; i < otpLength; i++) {
|
for (int i = 0; i < otpLength; i++) {
|
||||||
_controllers.add(TextEditingController());
|
_controllers.add(TextEditingController());
|
||||||
@ -82,38 +85,36 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
setState(() => otpValue = '');
|
setState(() => otpValue = '');
|
||||||
_focusNodes[0].requestFocus();
|
_focusNodes[0].requestFocus();
|
||||||
|
|
||||||
try {
|
if (_fromForgot) {
|
||||||
await ref.read(loginProvider.notifier).login(mobile);
|
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);
|
final loginState = ref.read(loginProvider);
|
||||||
loginState.when(
|
loginState.when(
|
||||||
data: (result) {
|
data: (result) {
|
||||||
if (result['success'] == true) {
|
if (result['success'] == true) {
|
||||||
_validationPopup.showSuccessMessage(
|
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
|
||||||
context,
|
|
||||||
"OTP has been resent successfully!",
|
|
||||||
);
|
|
||||||
_startTimer();
|
_startTimer();
|
||||||
for (var controller in _controllers) controller.clear();
|
|
||||||
setState(() => otpValue = '');
|
|
||||||
} else {
|
} else {
|
||||||
_validationPopup.showErrorMessage(
|
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
|
||||||
context,
|
|
||||||
result['error'] ?? "Failed to resend OTP",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loading: () {},
|
loading: () {},
|
||||||
error: (error, stack) {
|
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
|
||||||
_validationPopup.showErrorMessage(
|
|
||||||
context,
|
|
||||||
"Failed to resend OTP. Please try again.",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
_validationPopup.showErrorMessage(
|
|
||||||
context,
|
|
||||||
"An error occurred. Please try again.",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,34 +125,38 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ref.read(loginProvider.notifier).verifyOtp(mobile, otpValue);
|
if (_fromForgot) {
|
||||||
final loginState = ref.read(loginProvider);
|
await ref.read(forgotPasswordProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||||
|
final state = ref.read(forgotPasswordProvider);
|
||||||
loginState.when(
|
state.when(
|
||||||
data: (result) {
|
data: (result) {
|
||||||
if (result['success'] == true) {
|
if (result['success'] == true) {
|
||||||
_validationPopup.showSuccessMessage(
|
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||||
context,
|
Get.toNamed(ConstRouters.mpinSet);
|
||||||
"OTP Verified Successfully!",
|
} else {
|
||||||
);
|
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
}
|
||||||
Get.offAll(() => MainController());
|
},
|
||||||
});
|
loading: () {},
|
||||||
} else {
|
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||||
_validationPopup.showErrorMessage(
|
);
|
||||||
context,
|
} else {
|
||||||
result['error'] ?? "Invalid OTP. Please try again.",
|
// Original mobile login verify
|
||||||
);
|
await ref.read(loginProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||||
}
|
final state = ref.read(loginProvider);
|
||||||
},
|
state.when(
|
||||||
loading: () {},
|
data: (result) {
|
||||||
error: (error, stack) {
|
if (result['success'] == true) {
|
||||||
_validationPopup.showErrorMessage(
|
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||||
context,
|
Get.offAllNamed(ConstRouters.mpinSet);
|
||||||
"Failed to verify OTP. Please try again.",
|
} else {
|
||||||
);
|
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||||
},
|
}
|
||||||
);
|
},
|
||||||
|
loading: () {},
|
||||||
|
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onOtpChange(int index, String value) {
|
void _onOtpChange(int index, String value) {
|
||||||
@ -168,40 +173,25 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final loginState = ref.watch(loginProvider);
|
final isLoading = _fromForgot
|
||||||
final isLoading = loginState is AsyncLoading;
|
? ref.watch(forgotPasswordProvider).isLoading
|
||||||
|
: ref.watch(loginProvider).isLoading;
|
||||||
|
|
||||||
// Initialize responsive utils
|
|
||||||
final r = ResponsiveUtils(context);
|
final r = ResponsiveUtils(context);
|
||||||
|
|
||||||
// Responsive values
|
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
|
||||||
final logoWidth = r.getValue<double>(
|
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
|
||||||
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 titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
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 resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||||
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
||||||
|
|
||||||
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
||||||
final otpBoxHeight = r.getValue<double>(
|
final otpBoxHeight = r.getValue<double>(mobile: 48, tablet: 56, desktop: 64);
|
||||||
mobile: 48,
|
|
||||||
tablet: 56,
|
|
||||||
desktop: 64,
|
|
||||||
);
|
|
||||||
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||||
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||||
final otpBoxRadius = 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 spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||||
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
||||||
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
||||||
@ -209,7 +199,6 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
// Background gradient
|
|
||||||
Container(
|
Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
@ -225,8 +214,6 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Scrollable content
|
|
||||||
SingleChildScrollView(
|
SingleChildScrollView(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: r.screenHeight,
|
height: r.screenHeight,
|
||||||
@ -234,9 +221,7 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
child: CommonContainerAuth(
|
child: CommonContainerAuth(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
// Logo
|
|
||||||
Image.asset(
|
Image.asset(
|
||||||
AppAssets.taxgildelogoauth,
|
AppAssets.taxgildelogoauth,
|
||||||
width: logoWidth,
|
width: logoWidth,
|
||||||
@ -244,135 +229,90 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingSM),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Title
|
|
||||||
Text(
|
Text(
|
||||||
"Enter OTP",
|
"Enter OTP",
|
||||||
textAlign: TextAlign.center,
|
style: AppTextStyles.bold.copyWith(
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
|
||||||
fontSize: titleFontSize,
|
fontSize: titleFontSize,
|
||||||
height: 1.3,
|
|
||||||
letterSpacing: 0.01 * titleFontSize,
|
|
||||||
color: AppColors.authheading,
|
color: AppColors.authheading,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingSM),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Subtitle
|
|
||||||
Text(
|
Text(
|
||||||
"OTP has been sent to your registered mobile number",
|
"OTP has been sent to ${_identifier}",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
style: AppTextStyles.medium.copyWith(
|
||||||
fontSize: subtitleFontSize,
|
fontSize: subtitleFontSize,
|
||||||
height: 1.4,
|
|
||||||
letterSpacing: 0.03 * subtitleFontSize,
|
|
||||||
color: AppColors.authleading,
|
color: AppColors.authleading,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingMD),
|
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(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: List.generate(otpLength, (index) {
|
children: List.generate(otpLength, (index) {
|
||||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.symmetric(
|
margin: EdgeInsets.symmetric(horizontal: otpBoxMargin),
|
||||||
horizontal: otpBoxMargin,
|
|
||||||
),
|
|
||||||
width: otpBoxWidth,
|
width: otpBoxWidth,
|
||||||
height: otpBoxHeight,
|
height: otpBoxHeight,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isFilled
|
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||||
? AppColors.commanbutton
|
|
||||||
: Colors.white,
|
|
||||||
borderRadius: BorderRadius.circular(otpBoxRadius),
|
borderRadius: BorderRadius.circular(otpBoxRadius),
|
||||||
border: Border.all(
|
border: Border.all(color: const Color(0xFFDFDFDF)),
|
||||||
color: const Color(0xFFDFDFDF),
|
|
||||||
),
|
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: const Color(
|
color: const Color(0xFFBDBDBD).withOpacity(0.25),
|
||||||
0xFFBDBDBD,
|
|
||||||
).withOpacity(0.25),
|
|
||||||
blurRadius: 7,
|
blurRadius: 7,
|
||||||
offset: const Offset(0, 1),
|
offset: const Offset(0, 1),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: TextField(
|
child: KeyboardListener(
|
||||||
controller: _controllers[index],
|
focusNode: FocusNode(),
|
||||||
focusNode: _focusNodes[index],
|
onKeyEvent: (event) {
|
||||||
textAlign: TextAlign.center,
|
if (event is KeyDownEvent &&
|
||||||
keyboardType: TextInputType.number,
|
event.logicalKey ==
|
||||||
maxLength: 1,
|
LogicalKeyboardKey.backspace) {
|
||||||
enabled: !isLoading,
|
if (_controllers[index].text.isEmpty &&
|
||||||
style: TextStyle(
|
index > 0) {
|
||||||
fontFamily: "Gilroy",
|
_focusNodes[index - 1].requestFocus();
|
||||||
fontWeight: FontWeight.w400,
|
}
|
||||||
fontSize: otpFontSize,
|
}
|
||||||
letterSpacing: 0.03 * otpFontSize,
|
},
|
||||||
color: isFilled ? Colors.white : Colors.black,
|
child: TextField(
|
||||||
),
|
controller: _controllers[index],
|
||||||
decoration: const InputDecoration(
|
focusNode: _focusNodes[index],
|
||||||
counterText: '',
|
textAlign: TextAlign.center,
|
||||||
border: InputBorder.none,
|
keyboardType: TextInputType.number,
|
||||||
),
|
maxLength: 1,
|
||||||
onChanged: (value) =>
|
enabled: !isLoading,
|
||||||
_onOtpChange(index, value),
|
style: TextStyle(
|
||||||
),
|
fontFamily: "Gilroy",
|
||||||
),
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: otpFontSize,
|
||||||
|
color: isFilled ? Colors.white : Colors.black,
|
||||||
|
),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
counterText: '',
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
onChanged: (value) =>
|
||||||
|
_onOtpChange(index, value),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingXS),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Resend
|
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: _canResend && !isLoading ? _resendOtp : null,
|
onTap: _canResend && !isLoading ? _resendOtp : null,
|
||||||
child: Text(
|
child: Text(
|
||||||
"Resend",
|
"Resend",
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: AppTextStyles.medium.copyWith(
|
style: AppTextStyles.medium.copyWith(
|
||||||
fontSize: resendFontSize,
|
fontSize: resendFontSize,
|
||||||
height: 1.4,
|
|
||||||
letterSpacing: 0.02 * resendFontSize,
|
|
||||||
color: _canResend && !isLoading
|
color: _canResend && !isLoading
|
||||||
? AppColors.authchange
|
? AppColors.authchange
|
||||||
: Colors.grey,
|
: Colors.grey,
|
||||||
@ -381,20 +321,14 @@ class _OtpScreenState extends ConsumerState<OtpScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingSM),
|
SizedBox(height: spacingSM),
|
||||||
|
|
||||||
// Timer
|
|
||||||
Text(
|
Text(
|
||||||
_formatTime(_remainingSeconds),
|
_formatTime(_remainingSeconds),
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
fontSize: timerFontSize,
|
fontSize: timerFontSize,
|
||||||
color: _remainingSeconds > 0
|
color: _remainingSeconds > 0 ? AppColors.authheading : Colors.red,
|
||||||
? AppColors.authheading
|
|
||||||
: Colors.red,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: spacingLG),
|
SizedBox(height: spacingLG),
|
||||||
|
|
||||||
// Verify Button
|
|
||||||
isLoading
|
isLoading
|
||||||
? const CircularProgressIndicator()
|
? const CircularProgressIndicator()
|
||||||
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
||||||
|
|||||||
@ -2,7 +2,9 @@ import 'dart:async';
|
|||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:get/get.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_asstes.dart';
|
||||||
import 'package:taxglide/consts/app_colors.dart';
|
import 'package:taxglide/consts/app_colors.dart';
|
||||||
import 'package:taxglide/consts/comman_button.dart';
|
import 'package:taxglide/consts/comman_button.dart';
|
||||||
@ -155,7 +157,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call verify OTP API for signup
|
// 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);
|
final signupState = ref.read(signupProvider);
|
||||||
|
|
||||||
@ -169,7 +171,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
|
|
||||||
// Navigate to main screen after successful verification
|
// Navigate to main screen after successful verification
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
Get.offAll(() => MainController());
|
Get.offAll(() => MpinSetScreen());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_validationPopup.showErrorMessage(
|
_validationPopup.showErrorMessage(
|
||||||
@ -208,7 +210,20 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
final signupState = ref.watch(signupProvider);
|
final signupState = ref.watch(signupProvider);
|
||||||
final isLoading = signupState is AsyncLoading;
|
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(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
// Background gradient
|
// Background gradient
|
||||||
@ -257,10 +272,10 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
"OTP has been sent to your registered mobile number",
|
"OTP has been sent to your registered mail id",
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: AppTextStyles.semiBold.copyWith(
|
style: AppTextStyles.semiBold.copyWith(
|
||||||
fontSize: 14,
|
fontSize: 12,
|
||||||
height: 1.4,
|
height: 1.4,
|
||||||
letterSpacing: 0.03 * 14,
|
letterSpacing: 0.03 * 14,
|
||||||
color: AppColors.authleading,
|
color: AppColors.authleading,
|
||||||
@ -269,7 +284,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
const SizedBox(height: 22),
|
const SizedBox(height: 22),
|
||||||
Text.rich(
|
Text.rich(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: mobile,
|
text: email,
|
||||||
style: AppTextStyles.medium.copyWith(
|
style: AppTextStyles.medium.copyWith(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
height: 1.8,
|
height: 1.8,
|
||||||
@ -278,7 +293,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: " ( Change Number )",
|
text: " ( Change mail id )",
|
||||||
style: AppTextStyles.extraBold.copyWith(
|
style: AppTextStyles.extraBold.copyWith(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
height: 1.8,
|
height: 1.8,
|
||||||
@ -331,26 +346,39 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: TextField(
|
child: KeyboardListener(
|
||||||
controller: _controllers[index],
|
focusNode: FocusNode(),
|
||||||
focusNode: _focusNodes[index],
|
onKeyEvent: (event) {
|
||||||
textAlign: TextAlign.center,
|
if (event is KeyDownEvent &&
|
||||||
keyboardType: TextInputType.number,
|
event.logicalKey ==
|
||||||
maxLength: 1,
|
LogicalKeyboardKey.backspace) {
|
||||||
enabled: !isLoading,
|
if (_controllers[index].text.isEmpty &&
|
||||||
style: TextStyle(
|
index > 0) {
|
||||||
fontFamily: "Gilroy",
|
_focusNodes[index - 1].requestFocus();
|
||||||
fontWeight: FontWeight.w400,
|
}
|
||||||
fontSize: 28,
|
}
|
||||||
letterSpacing: 0.03 * 28,
|
},
|
||||||
color: isFilled ? Colors.white : Colors.black,
|
child: TextField(
|
||||||
|
controller: _controllers[index],
|
||||||
|
focusNode: _focusNodes[index],
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
maxLength: 1,
|
||||||
|
enabled: !isLoading,
|
||||||
|
style: TextStyle(
|
||||||
|
fontFamily: "Gilroy",
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 28,
|
||||||
|
letterSpacing: 0.03 * 28,
|
||||||
|
color: isFilled ? Colors.white : Colors.black,
|
||||||
|
),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
counterText: '',
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
onChanged: (value) =>
|
||||||
|
_onOtpChange(index, value),
|
||||||
),
|
),
|
||||||
decoration: const InputDecoration(
|
|
||||||
counterText: '',
|
|
||||||
border: InputBorder.none,
|
|
||||||
),
|
|
||||||
onChanged: (value) =>
|
|
||||||
_onOtpChange(index, value),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -403,6 +431,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,8 +80,12 @@ class ValidationPopup {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this method to your ValidationPopup class
|
// Validate Email
|
||||||
bool validateEmail(BuildContext context, String email) {
|
bool validateEmail(BuildContext context, String email) {
|
||||||
|
if (email.isEmpty) {
|
||||||
|
showErrorMessage(context, "Please enter your email address");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Email regex pattern
|
// Email regex pattern
|
||||||
final emailRegex = RegExp(
|
final emailRegex = RegExp(
|
||||||
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
|
r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$',
|
||||||
@ -94,6 +98,23 @@ class ValidationPopup {
|
|||||||
return true;
|
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
|
// Show success message
|
||||||
void showSuccessMessage(BuildContext context, String msg) {
|
void showSuccessMessage(BuildContext context, String msg) {
|
||||||
_showSnackBar(context, msg, isError: false);
|
_showSnackBar(context, msg, isError: false);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ class ConstsApi {
|
|||||||
static const String baseUrl = "https://www.taxglide.amrithaa.net";
|
static const String baseUrl = "https://www.taxglide.amrithaa.net";
|
||||||
|
|
||||||
static const String login = "$baseUrl/api/otp/sms/request";
|
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 signup = "$baseUrl/api/register";
|
||||||
static const String terms = "$baseUrl/api/get_terms_conditions";
|
static const String terms = "$baseUrl/api/get_terms_conditions";
|
||||||
static const String policy = "$baseUrl/api/get_privacy_policy";
|
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 dashboard = "$baseUrl/api/get_dashboard_data";
|
||||||
static const String proformaaccept = "$baseUrl/api/proforma/accept";
|
static const String proformaaccept = "$baseUrl/api/proforma/accept";
|
||||||
static const String payNow = "$baseUrl/api/pay_now";
|
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";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,17 @@ class LoginNotifier extends StateNotifier<AsyncValue<Map<String, dynamic>>> {
|
|||||||
|
|
||||||
LoginNotifier(this._apiRepository) : super(const AsyncValue.data({}));
|
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 {
|
Future<void> login(String mobile) async {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
@ -86,11 +97,11 @@ class SignupNotifier extends StateNotifier<AsyncValue<Map<String, dynamic>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify OTP for signup
|
// Verify OTP for signup
|
||||||
Future<void> verifySignupOtp(String mobile, String otp) async {
|
Future<void> verifySignupOtp(String email, String otp) async {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
try {
|
try {
|
||||||
final result = await _apiRepository.verifySignupOtp(mobile, otp);
|
final result = await _apiRepository.verifySignupOtp(email, otp);
|
||||||
if (mounted) state = AsyncValue.data(result);
|
if (mounted) state = AsyncValue.data(result);
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
if (mounted) state = AsyncValue.error(e, st);
|
if (mounted) state = AsyncValue.error(e, st);
|
||||||
@ -115,6 +126,17 @@ class EmployeeLoginNotifier
|
|||||||
|
|
||||||
EmployeeLoginNotifier(this._apiRepository) : super(const AsyncValue.data({}));
|
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 {
|
Future<void> login(String mobile) async {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
@ -137,6 +159,77 @@ class EmployeeLoginNotifier
|
|||||||
if (mounted) state = AsyncValue.error(e, st);
|
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 {
|
final termsProvider = FutureProvider<TermsModel>((ref) async {
|
||||||
|
|||||||
@ -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
|
// 🔹 VERIFY OTP (LOGIN) - ✅ Regenerates FCM token
|
||||||
Future<Map<String, dynamic>> verifyOtp(LoginModel model) async {
|
Future<Map<String, dynamic>> verifyOtp(LoginModel model) async {
|
||||||
try {
|
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
|
// 🔹 SIGNUP API
|
||||||
Future<Map<String, dynamic>> signupUser(SignupModel model) async {
|
Future<Map<String, dynamic>> signupUser(SignupModel model) async {
|
||||||
try {
|
try {
|
||||||
@ -258,7 +443,7 @@ class ApiRepository {
|
|||||||
|
|
||||||
// 🔹 VERIFY OTP (SIGNUP) - ✅ Regenerates FCM token
|
// 🔹 VERIFY OTP (SIGNUP) - ✅ Regenerates FCM token
|
||||||
Future<Map<String, dynamic>> verifySignupOtp(
|
Future<Map<String, dynamic>> verifySignupOtp(
|
||||||
String mobile,
|
String email,
|
||||||
String otp,
|
String otp,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
@ -267,7 +452,7 @@ class ApiRepository {
|
|||||||
final fcmToken = tokens['fcm_token'];
|
final fcmToken = tokens['fcm_token'];
|
||||||
final apnsToken = tokens['apns_token'];
|
final apnsToken = tokens['apns_token'];
|
||||||
|
|
||||||
final params = {'mobile': mobile, 'otp': otp};
|
final params = {'email': email, 'otp': otp};
|
||||||
|
|
||||||
if (fcmToken != null && fcmToken.isNotEmpty) {
|
if (fcmToken != null && fcmToken.isNotEmpty) {
|
||||||
params['fcm_token'] = fcmToken;
|
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
|
// 🔹 LOGOUT - ✅ Deletes FCM token
|
||||||
Future<void> logout() async {
|
Future<void> logout() async {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -1,23 +1,38 @@
|
|||||||
// login_model.dart
|
// login_model.dart
|
||||||
|
|
||||||
class LoginModel {
|
class LoginModel {
|
||||||
|
String? email;
|
||||||
|
String? pin;
|
||||||
String? mobile;
|
String? mobile;
|
||||||
String? otp;
|
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() {
|
Map<String, dynamic> toJsonMobile() {
|
||||||
return {'mobile': mobile};
|
return {'mobile': mobile};
|
||||||
}
|
}
|
||||||
|
|
||||||
// For sending mobile + OTP for verification
|
// For sending mobile + OTP for verification (Legacy)
|
||||||
Map<String, dynamic> toJsonOtp() {
|
Map<String, dynamic> toJsonOtp() {
|
||||||
return {'mobile': mobile, 'otp': otp};
|
return {'mobile': mobile, 'otp': otp};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For Email + PIN Login
|
||||||
|
Map<String, dynamic> toJsonEmailPin() {
|
||||||
|
return {
|
||||||
|
'email': email,
|
||||||
|
'pin': pin,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Response from API
|
// Response from API
|
||||||
factory LoginModel.fromJson(Map<String, dynamic> json) {
|
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'],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,4 +13,6 @@ class ConstRouters {
|
|||||||
static const String servicerequest = '/servicerequest';
|
static const String servicerequest = '/servicerequest';
|
||||||
static const String staff = '/staff';
|
static const String staff = '/staff';
|
||||||
static const String employeekycdetailslist = '/employeekycdetailslist';
|
static const String employeekycdetailslist = '/employeekycdetailslist';
|
||||||
|
static const String mpinSet = '/mpinSet';
|
||||||
|
static const String forgotPassword = '/forgotPassword';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:taxglide/auth/employee_login_screen.dart';
|
import 'package:taxglide/auth/employee_login_screen.dart';
|
||||||
import 'package:taxglide/auth/employee_otp_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/login_screen.dart';
|
||||||
|
import 'package:taxglide/auth/mpin_set_screen.dart';
|
||||||
import 'package:taxglide/auth/otp_screen.dart';
|
import 'package:taxglide/auth/otp_screen.dart';
|
||||||
import 'package:taxglide/auth/register_otp_screen.dart';
|
import 'package:taxglide/auth/register_otp_screen.dart';
|
||||||
import 'package:taxglide/auth/signup_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.policy, page: () => const PolicyScreen()),
|
||||||
GetPage(name: ConstRouters.staff, page: () => const StaffListScreen()),
|
GetPage(name: ConstRouters.staff, page: () => const StaffListScreen()),
|
||||||
|
GetPage(name: ConstRouters.mpinSet, page: () => const MpinSetScreen()),
|
||||||
|
GetPage(
|
||||||
|
name: ConstRouters.forgotPassword,
|
||||||
|
page: () => const ForgotScreen(),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
36
pubspec.lock
36
pubspec.lock
@ -5,10 +5,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: _fe_analyzer_shared
|
name: _fe_analyzer_shared
|
||||||
sha256: "8d7ff3948166b8ec5da0fbb5962000926b8e02f2ed9b3e51d1738905fbd4c98d"
|
sha256: da0d9209ca76bde579f2da330aeb9df62b6319c834fa7baae052021b0462401f
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "93.0.0"
|
version: "85.0.0"
|
||||||
_flutterfire_internals:
|
_flutterfire_internals:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -21,10 +21,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: analyzer
|
name: analyzer
|
||||||
sha256: de7148ed2fcec579b19f122c1800933dfa028f6d9fd38a152b04b1516cec120b
|
sha256: "974859dc0ff5f37bc4313244b3218c791810d03ab3470a579580279ba971a48d"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "10.0.1"
|
version: "7.7.1"
|
||||||
animated_notch_bottom_bar:
|
animated_notch_bottom_bar:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -101,10 +101,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: characters
|
name: characters
|
||||||
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
|
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.1"
|
version: "1.4.0"
|
||||||
checked_yaml:
|
checked_yaml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -724,26 +724,26 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matcher
|
name: matcher
|
||||||
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
|
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.18"
|
version: "0.12.17"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: material_color_utilities
|
name: material_color_utilities
|
||||||
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
|
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.13.0"
|
version: "0.11.1"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.17.0"
|
version: "1.16.0"
|
||||||
mime:
|
mime:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1137,26 +1137,26 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test
|
name: test
|
||||||
sha256: "54c516bbb7cee2754d327ad4fca637f78abfc3cbcc5ace83b3eda117e42cd71a"
|
sha256: "65e29d831719be0591f7b3b1a32a3cda258ec98c58c7b25f7b84241bc31215bb"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.29.0"
|
version: "1.26.2"
|
||||||
test_api:
|
test_api:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"
|
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.9"
|
version: "0.7.6"
|
||||||
test_core:
|
test_core:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_core
|
name: test_core
|
||||||
sha256: "394f07d21f0f2255ec9e3989f21e54d3c7dc0e6e9dbce160e5a9c1a6be0e2943"
|
sha256: "80bf5a02b60af04b09e14f6fe68b921aad119493e26e490deaca5993fef1b05a"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.15"
|
version: "0.6.11"
|
||||||
timezone:
|
timezone:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user