mpin add and 2026-04-19 updates
This commit is contained in:
1 parent
41d7cfa8c6
commit
7d25e77138
15 files changed
+2555
-1643
No files matched your search
+424
-283
@@ -1,283 +1,424 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
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 EmployeeLoginScreen extends ConsumerStatefulWidget {
|
||||
const EmployeeLoginScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<EmployeeLoginScreen> createState() =>
|
||||
_EmployeeLoginScreenState();
|
||||
}
|
||||
|
||||
class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final TextEditingController _mobileController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments;
|
||||
if (args != null && args is Map<String, dynamic>) {
|
||||
final mobile = args['mobile'] ?? '';
|
||||
if (mobile.isNotEmpty) {
|
||||
_mobileController.text = mobile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mobileController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _handleLogin() async {
|
||||
final mobile = _mobileController.text.trim();
|
||||
|
||||
if (!_validationPopup.validateMobileNumber(context, mobile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await ref.read(employeeloginProvider.notifier).login(mobile);
|
||||
final state = ref.read(employeeloginProvider);
|
||||
|
||||
state.when(
|
||||
data: (data) {
|
||||
if (data['success'] == true) {
|
||||
Get.toNamed(ConstRouters.employeeotp, arguments: {'mobile': mobile});
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"OTP sent successfully!",
|
||||
);
|
||||
} 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 loginState = ref.watch(employeeloginProvider);
|
||||
|
||||
// Initialize responsive utils
|
||||
final r = ResponsiveUtils(context);
|
||||
|
||||
// Responsive values
|
||||
final logoWidth = r.getValue<double>(
|
||||
mobile: 120,
|
||||
tablet: 141,
|
||||
desktop: 160,
|
||||
);
|
||||
final logoHeight = r.getValue<double>(
|
||||
mobile: 85,
|
||||
tablet: 100,
|
||||
desktop: 115,
|
||||
);
|
||||
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
||||
final linkFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
||||
|
||||
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
|
||||
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingLG = r.spacing(mobile: 20, tablet: 22, desktop: 28);
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) return;
|
||||
Get.offAllNamed(ConstRouters.login);
|
||||
},
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
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: SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: r.screenHeight),
|
||||
child: IntrinsicHeight(
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Logo
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
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),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
"Enter your registered Mobile Number",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
height: 1.4,
|
||||
letterSpacing: 0.03 * subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Mobile Number Input
|
||||
CommanTextFormField(
|
||||
controller: _mobileController,
|
||||
hintText: 'Enter your Mobile Number',
|
||||
keyboardType: TextInputType.phone,
|
||||
prefixIcon: Icons.phone_android,
|
||||
),
|
||||
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,
|
||||
),
|
||||
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),
|
||||
|
||||
// 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,
|
||||
height: 1.8,
|
||||
letterSpacing: 0.13,
|
||||
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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:taxglide/consts/app_asstes.dart';
|
||||
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';
|
||||
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
||||
|
||||
class EmployeeLoginScreen extends ConsumerStatefulWidget {
|
||||
const EmployeeLoginScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<EmployeeLoginScreen> createState() =>
|
||||
_EmployeeLoginScreenState();
|
||||
}
|
||||
|
||||
class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
|
||||
// Multi-box PIN logic
|
||||
final int pinLength = 4;
|
||||
final List<TextEditingController> _pinControllers = [];
|
||||
final List<FocusNode> _pinFocusNodes = [];
|
||||
String pinValue = '';
|
||||
|
||||
// Error states
|
||||
bool _emailHasError = false;
|
||||
bool _pinHasError = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize PIN controllers and focus nodes
|
||||
for (int i = 0; i < pinLength; i++) {
|
||||
_pinControllers.add(TextEditingController());
|
||||
_pinFocusNodes.add(FocusNode());
|
||||
}
|
||||
|
||||
final args = Get.arguments;
|
||||
if (args != null && args is Map<String, dynamic>) {
|
||||
final email = args['email'] ?? '';
|
||||
if (email.isNotEmpty) {
|
||||
_emailController.text = email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
for (var controller in _pinControllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
for (var node in _pinFocusNodes) {
|
||||
node.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPinChange(int index, String value) {
|
||||
if (_pinHasError) {
|
||||
setState(() => _pinHasError = false);
|
||||
}
|
||||
if (value.isNotEmpty && index < pinLength - 1) {
|
||||
_pinFocusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_pinFocusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
pinValue = _pinControllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _handleLogin() async {
|
||||
final email = _emailController.text.trim();
|
||||
final pin = pinValue.trim();
|
||||
|
||||
setState(() {
|
||||
_emailHasError = false;
|
||||
_pinHasError = false;
|
||||
});
|
||||
|
||||
if (!_validationPopup.validateEmail(context, email)) {
|
||||
setState(() => _emailHasError = true);
|
||||
return;
|
||||
}
|
||||
if (!_validationPopup.validatePin(context, pin)) {
|
||||
setState(() => _pinHasError = true);
|
||||
return;
|
||||
}
|
||||
|
||||
await ref.read(employeeloginProvider.notifier).loginWithPin(email, pin);
|
||||
final state = ref.read(employeeloginProvider);
|
||||
|
||||
state.when(
|
||||
data: (data) {
|
||||
if (data['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"Login Successful!",
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Get.offAll(() => const MainController());
|
||||
});
|
||||
} else if (data['error'] != null) {
|
||||
_validationPopup.showErrorMessage(context, data['error'].toString());
|
||||
setState(() {
|
||||
_emailHasError = true;
|
||||
_pinHasError = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) {
|
||||
_validationPopup.showErrorMessage(context, "Error: $err");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loginState = ref.watch(employeeloginProvider);
|
||||
|
||||
// Initialize responsive utils
|
||||
final r = ResponsiveUtils(context);
|
||||
|
||||
// Responsive values
|
||||
final logoWidth = r.getValue<double>(mobile: 120, tablet: 141, desktop: 160);
|
||||
final logoHeight = r.getValue<double>(mobile: 85, tablet: 100, desktop: 115);
|
||||
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
||||
final linkFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
||||
|
||||
final pinBoxWidth = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
|
||||
final pinBoxHeight = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
|
||||
final pinFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final pinBoxMargin = r.getValue<double>(mobile: 8, tablet: 6, desktop: 8);
|
||||
final pinBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
|
||||
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingLG = r.spacing(mobile: 20, tablet: 22, desktop: 28);
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) return;
|
||||
Get.offAllNamed(ConstRouters.login);
|
||||
},
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
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: SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: r.screenHeight),
|
||||
child: IntrinsicHeight(
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Logo
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
SizedBox(height: spacingMD),
|
||||
|
||||
// Login Title
|
||||
Text(
|
||||
"Employee Login",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingMD),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
"Enter your Email and PIN",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Email Input
|
||||
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),
|
||||
|
||||
// PIN Boxes
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(pinLength, (index) {
|
||||
bool isFilled = _pinControllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: pinBoxMargin),
|
||||
width: pinBoxWidth,
|
||||
height: pinBoxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||
borderRadius: BorderRadius.circular(pinBoxRadius),
|
||||
border: Border.all(
|
||||
color: _pinHasError
|
||||
? Colors.red
|
||||
: const Color(0xFFDFDFDF),
|
||||
width: _pinHasError ? 1.5 : 1.0,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _pinHasError
|
||||
? Colors.red.withOpacity(0.1)
|
||||
: const Color(0xFFBDBDBD).withOpacity(0.25),
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: KeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey ==
|
||||
LogicalKeyboardKey.backspace) {
|
||||
if (_pinControllers[index]
|
||||
.text
|
||||
.isEmpty &&
|
||||
index > 0) {
|
||||
_pinFocusNodes[index - 1]
|
||||
.requestFocus();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: TextField(
|
||||
controller: _pinControllers[index],
|
||||
focusNode: _pinFocusNodes[index],
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 1,
|
||||
obscureText: true,
|
||||
enabled: !loginState.isLoading,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: pinFontSize,
|
||||
color: isFilled
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
counterText: '',
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) =>
|
||||
_onPinChange(index, value),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
|
||||
SizedBox(height: spacingXS),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ConstRouters.forgotPassword,
|
||||
arguments: {'isEmployee': true},
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
"Forgot Password?",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: linkFontSize,
|
||||
color: AppColors.authchange,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Terms and Conditions
|
||||
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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+342
-420
@@ -1,420 +1,342 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/gestures.dart';
|
||||
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/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 '../router/consts_routers.dart';
|
||||
|
||||
class EmployeeOtpScreen extends ConsumerStatefulWidget {
|
||||
const EmployeeOtpScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<EmployeeOtpScreen> createState() => _EmployeeOtpScreenState();
|
||||
}
|
||||
|
||||
class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final int otpLength = 4;
|
||||
final List<TextEditingController> _controllers = [];
|
||||
final List<FocusNode> _focusNodes = [];
|
||||
String otpValue = '';
|
||||
|
||||
Timer? _timer;
|
||||
int _remainingSeconds = 600;
|
||||
bool _canResend = false;
|
||||
|
||||
late String mobile;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments as Map<String, dynamic>?;
|
||||
mobile = args?['mobile'] ?? '';
|
||||
|
||||
for (int i = 0; i < otpLength; i++) {
|
||||
_controllers.add(TextEditingController());
|
||||
_focusNodes.add(FocusNode());
|
||||
}
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
for (var c in _controllers) c.dispose();
|
||||
for (var f in _focusNodes) f.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_canResend = false;
|
||||
_remainingSeconds = 30;
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (_remainingSeconds > 0) {
|
||||
setState(() => _remainingSeconds--);
|
||||
} else {
|
||||
setState(() => _canResend = true);
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _formatTime(int seconds) {
|
||||
int minutes = seconds ~/ 60;
|
||||
int remainingSeconds = seconds % 60;
|
||||
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
Future<void> _resendOtp() async {
|
||||
if (!_canResend) return;
|
||||
|
||||
for (var controller in _controllers) controller.clear();
|
||||
setState(() => otpValue = '');
|
||||
_focusNodes[0].requestFocus();
|
||||
|
||||
try {
|
||||
await ref.read(employeeloginProvider.notifier).login(mobile);
|
||||
final loginState = ref.read(employeeloginProvider);
|
||||
loginState.when(
|
||||
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. Please try again.",
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
"An error occurred. Please try again.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _verifyOtp() async {
|
||||
if (otpValue.length != otpLength) {
|
||||
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
|
||||
return;
|
||||
}
|
||||
|
||||
await ref.read(employeeloginProvider.notifier).verifyOtp(mobile, otpValue);
|
||||
final loginState = ref.read(employeeloginProvider);
|
||||
|
||||
loginState.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"OTP Verified Successfully!",
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Get.offAll(() => const MainController());
|
||||
});
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
result['error'] ?? "Invalid OTP. Please try again.",
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, _) {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
"Failed to verify OTP. Please try again.",
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _onOtpChange(int index, String value) {
|
||||
if (value.isNotEmpty && index < otpLength - 1) {
|
||||
_focusNodes[index + 1].requestFocus();
|
||||
} else if (value.isEmpty && index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
otpValue = _controllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loginState = ref.watch(employeeloginProvider);
|
||||
final isLoading = loginState.isLoading;
|
||||
|
||||
// Initialize responsive utils
|
||||
final r = ResponsiveUtils(context);
|
||||
|
||||
// Responsive values
|
||||
final logoWidth = r.getValue<double>(
|
||||
mobile: 120,
|
||||
tablet: 141,
|
||||
desktop: 160,
|
||||
);
|
||||
final logoHeight = r.getValue<double>(
|
||||
mobile: 85,
|
||||
tablet: 100,
|
||||
desktop: 115,
|
||||
);
|
||||
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final mobileFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
||||
final resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
||||
|
||||
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
||||
final otpBoxHeight = r.getValue<double>(
|
||||
mobile: 48,
|
||||
tablet: 56,
|
||||
desktop: 64,
|
||||
);
|
||||
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
final otpBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
|
||||
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
||||
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
||||
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
// Gradient background
|
||||
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],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Scrollable content
|
||||
SingleChildScrollView(
|
||||
child: SizedBox(
|
||||
height: r.screenHeight,
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Logo
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Title
|
||||
Text(
|
||||
"Enter OTP",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontSize: titleFontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.3,
|
||||
letterSpacing: 0.01 * titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
"OTP has been sent to your registered mobile number",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontSize: subtitleFontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.4,
|
||||
letterSpacing: 0.03 * subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingMD),
|
||||
|
||||
// Mobile + Change Number
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: mobile,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: mobileFontSize,
|
||||
height: 1.8,
|
||||
letterSpacing: 0.01,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: " ( Change Number )",
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: mobileFontSize,
|
||||
height: 1.8,
|
||||
letterSpacing: 0.04,
|
||||
color: AppColors.authchange,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Get.offNamed(
|
||||
ConstRouters.employeelogin,
|
||||
arguments: {'mobile': mobile},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// OTP Input Fields
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(otpLength, (index) {
|
||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: otpBoxMargin,
|
||||
),
|
||||
width: otpBoxWidth,
|
||||
height: otpBoxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled
|
||||
? AppColors.commanbutton
|
||||
: Colors.white,
|
||||
borderRadius: BorderRadius.circular(otpBoxRadius),
|
||||
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: 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: otpFontSize,
|
||||
letterSpacing: 0.03 * otpFontSize,
|
||||
color: isFilled ? Colors.white : Colors.black,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
counterText: '',
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) =>
|
||||
_onOtpChange(index, value),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
SizedBox(height: spacingXS),
|
||||
|
||||
// Resend OTP
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GestureDetector(
|
||||
onTap: _canResend && !isLoading ? _resendOtp : null,
|
||||
child: Text(
|
||||
"Resend",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: resendFontSize,
|
||||
height: 1.4,
|
||||
letterSpacing: 0.02 * resendFontSize,
|
||||
color: _canResend && !isLoading
|
||||
? AppColors.authchange
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Timer
|
||||
Text(
|
||||
_formatTime(_remainingSeconds),
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: timerFontSize,
|
||||
color: _remainingSeconds > 0
|
||||
? AppColors.authheading
|
||||
: Colors.red,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Verify Button
|
||||
isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'dart:async';
|
||||
import 'package:flutter/gestures.dart';
|
||||
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/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/router/consts_routers.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:taxglide/consts/app_style.dart';
|
||||
|
||||
class EmployeeOtpScreen extends ConsumerStatefulWidget {
|
||||
const EmployeeOtpScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<EmployeeOtpScreen> createState() => _EmployeeOtpScreenState();
|
||||
}
|
||||
|
||||
class _EmployeeOtpScreenState extends ConsumerState<EmployeeOtpScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final int otpLength = 4;
|
||||
final List<TextEditingController> _controllers = [];
|
||||
final List<FocusNode> _focusNodes = [];
|
||||
String otpValue = '';
|
||||
|
||||
Timer? _timer;
|
||||
int _remainingSeconds = 600;
|
||||
bool _canResend = false;
|
||||
|
||||
late String _identifier;
|
||||
bool _fromForgot = false;
|
||||
bool _isEmployee = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments as Map<String, dynamic>? ?? {};
|
||||
_fromForgot = args['fromForgot'] ?? false;
|
||||
_identifier = args['email'] ?? args['mobile'] ?? '';
|
||||
|
||||
for (int i = 0; i < otpLength; i++) {
|
||||
_controllers.add(TextEditingController());
|
||||
_focusNodes.add(FocusNode());
|
||||
}
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
for (var c in _controllers) c.dispose();
|
||||
for (var f in _focusNodes) f.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_canResend = false;
|
||||
_remainingSeconds = 30;
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (_remainingSeconds > 0) {
|
||||
setState(() => _remainingSeconds--);
|
||||
} else {
|
||||
setState(() => _canResend = true);
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _formatTime(int seconds) {
|
||||
int minutes = seconds ~/ 60;
|
||||
int remainingSeconds = seconds % 60;
|
||||
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _resendOtp() async {
|
||||
if (!_canResend) return;
|
||||
for (var controller in _controllers) controller.clear();
|
||||
setState(() => otpValue = '');
|
||||
_focusNodes[0].requestFocus();
|
||||
|
||||
if (_fromForgot) {
|
||||
await ref.read(forgotPasswordProvider.notifier).requestOtp(_identifier, _isEmployee);
|
||||
final state = ref.read(forgotPasswordProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
|
||||
_startTimer();
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
|
||||
);
|
||||
} else {
|
||||
await ref.read(employeeloginProvider.notifier).login(_identifier);
|
||||
final state = ref.read(employeeloginProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
|
||||
_startTimer();
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _verifyOtp() async {
|
||||
if (otpValue.length != otpLength) {
|
||||
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_fromForgot) {
|
||||
await ref.read(forgotPasswordProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||
final state = ref.read(forgotPasswordProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||
Get.toNamed(ConstRouters.mpinSet);
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||
);
|
||||
} else {
|
||||
await ref.read(employeeloginProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||
final state = ref.read(employeeloginProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||
Get.offAllNamed(ConstRouters.mpinSet);
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _onOtpChange(int index, String value) {
|
||||
if (value.isNotEmpty && index < otpLength - 1) {
|
||||
_focusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
otpValue = _controllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isLoading = _fromForgot
|
||||
? ref.watch(forgotPasswordProvider).isLoading
|
||||
: ref.watch(employeeloginProvider).isLoading;
|
||||
|
||||
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 resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
||||
|
||||
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
||||
final otpBoxHeight = r.getValue<double>(mobile: 48, tablet: 56, desktop: 64);
|
||||
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
final otpBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
||||
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
||||
|
||||
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,
|
||||
children: [
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"Enter Staff OTP",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"OTP has been sent to ${_identifier}",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingMD),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(otpLength, (index) {
|
||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: otpBoxMargin),
|
||||
width: otpBoxWidth,
|
||||
height: otpBoxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||
borderRadius: BorderRadius.circular(otpBoxRadius),
|
||||
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,
|
||||
enabled: !isLoading,
|
||||
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: spacingSM),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GestureDetector(
|
||||
onTap: _canResend && !isLoading ? _resendOtp : null,
|
||||
child: Text(
|
||||
"Resend",
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: resendFontSize,
|
||||
color: _canResend && !isLoading
|
||||
? AppColors.authchange
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
_formatTime(_remainingSeconds),
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: timerFontSize,
|
||||
color: _remainingSeconds > 0 ? AppColors.authheading : Colors.red,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+453
-351
@@ -1,351 +1,453 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
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/comman_button.dart';
|
||||
import 'package:taxglide/consts/comman_container_auth.dart';
|
||||
import 'package:taxglide/consts/comman_textformfileds.dart';
|
||||
import 'package:taxglide/consts/comman_popup.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';
|
||||
import 'package:taxglide/consts/app_style.dart';
|
||||
|
||||
class LoginScreen extends ConsumerStatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
final TextEditingController _mobileController = TextEditingController();
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments;
|
||||
if (args != null && args is Map<String, dynamic>) {
|
||||
final mobile = args['mobile'] ?? '';
|
||||
if (mobile.isNotEmpty) {
|
||||
_mobileController.text = mobile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mobileController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _handleLogin() async {
|
||||
final mobile = _mobileController.text.trim();
|
||||
|
||||
if (!_validationPopup.validateMobileNumber(context, mobile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await ref.read(loginProvider.notifier).login(mobile);
|
||||
final state = ref.read(loginProvider);
|
||||
|
||||
state.when(
|
||||
data: (data) {
|
||||
if (data['success'] == true) {
|
||||
Get.toNamed(ConstRouters.otp, arguments: {'mobile': mobile});
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"OTP sent successfully!",
|
||||
);
|
||||
} 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 loginState = ref.watch(loginProvider);
|
||||
final policyAsync = ref.watch(policyProvider);
|
||||
final termsAsync = ref.watch(termsProvider);
|
||||
|
||||
// Initialize responsive utils
|
||||
final r = ResponsiveUtils(context);
|
||||
|
||||
// Responsive values
|
||||
final logoWidth = r.getValue<double>(
|
||||
mobile: 120,
|
||||
tablet: 141,
|
||||
desktop: 160,
|
||||
);
|
||||
final logoHeight = r.getValue<double>(
|
||||
mobile: 85,
|
||||
tablet: 100,
|
||||
desktop: 115,
|
||||
);
|
||||
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
||||
final signupFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
||||
|
||||
final spacingXS = r.spacing(mobile: 10, tablet: 15, desktop: 18);
|
||||
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 20, tablet: 22, desktop: 26);
|
||||
final spacingLG = r.spacing(mobile: 20, tablet: 22, desktop: 28);
|
||||
|
||||
return PopScope(
|
||||
canPop: true,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
// Handle custom behavior here if needed in the future
|
||||
},
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
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: SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: r.screenHeight),
|
||||
child: IntrinsicHeight(
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Logo
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Title
|
||||
Text(
|
||||
"Login",
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
"Enter your Mobile Number",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Mobile TextField
|
||||
CommanTextFormField(
|
||||
controller: _mobileController,
|
||||
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,
|
||||
),
|
||||
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: spacingSM),
|
||||
Text("Or",style: AppTextStyles.medium.copyWith(
|
||||
fontSize: spacingSM,
|
||||
color: AppColors.authleading,
|
||||
),),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Sign up
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: "Didn't Have account? ",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: signupFontSize,
|
||||
color: AppColors.black,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "Sign Up",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: signupFontSize,
|
||||
color: AppColors.authsignup,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Get.offNamed(ConstRouters.signup);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Login Button
|
||||
loginState.isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: CommanButton(
|
||||
text: "Login",
|
||||
onPressed: _handleLogin,
|
||||
),
|
||||
|
||||
SizedBox(height: spacingMD),
|
||||
|
||||
Text(
|
||||
"Other Login",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: otherLoginFontSize,
|
||||
height: 1.8,
|
||||
letterSpacing: 0.13,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: spacingXS),
|
||||
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: "Staff Login? ",
|
||||
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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:taxglide/consts/app_asstes.dart';
|
||||
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/comman_textformfileds.dart';
|
||||
import 'package:taxglide/consts/comman_popup.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';
|
||||
import 'package:taxglide/consts/app_style.dart';
|
||||
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
||||
|
||||
class LoginScreen extends ConsumerStatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
|
||||
// Multi-box PIN logic
|
||||
final int pinLength = 4;
|
||||
final List<TextEditingController> _pinControllers = [];
|
||||
final List<FocusNode> _pinFocusNodes = [];
|
||||
String pinValue = '';
|
||||
|
||||
// Error states
|
||||
bool _emailHasError = false;
|
||||
bool _pinHasError = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Initialize PIN controllers and focus nodes
|
||||
for (int i = 0; i < pinLength; i++) {
|
||||
_pinControllers.add(TextEditingController());
|
||||
_pinFocusNodes.add(FocusNode());
|
||||
}
|
||||
|
||||
final args = Get.arguments;
|
||||
if (args != null && args is Map<String, dynamic>) {
|
||||
final email = args['email'] ?? '';
|
||||
if (email.isNotEmpty) {
|
||||
_emailController.text = email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
for (var controller in _pinControllers) {
|
||||
controller.dispose();
|
||||
}
|
||||
for (var node in _pinFocusNodes) {
|
||||
node.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPinChange(int index, String value) {
|
||||
if (_pinHasError) {
|
||||
setState(() => _pinHasError = false);
|
||||
}
|
||||
if (value.isNotEmpty && index < pinLength - 1) {
|
||||
_pinFocusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_pinFocusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
pinValue = _pinControllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _handleLogin() async {
|
||||
final email = _emailController.text.trim();
|
||||
final pin = pinValue.trim();
|
||||
|
||||
setState(() {
|
||||
_emailHasError = false;
|
||||
_pinHasError = false;
|
||||
});
|
||||
|
||||
if (!_validationPopup.validateEmail(context, email)) {
|
||||
setState(() => _emailHasError = true);
|
||||
return;
|
||||
}
|
||||
if (!_validationPopup.validatePin(context, pin)) {
|
||||
setState(() => _pinHasError = true);
|
||||
return;
|
||||
}
|
||||
|
||||
await ref.read(loginProvider.notifier).loginWithPin(email, pin);
|
||||
final state = ref.read(loginProvider);
|
||||
|
||||
state.when(
|
||||
data: (data) {
|
||||
if (data['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"Login Successful!",
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Get.offAll(() => const MainController());
|
||||
});
|
||||
} else if (data['error'] != null) {
|
||||
_validationPopup.showErrorMessage(context, data['error'].toString());
|
||||
setState(() {
|
||||
_emailHasError = true;
|
||||
_pinHasError = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) {
|
||||
_validationPopup.showErrorMessage(context, "Error: $err");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loginState = ref.watch(loginProvider);
|
||||
final policyAsync = ref.watch(policyProvider);
|
||||
final termsAsync = ref.watch(termsProvider);
|
||||
|
||||
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 termsFontSize = r.fontSize(mobile: 10.5, tablet: 11.34, desktop: 12);
|
||||
final signupFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final otherLoginFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
||||
|
||||
final pinBoxWidth = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
|
||||
final pinBoxHeight = r.getValue<double>(mobile: 55, tablet: 60, desktop: 68);
|
||||
final pinFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final pinBoxMargin = r.getValue<double>(mobile: 8, tablet: 6, desktop: 8);
|
||||
final pinBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingXS = r.spacing(mobile: 10, tablet: 15, desktop: 18);
|
||||
final spacingSM = r.spacing(mobile: 15, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 20, tablet: 22, desktop: 26);
|
||||
final spacingLG = r.spacing(mobile: 20, tablet: 22, desktop: 28);
|
||||
|
||||
return PopScope(
|
||||
canPop: true,
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
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: SingleChildScrollView(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: r.screenHeight),
|
||||
child: IntrinsicHeight(
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"Login",
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"Enter your Email and PIN",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
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),
|
||||
|
||||
// PIN Boxes
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(pinLength, (index) {
|
||||
bool isFilled = _pinControllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: pinBoxMargin),
|
||||
width: pinBoxWidth,
|
||||
height: pinBoxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||
borderRadius: BorderRadius.circular(pinBoxRadius),
|
||||
border: Border.all(
|
||||
color: _pinHasError
|
||||
? Colors.red
|
||||
: const Color(0xFFDFDFDF),
|
||||
width: _pinHasError ? 1.5 : 1.0,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _pinHasError
|
||||
? Colors.red.withOpacity(0.1)
|
||||
: const Color(0xFFBDBDBD).withOpacity(0.25),
|
||||
blurRadius: 7,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
child: KeyboardListener(
|
||||
focusNode: FocusNode(),
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey ==
|
||||
LogicalKeyboardKey.backspace) {
|
||||
if (_pinControllers[index]
|
||||
.text
|
||||
.isEmpty &&
|
||||
index > 0) {
|
||||
_pinFocusNodes[index - 1]
|
||||
.requestFocus();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: TextField(
|
||||
controller: _pinControllers[index],
|
||||
focusNode: _pinFocusNodes[index],
|
||||
textAlign: TextAlign.center,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 1,
|
||||
obscureText: true,
|
||||
enabled: !loginState.isLoading,
|
||||
style: TextStyle(
|
||||
fontFamily: "Gilroy",
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: pinFontSize,
|
||||
color: isFilled
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
counterText: '',
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) =>
|
||||
_onPinChange(index, value),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
|
||||
SizedBox(height: spacingXS),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Get.toNamed(
|
||||
ConstRouters.forgotPassword,
|
||||
arguments: {'isEmployee': false},
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
"Forgot Password?",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: signupFontSize,
|
||||
color: AppColors.authchange,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: spacingLG),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: "By signing up, you agree to the ",
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: termsFontSize,
|
||||
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: spacingSM),
|
||||
Text("Or", style: AppTextStyles.medium.copyWith(
|
||||
fontSize: 14,
|
||||
color: AppColors.authleading,
|
||||
)),
|
||||
SizedBox(height: spacingSM),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: "Didn't Have account? ",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: signupFontSize,
|
||||
color: AppColors.black,
|
||||
),
|
||||
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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+345
-411
@@ -1,411 +1,345 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/gestures.dart';
|
||||
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/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/router/consts_routers.dart';
|
||||
|
||||
import 'package:taxglide/view/Main_controller/main_controller.dart';
|
||||
import 'package:taxglide/consts/app_style.dart';
|
||||
|
||||
class OtpScreen extends ConsumerStatefulWidget {
|
||||
const OtpScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<OtpScreen> createState() => _OtpScreenState();
|
||||
}
|
||||
|
||||
class _OtpScreenState extends ConsumerState<OtpScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final int otpLength = 4;
|
||||
final List<TextEditingController> _controllers = [];
|
||||
final List<FocusNode> _focusNodes = [];
|
||||
String otpValue = '';
|
||||
|
||||
Timer? _timer;
|
||||
int _remainingSeconds = 600;
|
||||
bool _canResend = false;
|
||||
|
||||
late String mobile;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments as Map<String, dynamic>;
|
||||
mobile = args['mobile'] ?? '';
|
||||
|
||||
for (int i = 0; i < otpLength; i++) {
|
||||
_controllers.add(TextEditingController());
|
||||
_focusNodes.add(FocusNode());
|
||||
}
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
for (var c in _controllers) c.dispose();
|
||||
for (var f in _focusNodes) f.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_canResend = false;
|
||||
_remainingSeconds = 30;
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (_remainingSeconds > 0) {
|
||||
setState(() => _remainingSeconds--);
|
||||
} else {
|
||||
setState(() => _canResend = true);
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _formatTime(int seconds) {
|
||||
int minutes = seconds ~/ 60;
|
||||
int remainingSeconds = seconds % 60;
|
||||
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _resendOtp() async {
|
||||
if (!_canResend) return;
|
||||
for (var controller in _controllers) controller.clear();
|
||||
setState(() => otpValue = '');
|
||||
_focusNodes[0].requestFocus();
|
||||
|
||||
try {
|
||||
await ref.read(loginProvider.notifier).login(mobile);
|
||||
final loginState = ref.read(loginProvider);
|
||||
loginState.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"OTP has been resent successfully!",
|
||||
);
|
||||
_startTimer();
|
||||
for (var controller in _controllers) controller.clear();
|
||||
setState(() => otpValue = '');
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
result['error'] ?? "Failed to resend OTP",
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, stack) {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
"Failed to resend OTP. Please try again.",
|
||||
);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
"An error occurred. Please try again.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _verifyOtp() async {
|
||||
if (otpValue.length != otpLength) {
|
||||
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
|
||||
return;
|
||||
}
|
||||
|
||||
await ref.read(loginProvider.notifier).verifyOtp(mobile, otpValue);
|
||||
final loginState = ref.read(loginProvider);
|
||||
|
||||
loginState.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(
|
||||
context,
|
||||
"OTP Verified Successfully!",
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Get.offAll(() => MainController());
|
||||
});
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
result['error'] ?? "Invalid OTP. Please try again.",
|
||||
);
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, stack) {
|
||||
_validationPopup.showErrorMessage(
|
||||
context,
|
||||
"Failed to verify OTP. Please try again.",
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _onOtpChange(int index, String value) {
|
||||
if (value.isNotEmpty && index < otpLength - 1) {
|
||||
_focusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
otpValue = _controllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loginState = ref.watch(loginProvider);
|
||||
final isLoading = loginState is AsyncLoading;
|
||||
|
||||
// Initialize responsive utils
|
||||
final r = ResponsiveUtils(context);
|
||||
|
||||
// Responsive values
|
||||
final logoWidth = r.getValue<double>(
|
||||
mobile: 120,
|
||||
tablet: 141,
|
||||
desktop: 160,
|
||||
);
|
||||
final logoHeight = r.getValue<double>(
|
||||
mobile: 85,
|
||||
tablet: 100,
|
||||
desktop: 115,
|
||||
);
|
||||
final titleFontSize = r.fontSize(mobile: 26, tablet: 32, desktop: 36);
|
||||
final subtitleFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final mobileFontSize = r.fontSize(mobile: 12, tablet: 13, desktop: 14);
|
||||
final resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
||||
|
||||
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
||||
final otpBoxHeight = r.getValue<double>(
|
||||
mobile: 48,
|
||||
tablet: 56,
|
||||
desktop: 64,
|
||||
);
|
||||
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
final otpBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingXS = r.spacing(mobile: 10, tablet: 10, desktop: 12);
|
||||
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
||||
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
||||
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
// Background gradient
|
||||
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],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Scrollable content
|
||||
SingleChildScrollView(
|
||||
child: SizedBox(
|
||||
height: r.screenHeight,
|
||||
child: Center(
|
||||
child: CommonContainerAuth(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Logo
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Title
|
||||
Text(
|
||||
"Enter OTP",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
height: 1.3,
|
||||
letterSpacing: 0.01 * titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
"OTP has been sent to your registered mobile number",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
height: 1.4,
|
||||
letterSpacing: 0.03 * subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingMD),
|
||||
|
||||
// Mobile number + Change
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: mobile,
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: mobileFontSize,
|
||||
height: 1.8,
|
||||
letterSpacing: 0.01,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: " ( Change Number )",
|
||||
style: AppTextStyles.extraBold.copyWith(
|
||||
fontSize: mobileFontSize,
|
||||
height: 1.8,
|
||||
letterSpacing: 0.04,
|
||||
color: AppColors.authchange,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Get.offNamed(
|
||||
ConstRouters.login,
|
||||
arguments: {'mobile': mobile},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// OTP Boxes
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(otpLength, (index) {
|
||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: otpBoxMargin,
|
||||
),
|
||||
width: otpBoxWidth,
|
||||
height: otpBoxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled
|
||||
? AppColors.commanbutton
|
||||
: Colors.white,
|
||||
borderRadius: BorderRadius.circular(otpBoxRadius),
|
||||
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: 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: otpFontSize,
|
||||
letterSpacing: 0.03 * otpFontSize,
|
||||
color: isFilled ? Colors.white : Colors.black,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
counterText: '',
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (value) =>
|
||||
_onOtpChange(index, value),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
SizedBox(height: spacingXS),
|
||||
|
||||
// Resend
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GestureDetector(
|
||||
onTap: _canResend && !isLoading ? _resendOtp : null,
|
||||
child: Text(
|
||||
"Resend",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: resendFontSize,
|
||||
height: 1.4,
|
||||
letterSpacing: 0.02 * resendFontSize,
|
||||
color: _canResend && !isLoading
|
||||
? AppColors.authchange
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
|
||||
// Timer
|
||||
Text(
|
||||
_formatTime(_remainingSeconds),
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: timerFontSize,
|
||||
color: _remainingSeconds > 0
|
||||
? AppColors.authheading
|
||||
: Colors.red,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
|
||||
// Verify Button
|
||||
isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'dart:async';
|
||||
import 'package:flutter/gestures.dart';
|
||||
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/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/router/consts_routers.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:taxglide/consts/app_style.dart';
|
||||
|
||||
class OtpScreen extends ConsumerStatefulWidget {
|
||||
const OtpScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<OtpScreen> createState() => _OtpScreenState();
|
||||
}
|
||||
|
||||
class _OtpScreenState extends ConsumerState<OtpScreen> {
|
||||
final ValidationPopup _validationPopup = ValidationPopup();
|
||||
final int otpLength = 4;
|
||||
final List<TextEditingController> _controllers = [];
|
||||
final List<FocusNode> _focusNodes = [];
|
||||
String otpValue = '';
|
||||
|
||||
Timer? _timer;
|
||||
int _remainingSeconds = 600;
|
||||
bool _canResend = false;
|
||||
|
||||
late String _identifier; // Email or Mobile
|
||||
bool _fromForgot = false;
|
||||
bool _isEmployee = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final args = Get.arguments as Map<String, dynamic>? ?? {};
|
||||
_fromForgot = args['fromForgot'] ?? false;
|
||||
_isEmployee = args['isEmployee'] ?? false;
|
||||
_identifier = args['email'] ?? args['mobile'] ?? '';
|
||||
|
||||
for (int i = 0; i < otpLength; i++) {
|
||||
_controllers.add(TextEditingController());
|
||||
_focusNodes.add(FocusNode());
|
||||
}
|
||||
_startTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
for (var c in _controllers) c.dispose();
|
||||
for (var f in _focusNodes) f.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_canResend = false;
|
||||
_remainingSeconds = 30;
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (_remainingSeconds > 0) {
|
||||
setState(() => _remainingSeconds--);
|
||||
} else {
|
||||
setState(() => _canResend = true);
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _formatTime(int seconds) {
|
||||
int minutes = seconds ~/ 60;
|
||||
int remainingSeconds = seconds % 60;
|
||||
return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _resendOtp() async {
|
||||
if (!_canResend) return;
|
||||
for (var controller in _controllers) controller.clear();
|
||||
setState(() => otpValue = '');
|
||||
_focusNodes[0].requestFocus();
|
||||
|
||||
if (_fromForgot) {
|
||||
await ref.read(forgotPasswordProvider.notifier).requestOtp(_identifier, _isEmployee);
|
||||
final state = ref.read(forgotPasswordProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
|
||||
_startTimer();
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
|
||||
);
|
||||
} else {
|
||||
// Original mobile login resend (if still needed)
|
||||
await ref.read(loginProvider.notifier).login(_identifier);
|
||||
final loginState = ref.read(loginProvider);
|
||||
loginState.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP has been resent successfully!");
|
||||
_startTimer();
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Failed to resend OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (error, _) => _validationPopup.showErrorMessage(context, "Failed to resend OTP"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _verifyOtp() async {
|
||||
if (otpValue.length != otpLength) {
|
||||
_validationPopup.showErrorMessage(context, "Please enter all OTP digits");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_fromForgot) {
|
||||
await ref.read(forgotPasswordProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||
final state = ref.read(forgotPasswordProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||
Get.toNamed(ConstRouters.mpinSet);
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||
);
|
||||
} else {
|
||||
// Original mobile login verify
|
||||
await ref.read(loginProvider.notifier).verifyOtp(_identifier, otpValue);
|
||||
final state = ref.read(loginProvider);
|
||||
state.when(
|
||||
data: (result) {
|
||||
if (result['success'] == true) {
|
||||
_validationPopup.showSuccessMessage(context, "OTP Verified successfully!");
|
||||
Get.offAllNamed(ConstRouters.mpinSet);
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(context, result['error'] ?? "Invalid OTP");
|
||||
}
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) => _validationPopup.showErrorMessage(context, "Verification failed"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _onOtpChange(int index, String value) {
|
||||
if (value.isNotEmpty && index < otpLength - 1) {
|
||||
_focusNodes[index + 1].requestFocus();
|
||||
}
|
||||
if (value.isEmpty && index > 0) {
|
||||
_focusNodes[index - 1].requestFocus();
|
||||
}
|
||||
setState(() {
|
||||
otpValue = _controllers.map((c) => c.text).join();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isLoading = _fromForgot
|
||||
? ref.watch(forgotPasswordProvider).isLoading
|
||||
: ref.watch(loginProvider).isLoading;
|
||||
|
||||
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 resendFontSize = r.fontSize(mobile: 13, tablet: 14, desktop: 15);
|
||||
final timerFontSize = r.fontSize(mobile: 14, tablet: 16, desktop: 18);
|
||||
|
||||
final otpBoxWidth = r.getValue<double>(mobile: 52, tablet: 60, desktop: 68);
|
||||
final otpBoxHeight = r.getValue<double>(mobile: 48, tablet: 56, desktop: 64);
|
||||
final otpFontSize = r.fontSize(mobile: 22, tablet: 28, desktop: 32);
|
||||
final otpBoxMargin = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
final otpBoxRadius = r.getValue<double>(mobile: 5, tablet: 6, desktop: 8);
|
||||
|
||||
final spacingSM = r.spacing(mobile: 20, tablet: 20, desktop: 24);
|
||||
final spacingMD = r.spacing(mobile: 22, tablet: 22, desktop: 26);
|
||||
final spacingLG = r.spacing(mobile: 30, tablet: 30, desktop: 36);
|
||||
|
||||
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,
|
||||
children: [
|
||||
Image.asset(
|
||||
AppAssets.taxgildelogoauth,
|
||||
width: logoWidth,
|
||||
height: logoHeight,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"Enter OTP",
|
||||
style: AppTextStyles.bold.copyWith(
|
||||
fontSize: titleFontSize,
|
||||
color: AppColors.authheading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
"OTP has been sent to ${_identifier}",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: subtitleFontSize,
|
||||
color: AppColors.authleading,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingMD),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(otpLength, (index) {
|
||||
bool isFilled = _controllers[index].text.isNotEmpty;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: otpBoxMargin),
|
||||
width: otpBoxWidth,
|
||||
height: otpBoxHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: isFilled ? AppColors.commanbutton : Colors.white,
|
||||
borderRadius: BorderRadius.circular(otpBoxRadius),
|
||||
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,
|
||||
enabled: !isLoading,
|
||||
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: spacingSM),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GestureDetector(
|
||||
onTap: _canResend && !isLoading ? _resendOtp : null,
|
||||
child: Text(
|
||||
"Resend",
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: resendFontSize,
|
||||
color: _canResend && !isLoading
|
||||
? AppColors.authchange
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSM),
|
||||
Text(
|
||||
_formatTime(_remainingSeconds),
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: timerFontSize,
|
||||
color: _remainingSeconds > 0 ? AppColors.authheading : Colors.red,
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingLG),
|
||||
isLoading
|
||||
? const CircularProgressIndicator()
|
||||
: CommanButton(text: "Verify", onPressed: _verifyOtp),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ import 'dart:async';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:taxglide/auth/mpin_set_screen.dart';
|
||||
import 'package:taxglide/consts/app_asstes.dart';
|
||||
import 'package:taxglide/consts/app_colors.dart';
|
||||
import 'package:taxglide/consts/comman_button.dart';
|
||||
@@ -155,7 +157,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
}
|
||||
|
||||
// Call verify OTP API for signup
|
||||
await ref.read(signupProvider.notifier).verifySignupOtp(mobile, otpValue);
|
||||
await ref.read(signupProvider.notifier).verifySignupOtp(email, otpValue);
|
||||
|
||||
final signupState = ref.read(signupProvider);
|
||||
|
||||
@@ -169,7 +171,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
|
||||
// Navigate to main screen after successful verification
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Get.offAll(() => MainController());
|
||||
Get.offAll(() => MpinSetScreen());
|
||||
});
|
||||
} else {
|
||||
_validationPopup.showErrorMessage(
|
||||
@@ -208,7 +210,20 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
final signupState = ref.watch(signupProvider);
|
||||
final isLoading = signupState is AsyncLoading;
|
||||
|
||||
return Scaffold(
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (didPop) return;
|
||||
Get.offNamed(
|
||||
ConstRouters.signup,
|
||||
arguments: {
|
||||
'name': name,
|
||||
'email': email,
|
||||
'mobile': mobile,
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
// Background gradient
|
||||
@@ -257,10 +272,10 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
"OTP has been sent to your registered mobile number",
|
||||
"OTP has been sent to your registered mail id",
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.semiBold.copyWith(
|
||||
fontSize: 14,
|
||||
fontSize: 12,
|
||||
height: 1.4,
|
||||
letterSpacing: 0.03 * 14,
|
||||
color: AppColors.authleading,
|
||||
@@ -269,7 +284,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
const SizedBox(height: 22),
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
text: mobile,
|
||||
text: email,
|
||||
style: AppTextStyles.medium.copyWith(
|
||||
fontSize: 13,
|
||||
height: 1.8,
|
||||
@@ -278,7 +293,7 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: " ( Change Number )",
|
||||
text: " ( Change mail id )",
|
||||
style: AppTextStyles.extraBold.copyWith(
|
||||
fontSize: 13,
|
||||
height: 1.8,
|
||||
@@ -331,26 +346,39 @@ class _RegisterOtpScreenState extends ConsumerState<RegisterOtpScreen> {
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
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,
|
||||
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,
|
||||
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> {
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user