969 lines
46 KiB
Dart
Executable File
969 lines
46 KiB
Dart
Executable File
import 'dart:convert';
|
|
import 'dart:io';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:jwt_decode/jwt_decode.dart';
|
|
import 'package:nhance_app_pwa/customAppBar/toastHelper.dart';
|
|
import 'package:pinput/pinput.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../../config/environment.dart';
|
|
import '../../customAppBar/responsive.dart';
|
|
import '../postEnrollment/service/svg_service.dart';
|
|
import '../service/SessionManager.dart';
|
|
import '../service/TokenService.dart';
|
|
import 'authenticationService.dart';
|
|
|
|
import 'package:nhance_app_pwa/logger.dart';
|
|
|
|
class pinPage extends StatefulWidget {
|
|
const pinPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<pinPage> createState() => _pinPageState();
|
|
}
|
|
|
|
class _pinPageState extends State<pinPage> {
|
|
final AuthService _authService = AuthService();
|
|
final TextEditingController _pinController = TextEditingController();
|
|
final _formKey = GlobalKey<FormState>();
|
|
late final FocusNode focusNode;
|
|
String? savedPin;
|
|
dynamic empMobileNo;
|
|
dynamic empEmailid;
|
|
dynamic _token;
|
|
dynamic _postToken;
|
|
dynamic empCodeString;
|
|
dynamic empClientBranchId;
|
|
dynamic empPrimaryId;
|
|
dynamic gpaEmpName;
|
|
dynamic client_id;
|
|
dynamic emp_status;
|
|
dynamic enrollmentEmpCodeString;
|
|
dynamic enrollmentEmpClientBranchId;
|
|
dynamic enrollmentEmpPrimaryId;
|
|
dynamic enrollmentGpaEmpName;
|
|
dynamic enrollmentClient_id;
|
|
dynamic clientName;
|
|
dynamic clientLogo;
|
|
dynamic enrollmentEmp_status;
|
|
dynamic bioMetricMpin;
|
|
dynamic biometricStatus;
|
|
dynamic isMpinSkippedStatus;
|
|
late SessionManager session;
|
|
bool _isVerifyingForgotPin = false;
|
|
bool _isPinForgotVerified = false;
|
|
bool _isVerifyingPin = false;
|
|
bool _isPinVerified = false; // hard success lock
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_checkBiometricAuthentication();
|
|
// _loadSavedPin();
|
|
focusNode = FocusNode();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
focusNode.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> checkLoginPin(BuildContext context) async {
|
|
logDebug('checkLoginPin');
|
|
try {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
empMobileNo = prefs.getString('empMobileNo');
|
|
empEmailid = prefs.getString('empEmailid');
|
|
logDebug('empMobileNo $empMobileNo');
|
|
logDebug('empEmailid $empEmailid');
|
|
// _preToken = prefs.getString('token');
|
|
var params = {};
|
|
if (empMobileNo != null && empMobileNo.isNotEmpty) {
|
|
params = {'mobile_number': empMobileNo};
|
|
} else if (empEmailid != null && empEmailid.isNotEmpty) {
|
|
params = {'email_id': empEmailid};
|
|
}
|
|
|
|
final response = await http.post(
|
|
Uri.parse(Environment.apiUrlEnrollment + 'checkMpin'),
|
|
body: json.encode(params),
|
|
headers: {
|
|
HttpHeaders.contentTypeHeader: 'application/json',
|
|
'APP-SIGNATURE': 'nhance-2025-signature-T8f6gV9k5fK2wf5V5c4vId3b0J8z6cAm2x8Y',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
logDebug('checkLoginPin response');
|
|
Map<String, dynamic> data = json.decode(response.body);
|
|
if (data['status'] == 'success') {
|
|
logDebug('checkLoginPin success');
|
|
if (data['data'] != null) {
|
|
prefs.setString('mpinText', data['data']);
|
|
}
|
|
|
|
if (data['Mpin'] != null) {
|
|
prefs.setString('mpin', data['Mpin']);
|
|
}
|
|
|
|
if (data['is_biometric_enabled'] != null) {
|
|
prefs.setString(
|
|
'is_biometric_enabled', data['is_biometric_enabled']);
|
|
}
|
|
|
|
if (data['is_mpin_skipped'] != null) {
|
|
prefs.setString('is_mpin_skipped', data['is_mpin_skipped']);
|
|
}
|
|
}
|
|
} else {
|
|
logDebug('checkLoginPin Unable to process. Please try again later');
|
|
ToastHelper.showErrorToast(context, 'Unable to process. Please try again later');
|
|
throw Exception('Failed to verify pin number');
|
|
}
|
|
} catch (e) {
|
|
ToastHelper.showErrorToast(context, 'Unable to process. Please try again later');
|
|
logDebug('Error: $e');
|
|
}
|
|
}
|
|
|
|
Future<void> _checkBiometricAuthentication() async {
|
|
await checkLoginPin(context);
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
bioMetricMpin = prefs.getString('mpin');
|
|
biometricStatus = prefs.getString('is_biometric_enabled');
|
|
isMpinSkippedStatus = prefs.getString('is_mpin_skipped');
|
|
logDebug('biometricStatus');
|
|
logDebug(biometricStatus);
|
|
|
|
if(biometricStatus == '1' && !_isVerifyingPin && !_isPinVerified) {
|
|
bool authenticated = await _authService.authenticateWithBiometrics();
|
|
if (authenticated) {
|
|
setState(() {
|
|
_isVerifyingPin = true;
|
|
});
|
|
enterPinApi(bioMetricMpin);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> enterPinApi(mpin) async {
|
|
logDebug('mpin $mpin');
|
|
try {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
empMobileNo = prefs.getString('empMobileNo');
|
|
empEmailid = prefs.getString('empEmailid');
|
|
var params = {};
|
|
if(mpin != null && mpin.isNotEmpty){
|
|
|
|
if (empMobileNo != null && empMobileNo.isNotEmpty) {
|
|
logDebug('mpin empMobileNo');
|
|
params = {'mobile_number': empMobileNo, 'mpin': mpin};
|
|
} else if(empEmailid != null && empEmailid.isNotEmpty){
|
|
logDebug('mpin empEmailid');
|
|
params = {'email_id': empEmailid, 'mpin': mpin};
|
|
}
|
|
} else {
|
|
if (empMobileNo != null && empMobileNo.isNotEmpty) {
|
|
params = {'mobile_number': empMobileNo, 'mpin': _pinController.text};
|
|
} else if(empEmailid != null && empEmailid.isNotEmpty){
|
|
params = {'email_id': empEmailid, 'mpin': _pinController.text};
|
|
}
|
|
// _token = prefs.getString('token');
|
|
}
|
|
|
|
|
|
final response = await http.post(
|
|
Uri.parse(Environment.apiUrlEnrollment + 'verifyMpin'),
|
|
body: json.encode(params),
|
|
headers: {
|
|
HttpHeaders.contentTypeHeader: 'application/json',
|
|
'APP-SIGNATURE': 'nhance-2025-signature-T8f6gV9k5fK2wf5V5c4vId3b0J8z6cAm2x8Y',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
Map<String, dynamic> data = json.decode(response.body);
|
|
logDebug('data: $data');
|
|
_token = data['data'];
|
|
String status = data['status'];
|
|
|
|
// Directly access the post_enrollment data
|
|
Map<String, dynamic> post = data['post_enrollment'];
|
|
logDebug('post: $post');
|
|
_postToken = post['data'];
|
|
String postStatus = post['status'];
|
|
|
|
// Save tokens
|
|
await TokenService.saveTokens(preToken: _token, postToken: _postToken);
|
|
logDebug('Tokens saved → preToken: $_token, postToken: $_postToken');
|
|
|
|
if (postStatus == 'success') {
|
|
postSuccessData(post, data);
|
|
} else if (status == 'success') {
|
|
enrollmentSuccessData(data);
|
|
} else {
|
|
ToastHelper.showErrorToast(context, 'Invalid Pin Number');
|
|
logDebug('Invalid Pin Number');
|
|
}
|
|
} else if (response.statusCode == 401) {
|
|
await SessionManager().clear();
|
|
ToastHelper.showErrorToast(context, 'Session Out');
|
|
if (!context.mounted) return;
|
|
context.go('/login');
|
|
|
|
} else if (response.statusCode == 403) {
|
|
await SessionManager().clear();
|
|
ToastHelper.showErrorToast(context, 'Session Out');
|
|
if (!context.mounted) return;
|
|
context.go('/login');
|
|
|
|
} else if (response.statusCode == 451) {
|
|
final body = jsonDecode(response.body);
|
|
final message = body['message'];
|
|
ToastHelper.showWarningToast(context, message);
|
|
} else if (response.statusCode == 429) {
|
|
final body = jsonDecode(response.body);
|
|
final message = body['message'];
|
|
ToastHelper.showWarningToast(context, message);
|
|
} else {
|
|
throw Exception('Failed to load data');
|
|
}
|
|
} catch (e) {
|
|
ToastHelper.showErrorToast(context, 'Unable to process. Please try again later');
|
|
context.go('/login');
|
|
logDebug('Error: $e');
|
|
}
|
|
}
|
|
|
|
void postSuccessData(post, data) async {
|
|
String status = data['status'];
|
|
String postStatus = post['status'];
|
|
|
|
if (postStatus == 'success') {
|
|
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// prefs.setString('_postToken', post['data']);
|
|
|
|
await SessionManager().initializeFromPostToken(post['data']);
|
|
|
|
session = await SessionManager();
|
|
// Decode the JWT token received from the API response
|
|
// Map<String, dynamic>? decodedToken = Jwt.parseJwt(post['data']);
|
|
// logDebug('postdecodedToken : $decodedToken');
|
|
// empClientBranchId = decodedToken['client_branch_id'];
|
|
// prefs.setString('empClientBranchId', empClientBranchId);
|
|
// empCodeString = decodedToken['emp_code'].toString();
|
|
// prefs.setString('empCode', empCodeString);
|
|
// empPrimaryId = decodedToken['id'];
|
|
// prefs.setString('empPrimaryId', empPrimaryId);
|
|
// gpaEmpName = decodedToken['name'].toString();
|
|
// prefs.setString('gpaEmpName', gpaEmpName);
|
|
// client_id = decodedToken['client_id'];
|
|
// prefs.setString('client_id', client_id);
|
|
// emp_status = decodedToken['emp_status'];
|
|
// prefs.setString('emp_status', emp_status);
|
|
// getClientLogoAndDetails();
|
|
|
|
logDebug('Successfully Login');
|
|
|
|
// Redirect to another page
|
|
}
|
|
|
|
if (status == 'success') {
|
|
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// prefs.setString('enrollToken', data['data']);
|
|
await SessionManager().initializeFromPreToken(data['data']);
|
|
// // Decode the JWT token received from the API response
|
|
// Map<String, dynamic>? decodedToken = Jwt.parseJwt(data['data']);
|
|
// logDebug('enrolldecodedToken : $decodedToken');
|
|
// enrollmentEmpClientBranchId = decodedToken['client_branch_id'];
|
|
// prefs.setString(
|
|
// 'enrollmentEmpClientBranchId', enrollmentEmpClientBranchId);
|
|
// enrollmentEmpCodeString = decodedToken['emp_code'].toString();
|
|
// prefs.setString('enrollmentEmpCodeString', enrollmentEmpCodeString);
|
|
// enrollmentEmpPrimaryId = decodedToken['id'];
|
|
// prefs.setString('enrollmentEmpPrimaryId', enrollmentEmpPrimaryId);
|
|
// enrollmentGpaEmpName = decodedToken['name'].toString();
|
|
// prefs.setString('enrollmentGpaEmpName', enrollmentGpaEmpName);
|
|
// enrollmentClient_id = decodedToken['client_id'];
|
|
// prefs.setString('enrollmentClient_id', enrollmentClient_id);
|
|
// enrollmentEmp_status = decodedToken['emp_status'];
|
|
// prefs.setString('enrollmentEmp_status', enrollmentEmp_status);
|
|
getClientLogoAndDetails();
|
|
}
|
|
|
|
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
logDebug(_postToken);
|
|
if (_postToken != null && _postToken.isNotEmpty) {
|
|
setState(() {
|
|
_isPinVerified = true; // 🔒 HARD LOCK
|
|
});
|
|
|
|
ToastHelper.showSuccessToast(context, 'Successfully Logged In');
|
|
// if (enrollmentEmp_status == 'enrolled' ||
|
|
// enrollmentEmp_status == 'active') {
|
|
logDebug('Token12345: ${await TokenService.getPostToken()}');
|
|
logDebug('Token00000');
|
|
// if (context.mounted) {
|
|
SessionManager().unlockMobileAppSession();
|
|
context.go('/home');
|
|
// }
|
|
// Navigator.pushReplacementNamed(context, 'home');
|
|
// } else {
|
|
// Navigator.pushReplacementNamed(context, 'empDetails');
|
|
// }
|
|
}
|
|
}
|
|
|
|
void enrollmentSuccessData(data) async {
|
|
await SessionManager().initializeFromPreToken(data['data']);
|
|
// final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
// prefs.setString('enrollToken', data['data']);
|
|
|
|
// // Decode the JWT token received from the API response
|
|
// Map<String, dynamic>? decodedToken = Jwt.parseJwt(data['data']);
|
|
// logDebug('decodedToken : $decodedToken');
|
|
// enrollmentEmpClientBranchId = decodedToken['client_branch_id'];
|
|
// prefs.setString('enrollmentEmpClientBranchId', enrollmentEmpClientBranchId);
|
|
// enrollmentEmpCodeString = decodedToken['emp_code'].toString();
|
|
// prefs.setString('enrollmentEmpCodeString', enrollmentEmpCodeString);
|
|
// enrollmentEmpPrimaryId = decodedToken['id'];
|
|
// prefs.setString('enrollmentEmpPrimaryId', enrollmentEmpPrimaryId);
|
|
// enrollmentGpaEmpName = decodedToken['name'].toString();
|
|
// prefs.setString('enrollmentGpaEmpName', enrollmentGpaEmpName);
|
|
// enrollmentClient_id = decodedToken['client_id'];
|
|
// prefs.setString('enrollmentClient_id', enrollmentClient_id);
|
|
// enrollmentEmp_status = decodedToken['emp_status'];
|
|
// prefs.setString('enrollmentEmp_status', enrollmentEmp_status);
|
|
getClientLogoAndDetails();
|
|
|
|
logDebug('Successfully Login');
|
|
|
|
// Redirect to another page
|
|
final token = await TokenService.getPreToken();
|
|
if (token != null && token.isNotEmpty) {
|
|
setState(() {
|
|
_isPinVerified = true; // 🔒 HARD LOCK
|
|
});
|
|
ToastHelper.showSuccessToast(context, 'Successfully Logged In');
|
|
// if (enrollmentEmp_status == 'enrolled' ||
|
|
// enrollmentEmp_status == 'active') {
|
|
// Navigator.pushReplacementNamed(context, 'home');
|
|
// } else {
|
|
SessionManager().unlockMobileAppSession();
|
|
context.go('/empDetails');
|
|
// Navigator.pushReplacementNamed(context, 'empDetails');
|
|
// }
|
|
}
|
|
}
|
|
|
|
Future<void> enterLoginPin() async {
|
|
if (_isVerifyingPin || _isPinVerified) return;
|
|
|
|
if (!_formKey.currentState!.validate()) return;
|
|
|
|
setState(() {
|
|
_isVerifyingPin = true;
|
|
});
|
|
try {
|
|
await enterPinApi(_pinController.text);
|
|
} catch (e) {
|
|
ToastHelper.showErrorToast(context, 'Unable to process. Please try again later');
|
|
logDebug('Error: $e');
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
_isVerifyingPin = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _loadSavedPin() async {
|
|
savedPin = await _authService.getPin();
|
|
}
|
|
|
|
String? _validatePin(String? value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Please enter a pin';
|
|
}
|
|
if (value.length != 4) {
|
|
return 'Pin must be 4 digits';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Future<void> forgotPin() async {
|
|
if (_isVerifyingForgotPin || _isPinForgotVerified) return;
|
|
setState(() {
|
|
_isVerifyingForgotPin = true;
|
|
});
|
|
try {
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
empMobileNo = prefs.getString('empMobileNo');
|
|
empEmailid = prefs.getString('empEmailid');
|
|
logDebug('empMobileNo $empMobileNo' );
|
|
logDebug('empEmailid $empEmailid');
|
|
// _token = prefs.getString('token');
|
|
var params = {};
|
|
if (empMobileNo != null && empMobileNo.isNotEmpty) {
|
|
params = {'mobile_number': empMobileNo};
|
|
} else if(empEmailid != null && empEmailid.isNotEmpty){
|
|
params = {'email_id': empEmailid};
|
|
}
|
|
logDebug(params);
|
|
final response = await http.post(
|
|
Uri.parse(Environment.apiUrlEnrollment + 'forgotMPIN'),
|
|
body: json.encode(params),
|
|
headers: {
|
|
HttpHeaders.contentTypeHeader: 'application/json',
|
|
'APP-SIGNATURE': 'nhance-2025-signature-T8f6gV9k5fK2wf5V5c4vId3b0J8z6cAm2x8Y',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
Map<String, dynamic> data = json.decode(response.body);
|
|
if (data['status'] == 'success') {
|
|
setState(() {
|
|
_isPinForgotVerified = true; // 🔒 HARD LOCK
|
|
});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.clear();
|
|
await SessionManager().clear();
|
|
// await SessionManager().mobileSessionClear();
|
|
context.go('/login');
|
|
// Navigator.pushNamed(context, 'login');
|
|
// logDebug('data');
|
|
// prefs.setString('mpinText', data['data']);
|
|
// prefs.setString('mpin', data['Mpin']);
|
|
// prefs.setString('is_biometric_enabled', data['is_biometric_enabled']);
|
|
// prefs.setString('is_mpin_skipped', data['is_mpin_skipped']);
|
|
// if(data['is_mpin_skipped'] == '1'){
|
|
// Navigator.pushReplacementNamed(context, 'pinPage');
|
|
// }
|
|
|
|
}
|
|
} else if (response.statusCode == 401) {
|
|
await SessionManager().clear();
|
|
ToastHelper.showErrorToast(context, 'Session Out');
|
|
if (!context.mounted) return;
|
|
context.go('/login');
|
|
|
|
} else if (response.statusCode == 403) {
|
|
await SessionManager().clear();
|
|
ToastHelper.showErrorToast(context, 'Session Out');
|
|
if (!context.mounted) return;
|
|
context.go('/login');
|
|
|
|
} else if (response.statusCode == 451) {
|
|
final body = jsonDecode(response.body);
|
|
final message = body['message'];
|
|
ToastHelper.showWarningToast(context, message);
|
|
} else if (response.statusCode == 429) {
|
|
final body = jsonDecode(response.body);
|
|
final message = body['message'];
|
|
ToastHelper.showWarningToast(context, message);
|
|
} else {
|
|
throw Exception('Failed to load data');
|
|
}
|
|
} catch (e) {
|
|
// ToastHelper.showErrorToast(context, 'Unable to process. Please try again later');
|
|
logDebug('Error: $e');
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
_isVerifyingForgotPin = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
Future<void> getClientLogoAndDetails() async {
|
|
session = await SessionManager();
|
|
var url = Uri.parse(Environment.apiUrlEnrollment +
|
|
'getClientDetails?post_client_id=${session.client_id}&post_branch_id=${session.empClientBranchId}&pre_client_id=${session.enrollmentClient_id}&pre_branch_id=${session.enrollmentEmpClientBranchId}');
|
|
try {
|
|
var response = await http.get(
|
|
url,
|
|
headers: {
|
|
'Authorization':
|
|
'Bearer $_token', // Add token to the Authorization header
|
|
'APP-SIGNATURE': 'nhance-2025-signature-T8f6gV9k5fK2wf5V5c4vId3b0J8z6cAm2x8Y',
|
|
},
|
|
);
|
|
if (response.statusCode == 200) {
|
|
// logDebug('response.statusCode == 200');
|
|
Map<String, dynamic> data = json.decode(response.body);
|
|
// logDebug(data);
|
|
|
|
if (data.containsKey('data')) {
|
|
dynamic clientDetails = data['data'];
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
prefs.setString('clientLogo', clientDetails['client']['client_logo']);
|
|
prefs.setString('clientName', clientDetails['client']['client_name']);
|
|
setState(() {
|
|
clientName = clientDetails['client']['client_name'];
|
|
logDebug(clientName);
|
|
clientLogo = clientDetails['client']['client_logo'];
|
|
logDebug(clientLogo);
|
|
});
|
|
} else {
|
|
logDebug('API request failed with status: ${data['status']}');
|
|
}
|
|
} else {
|
|
logDebug('Request failed with status: ${response.statusCode}');
|
|
}
|
|
} catch (e) {
|
|
logDebug('Exception occurred: $e');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
const focusedBorderColor = Color.fromRGBO(23, 171, 144, 1);
|
|
const fillColor = Color.fromRGBO(243, 246, 249, 0);
|
|
const borderColor = Color.fromRGBO(23, 171, 144, 0.4);
|
|
|
|
Size _size = MediaQuery.of(context).size;
|
|
EdgeInsets marginInsets = EdgeInsets.zero;
|
|
if (Responsive.isDesktop(context)) {
|
|
marginInsets = const EdgeInsets.only(
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
top: 0,
|
|
);
|
|
} else if (Responsive.isMobile(context)) {
|
|
marginInsets = const EdgeInsets.only(
|
|
left: 25, // Example value for mobile
|
|
right: 25, // Example value for mobile
|
|
bottom: 0, // Example value for mobile
|
|
top: 0, // Example value for mobile
|
|
);
|
|
} else if (Responsive.isTablet(context)) {
|
|
marginInsets = const EdgeInsets.only(
|
|
left: 25, // Example value for mobile
|
|
right: 25, // Example value for mobile
|
|
bottom: 0, // Example value for mobile
|
|
top: 0, // Example value for mobile
|
|
);
|
|
}
|
|
|
|
final defaultPinTheme = PinTheme(
|
|
width: 56,
|
|
height: 56,
|
|
textStyle: const TextStyle(
|
|
fontSize: 20,
|
|
color: Color.fromRGBO(30, 60, 87, 1),
|
|
),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(19),
|
|
border: Border.all(color: borderColor),
|
|
),
|
|
);
|
|
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
return false;
|
|
},
|
|
child: Scaffold(
|
|
resizeToAvoidBottomInset: true, // IMPORTANT
|
|
bottomNavigationBar: SafeArea(
|
|
child: Container(
|
|
color: Colors.white, // 👈 set your color here
|
|
padding: const EdgeInsets.only(bottom: 8, top: 4),
|
|
child: RichText(
|
|
textAlign: TextAlign.center,
|
|
text: TextSpan(
|
|
text: 'By continuing, you agree with our ',
|
|
style: GoogleFonts.poppins(
|
|
color: Colors.black,
|
|
fontSize: 9,
|
|
),
|
|
children: const [
|
|
TextSpan(
|
|
text: 'privacy policy ',
|
|
style: TextStyle(color: Color(0xFF00989E)),
|
|
),
|
|
TextSpan(text: 'and '),
|
|
TextSpan(
|
|
text: 'terms of use',
|
|
style: TextStyle(color: Color(0xFF00989E)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
body: Container(
|
|
color: Colors.white, // Set the color for the body
|
|
child: SizedBox.expand(
|
|
child: Stack(children: [
|
|
SingleChildScrollView(
|
|
child: Container(
|
|
padding: EdgeInsets.all(0),
|
|
color: Color(0xFFFFFCE5),
|
|
child: Column(children: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Color(
|
|
0xFFFFFCE5), // Set background color for the container
|
|
borderRadius: BorderRadius.circular(
|
|
10), // Set border radius for the container
|
|
),
|
|
// padding: EdgeInsets.only(top: 0, bottom: 0, left: 10, right: 10),
|
|
child: Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(height: 8),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
flex: 12,
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 16.0), // Add left margin
|
|
child: Image.asset(
|
|
'assets/nhance_app_logo.png',
|
|
width: 150,
|
|
height: 100,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 10),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
flex: 12,
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 16.0), // Add left margin
|
|
child: SvgPicture.string(
|
|
SvgService.getSvg('mpin'),
|
|
width: 150,
|
|
height: 150,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 30),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
flex: 12,
|
|
child: Text(
|
|
'Enter PIN to login',
|
|
textAlign: TextAlign.center,
|
|
style: GoogleFonts.poppins(
|
|
fontSize: 16,
|
|
color: Color(0xFF404040),
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(height: 10),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors
|
|
.white, // Set background color for the container
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(150.0),
|
|
topRight: Radius.circular(0),
|
|
), // Set border radius for the container
|
|
),
|
|
padding: EdgeInsets.only(
|
|
top: 20, bottom: 10, left: 10, right: 10),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
margin: marginInsets,
|
|
alignment: Alignment.bottomCenter,
|
|
child: SingleChildScrollView(
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
flex: 12,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 40),
|
|
Container(
|
|
margin:
|
|
EdgeInsets.symmetric(
|
|
horizontal: 30),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment
|
|
.start, // Align text to the right
|
|
children: [
|
|
Align(
|
|
// alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'Enter the 4 Digit pin',
|
|
style: GoogleFonts
|
|
.poppins(
|
|
fontSize: 16,
|
|
color: Color(
|
|
0xFF909090),
|
|
fontWeight:
|
|
FontWeight
|
|
.w400,
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
SizedBox(height: 5),
|
|
Container(
|
|
margin:
|
|
EdgeInsets.symmetric(
|
|
horizontal: 0),
|
|
child: Pinput(
|
|
enabled: !_isVerifyingPin && !_isPinVerified,
|
|
length: 4,
|
|
defaultPinTheme:
|
|
defaultPinTheme,
|
|
separatorBuilder:
|
|
(index) =>
|
|
const SizedBox(
|
|
width: 8),
|
|
showCursor: true,
|
|
controller:
|
|
_pinController,
|
|
validator: _validatePin,
|
|
errorPinTheme:
|
|
defaultPinTheme
|
|
.copyBorderWith(
|
|
border: Border.all(
|
|
color: Colors
|
|
.redAccent),
|
|
),
|
|
hapticFeedbackType:
|
|
HapticFeedbackType
|
|
.lightImpact,
|
|
onCompleted: (pin) {
|
|
logDebug(
|
|
'onCompleted: $pin');
|
|
},
|
|
onChanged: (value) {
|
|
logDebug(
|
|
'onChanged: $value');
|
|
},
|
|
cursor: Column(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment
|
|
.end,
|
|
children: [
|
|
Container(
|
|
margin:
|
|
const EdgeInsets
|
|
.only(
|
|
bottom: 9),
|
|
width: 22,
|
|
height: 1,
|
|
color:
|
|
focusedBorderColor,
|
|
),
|
|
],
|
|
),
|
|
focusedPinTheme:
|
|
defaultPinTheme
|
|
.copyWith(
|
|
decoration:
|
|
defaultPinTheme
|
|
.decoration!
|
|
.copyWith(
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(8),
|
|
border: Border.all(
|
|
color:
|
|
focusedBorderColor),
|
|
),
|
|
),
|
|
obscureText: true,
|
|
obscuringWidget: const Text(
|
|
'●',
|
|
style: TextStyle(fontSize: 12,color: Colors.black87),
|
|
),
|
|
submittedPinTheme:
|
|
defaultPinTheme
|
|
.copyWith(
|
|
decoration:
|
|
defaultPinTheme
|
|
.decoration!
|
|
.copyWith(
|
|
color: fillColor,
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(19),
|
|
border: Border.all(
|
|
color:
|
|
focusedBorderColor),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 15),
|
|
Container(
|
|
margin:
|
|
EdgeInsets.symmetric(
|
|
horizontal: 30),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
height: 45,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton
|
|
.styleFrom(
|
|
backgroundColor:
|
|
Color(0xFF00989E),
|
|
shape:
|
|
RoundedRectangleBorder(
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(
|
|
10),
|
|
),
|
|
),
|
|
onPressed: (_isVerifyingPin || _isPinVerified)
|
|
? null
|
|
: () {
|
|
enterLoginPin();
|
|
},
|
|
child: _isVerifyingPin
|
|
? const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
),
|
|
)
|
|
: Text(
|
|
"Submit",
|
|
style: GoogleFonts.poppins(color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 15),
|
|
Container(
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment
|
|
.center,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: (_isVerifyingForgotPin || _isPinForgotVerified)
|
|
? null
|
|
: () {
|
|
forgotPin();
|
|
},
|
|
child: Text(
|
|
'Forgot PIN?',
|
|
style: GoogleFonts
|
|
.poppins(
|
|
fontSize: 12,
|
|
color: Color(
|
|
0xFF929292),
|
|
fontWeight:
|
|
FontWeight
|
|
.w400,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 15),
|
|
Container(
|
|
margin:
|
|
EdgeInsets.symmetric(
|
|
horizontal: 30),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
height: 45,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton
|
|
.styleFrom(
|
|
backgroundColor:
|
|
Color(0xFF00989E),
|
|
shape:
|
|
RoundedRectangleBorder(
|
|
borderRadius:
|
|
BorderRadius
|
|
.circular(
|
|
10),
|
|
),
|
|
),
|
|
onPressed: (_isVerifyingForgotPin || _isPinForgotVerified)
|
|
? null
|
|
: () {
|
|
forgotPin();
|
|
},
|
|
child: _isVerifyingForgotPin
|
|
? const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(
|
|
strokeWidth: 2,
|
|
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
|
),
|
|
)
|
|
: Text(
|
|
"Login with OTP",
|
|
style: GoogleFonts
|
|
.poppins(
|
|
color: Color(
|
|
0xFFFFFFFF)),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
]),
|
|
)),
|
|
]),
|
|
))));
|
|
}
|
|
}
|