diff --git a/lib/pages/login/confirm-login.dart b/lib/pages/login/confirm-login.dart index e773957a..d9f2d614 100644 --- a/lib/pages/login/confirm-login.dart +++ b/lib/pages/login/confirm-login.dart @@ -40,18 +40,17 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:intl/intl.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; -import 'package:local_auth_ios/local_auth_ios.dart'; +import 'package:local_auth_darwin/types/auth_messages_ios.dart'; class ConfirmLogin extends StatefulWidget { final Function? changePageViewIndex; final fromRegistration; final bool isDubai; - const ConfirmLogin( - {Key? key, - this.changePageViewIndex, - this.fromRegistration = false, - this.isDubai = false}) + const ConfirmLogin({Key? key, + this.changePageViewIndex, + this.fromRegistration = false, + this.isDubai = false}) : super(key: key); @override @@ -65,7 +64,7 @@ class _ConfirmLogin extends State { bool authenticated = false; final authService = AuthProvider(); PharmacyModuleViewModel pharmacyModuleViewModel = - locator(); + locator(); late int mobileNumber; String errorMsg = ''; SelectDeviceIMEIRES? user; @@ -96,9 +95,9 @@ class _ConfirmLogin extends State { int fingrePrintBefore = 0; AuthenticatedUserObject authenticatedUserObject = - locator(); + locator(); AppointmentRateViewModel appointmentRateViewModel = - locator(); + locator(); late ProjectViewModel projectViewModel; late ToDoCountProviderModel toDoProvider; @@ -145,7 +144,9 @@ class _ConfirmLogin extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - TranslationBase.of(context).welcomeBack, + TranslationBase + .of(context) + .welcomeBack, style: TextStyle( fontSize: 12, fontWeight: FontWeight.w600, @@ -163,7 +164,9 @@ class _ConfirmLogin extends State { ), SizedBox(height: 10), Text( - TranslationBase.of(context).accountInfo, + TranslationBase + .of(context) + .accountInfo, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -189,11 +192,12 @@ class _ConfirmLogin extends State { children: [ Row( mainAxisAlignment: - MainAxisAlignment.spaceBetween, + MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - TranslationBase.of(context) + TranslationBase + .of(context) .lastLoginAt .toCamelCase, style: TextStyle( @@ -208,8 +212,8 @@ class _ConfirmLogin extends State { // : user!.createdOn != null ? DateUtil.getDayMonthYearDateFormatted( - DateUtil.convertStringToDate( - user!.createdOn!)) + DateUtil.convertStringToDate( + user!.createdOn!)) : '--', style: TextStyle( fontSize: 12, @@ -221,11 +225,12 @@ class _ConfirmLogin extends State { ), Row( mainAxisAlignment: - MainAxisAlignment.spaceBetween, + MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - TranslationBase.of(context) + TranslationBase + .of(context) .lastLoginWith .toCamelCase, style: TextStyle( @@ -252,9 +257,9 @@ class _ConfirmLogin extends State { // : user!.createdOn != null ? DateUtil.formatDateToTimeLang( - DateUtil.convertStringToDate( - user!.createdOn!), - false) + DateUtil.convertStringToDate( + user!.createdOn!), + false) : '--', style: TextStyle( fontSize: 12, @@ -268,7 +273,9 @@ class _ConfirmLogin extends State { ), ), Text( - TranslationBase.of(context).pleaseVerify, + TranslationBase + .of(context) + .pleaseVerify, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -277,10 +284,10 @@ class _ConfirmLogin extends State { ), GridView( gridDelegate: - SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - crossAxisSpacing: 13, - mainAxisSpacing: 9), + SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + crossAxisSpacing: 13, + mainAxisSpacing: 9), physics: NeverScrollableScrollPhysics(), padding: EdgeInsets.only(top: 9), shrinkWrap: true, @@ -306,27 +313,32 @@ class _ConfirmLogin extends State { SizedBox(height: 23), this.onlySMSBox == false ? Text( - TranslationBase.of(context).verifyLoginWith, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Color(0xff2B353E), - letterSpacing: -0.64, - height: 25 / 16), - ) + TranslationBase + .of(context) + .verifyLoginWith, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Color(0xff2B353E), + letterSpacing: -0.64, + height: 25 / 16), + ) : Text( - TranslationBase.of(context) - .verifyFingerprint2, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Color(0xff2B353E), - letterSpacing: -0.64, - height: 25 / 16), - ), + TranslationBase + .of(context) + .verifyFingerprint2, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Color(0xff2B353E), + letterSpacing: -0.64, + height: 25 / 16), + ), SizedBox(height: 23), Text( - TranslationBase.of(context).pleaseVerify, + TranslationBase + .of(context) + .pleaseVerify, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -335,10 +347,10 @@ class _ConfirmLogin extends State { ), GridView( gridDelegate: - SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - crossAxisSpacing: 13, - mainAxisSpacing: 9), + SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + crossAxisSpacing: 13, + mainAxisSpacing: 9), physics: NeverScrollableScrollPhysics(), padding: EdgeInsets.only(top: 9), shrinkWrap: true, @@ -357,8 +369,10 @@ class _ConfirmLogin extends State { height: 12, ), DefaultButton( - TranslationBase.of(context).useAnotherAccount, - () { + TranslationBase + .of(context) + .useAnotherAccount, + () { Navigator.of(context).pushNamed(LOGIN_TYPE); projectViewModel.analytics.loginRegistration .login_with_other_account(); @@ -450,22 +464,23 @@ class _ConfirmLogin extends State { sharedPref.setObject(REGISTER_DATA_FOR_REGISTER, request); authService .checkPatientAuthentication(request) - .then((value) => { - GifLoaderDialogUtils.hideDialog(context), - if (value['isSMSSent']) - { - sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), - this.loginTokenID = value['LogInTokenID'], - sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), - // Future.delayed(Duration(seconds: 1), () { - this.sendActivationCode(type) - // }) - } - else - { - if (value['IsAuthenticated']) {this.checkActivationCode()} - } - }) + .then((value) => + { + GifLoaderDialogUtils.hideDialog(context), + if (value['isSMSSent']) + { + sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), + this.loginTokenID = value['LogInTokenID'], + sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), + // Future.delayed(Duration(seconds: 1), () { + this.sendActivationCode(type) + // }) + } + else + { + if (value['IsAuthenticated']) {this.checkActivationCode()} + } + }) .catchError((err) { print(err); GifLoaderDialogUtils.hideDialog(context); @@ -516,10 +531,11 @@ class _ConfirmLogin extends State { context, type, this.mobileNumber, - (value) { + (value) { this.checkActivationCode(value: value); }, - () => { + () => + { Navigator.pop(context), }, ).displayDialog(context); @@ -611,12 +627,12 @@ class _ConfirmLogin extends State { this.zipCode = this.registerd_data != null ? this.registerd_data.zipCode : this.user!.outSA == true - ? "971" - : "966"; + ? "971" + : "966"; this.patientOutSA = this.registerd_data != null ? this.registerd_data.zipCode == "966" - ? 0 - : 1 + ? 0 + : 1 : this.user!.outSA; if (this.registerd_data != null) { this.loginTokenID = await sharedPref.getString(LOGIN_TOKEN_ID); @@ -637,8 +653,8 @@ class _ConfirmLogin extends State { this.lastLogin = await sharedPref.getInt(LAST_LOGIN) != null ? await sharedPref.getInt(LAST_LOGIN) : user != null - ? user!.logInType - : null; + ? user!.logInType + : null; showLoader(false); //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN); @@ -652,7 +668,7 @@ class _ConfirmLogin extends State { request.projectOutSA = this.patientOutSA == true ? true : false; request.loginType = this.selectedOption; request.oTPSendType = - type == 1 ? type : 2; //this.selectedOption == 1 ? 1 : 2; + type == 1 ? type : 2; //this.selectedOption == 1 ? 1 : 2; request.zipCode = this.zipCode; request.logInTokenID = this.loginTokenID ?? ""; @@ -665,17 +681,17 @@ class _ConfirmLogin extends State { ? this.registerd_data.patientID : 0; request.patientIdentificationID = request.nationalID = - this.registerd_data.patientIdentificationID != null - ? this.registerd_data.patientIdentificationID - : '0'; + this.registerd_data.patientIdentificationID != null + ? this.registerd_data.patientIdentificationID + : '0'; request.dob = this.registerd_data.dob; request.isRegister = this.registerd_data.isRegister; } else { request.searchType = request.searchType != null ? request.searchType : 2; request.patientID = - this.user!.patientID != null ? this.user!.patientID : 0; + this.user!.patientID != null ? this.user!.patientID : 0; request.nationalID = - request.nationalID != null ? request.nationalID : '0'; + request.nationalID != null ? request.nationalID : '0'; request.patientIdentificationID = request.patientIdentificationID != null ? request.patientIdentificationID : '0'; @@ -699,39 +715,40 @@ class _ConfirmLogin extends State { authService .checkActivationCodeRegister(request, value) - .then((result) => { - res = result, - if (result is Map) - { - result = CheckActivationCode.fromJson( - result as Map), - if (this.registerd_data != null && - this.registerd_data.isRegister == true) - { - // if(widget.isDubai ==false){ - widget.changePageViewIndex!(1), - // if(widget.isDubai ==false){ - - Navigator.popUntil( - context, - (route) => - Utils.route(route, equalsTo: RegisterNew)), - } - } - else - { - // Navigator.of(context).pop(), - GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 1), () { - AppToast.showErrorToast(message: result); - }), - projectViewModel.analytics.loginRegistration - .login_fail(error: result), - projectViewModel.analytics.errorTracking.log( - 'otp_verification_at_confirm_login', - error: result), - } - }) + .then((result) => + { + res = result, + if (result is Map) + { + result = CheckActivationCode.fromJson( + result as Map), + if (this.registerd_data != null && + this.registerd_data.isRegister == true) + { + // if(widget.isDubai ==false){ + widget.changePageViewIndex!(1), + // if(widget.isDubai ==false){ + + Navigator.popUntil( + context, + (route) => + Utils.route(route, equalsTo: RegisterNew)), + } + } + else + { + // Navigator.of(context).pop(), + GifLoaderDialogUtils.hideDialog(context), + Future.delayed(Duration(seconds: 1), () { + AppToast.showErrorToast(message: result); + }), + projectViewModel.analytics.loginRegistration + .login_fail(error: result), + projectViewModel.analytics.errorTracking.log( + 'otp_verification_at_confirm_login', + error: result), + } + }) .catchError((err) { print(err); GifLoaderDialogUtils.hideDialog(context); @@ -743,58 +760,59 @@ class _ConfirmLogin extends State { } else { authService .checkActivationCode(request, value) - .then((result) => { - res = result, - if (result is Map) - { - result = CheckActivationCode.fromJson( - result as Map), - if (this.registerd_data != null && - this.registerd_data.isRegister == true) - { - widget.changePageViewIndex!(1), - Navigator.popUntil( - context, - (route) => - Utils.route(route, equalsTo: RegisterNew)), - } - else - { - sharedPref.remove(FAMILY_FILE), - result.list.isFamily = false, - userData = result.list, - sharedPref.setString( - BLOOD_TYPE, result.patientBloodType ?? "O+"), - //Remove o+ from here Added by Aamir - authenticatedUserObject.user = result.list, - projectViewModel.setPrivilege(privilegeList: res), - sharedPref.setObject(MAIN_USER, result.list), - sharedPref.setObject(USER_PROFILE, result.list), - loginTokenID = result.logInTokenID, - sharedPref.setObject( - LOGIN_TOKEN_ID, result.logInTokenID), - sharedPref.setString( - TOKEN, result.authenticationTokenID), - projectViewModel.analytics.loginRegistration - .login_successful(), - checkIfUserAgreedBefore(result), - } - } - else - { - // Navigator.of(context).pop(), - GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 1), () { - AppToast.showErrorToast(message: result); - startSMSService(tempType); - }), - - projectViewModel.analytics.loginRegistration - .login_fail(error: result), - projectViewModel.analytics.errorTracking - .log('otp_verification_at_confirm_login', error: result) - } - }) + .then((result) => + { + res = result, + if (result is Map) + { + result = CheckActivationCode.fromJson( + result as Map), + if (this.registerd_data != null && + this.registerd_data.isRegister == true) + { + widget.changePageViewIndex!(1), + Navigator.popUntil( + context, + (route) => + Utils.route(route, equalsTo: RegisterNew)), + } + else + { + sharedPref.remove(FAMILY_FILE), + result.list.isFamily = false, + userData = result.list, + sharedPref.setString( + BLOOD_TYPE, result.patientBloodType ?? "O+"), + //Remove o+ from here Added by Aamir + authenticatedUserObject.user = result.list, + projectViewModel.setPrivilege(privilegeList: res), + sharedPref.setObject(MAIN_USER, result.list), + sharedPref.setObject(USER_PROFILE, result.list), + loginTokenID = result.logInTokenID, + sharedPref.setObject( + LOGIN_TOKEN_ID, result.logInTokenID), + sharedPref.setString( + TOKEN, result.authenticationTokenID), + projectViewModel.analytics.loginRegistration + .login_successful(), + checkIfUserAgreedBefore(result), + } + } + else + { + // Navigator.of(context).pop(), + GifLoaderDialogUtils.hideDialog(context), + Future.delayed(Duration(seconds: 1), () { + AppToast.showErrorToast(message: result); + startSMSService(tempType); + }), + + projectViewModel.analytics.loginRegistration + .login_fail(error: result), + projectViewModel.analytics.errorTracking + .log('otp_verification_at_confirm_login', error: result) + } + }) .catchError((err) { GifLoaderDialogUtils.hideDialog(context); Future.delayed(Duration(seconds: 1), () { @@ -888,28 +906,29 @@ class _ConfirmLogin extends State { getToDoCount(); appointmentRateViewModel .getIsLastAppointmentRatedList(projectViewModel.isArabic ? 1 : 2) - .then((value) => { - GifLoaderDialogUtils.hideDialog(AppGlobal.context), - if (appointmentRateViewModel.isHaveAppointmentNotRate) - { - Navigator.pushAndRemoveUntil( - context, - FadePage( - page: RateAppointmentDoctor(), - ), - (r) => false) - } - else - { - Navigator.pushAndRemoveUntil( - context, - FadePage( - page: LandingPage(), - ), - (r) => false) - }, - insertIMEI() - }) + .then((value) => + { + GifLoaderDialogUtils.hideDialog(AppGlobal.context), + if (appointmentRateViewModel.isHaveAppointmentNotRate) + { + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: RateAppointmentDoctor(), + ), + (r) => false) + } + else + { + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: LandingPage(), + ), + (r) => false) + }, + insertIMEI() + }) .catchError((err) { print(err); }); @@ -931,28 +950,27 @@ class _ConfirmLogin extends State { }); } - Widget _loginOptionButton( - String _title, String _icon, int _flag, int? _loginIndex) { + Widget _loginOptionButton(String _title, String _icon, int _flag, int? _loginIndex) { bool isDisable = - (_flag == 3 && !checkIfBiometricAvailable(BiometricType.face) || + (_flag == 3 && !checkIfBiometricAvailable(BiometricType.face) || + _flag == 2 && + !checkIfBiometricAvailable(BiometricType.fingerprint) && _flag == 2 && - !checkIfBiometricAvailable(BiometricType.fingerprint) && - _flag == 2 && - !checkIfBiometricAvailable(BiometricType.strong)); + !checkIfBiometricAvailable(BiometricType.strong)); return InkWell( onTap: isDisable ? null : () { - if (_flag == 0) { - setState(() { - isMoreOption = true; - }); - } else { - authenticateUser(_flag, isActive: _loginIndex); - projectViewModel.analytics.loginRegistration.verify_otp_method( - forRegistration: widget.fromRegistration); - } - }, + if (_flag == 0) { + setState(() { + isMoreOption = true; + }); + } else { + authenticateUser(_flag, isActive: _loginIndex); + projectViewModel.analytics.loginRegistration.verify_otp_method( + forRegistration: widget.fromRegistration); + } + }, child: Container( padding: EdgeInsets.only(left: 20, right: 20, bottom: 15, top: 28), decoration: BoxDecoration( @@ -974,7 +992,9 @@ class _ConfirmLogin extends State { color: isDisable ? Color(0xff2B353E).withOpacity(0.7) : null, ), Text( - TranslationBase.of(context).verifyThrough + " " + _title, + TranslationBase + .of(context) + .verifyThrough + " " + _title, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w600, @@ -994,23 +1014,31 @@ class _ConfirmLogin extends State { Widget getButton(int flag) { switch (flag) { case 4: - return _loginOptionButton(TranslationBase.of(context).verifyWhatsApp, + return _loginOptionButton(TranslationBase + .of(context) + .verifyWhatsApp, 'assets/images/new/verify_whatsapp.svg', flag, null); break; case 1: - return _loginOptionButton(TranslationBase.of(context).verifySMS, + return _loginOptionButton(TranslationBase + .of(context) + .verifySMS, 'assets/images/new/verify_sms.svg', flag, null); break; case 2: return _loginOptionButton( - TranslationBase.of(context).verifyFingerprint, + TranslationBase + .of(context) + .verifyFingerprint, 'assets/images/new/verify_thumb.svg', flag, BiometricType.fingerprint.index); break; case 3: return _loginOptionButton( - TranslationBase.of(context).verifyFaceID, + TranslationBase + .of(context) + .verifyFaceID, 'assets/images/new/verify_face.svg', flag, BiometricType.face.index); @@ -1018,7 +1046,8 @@ class _ConfirmLogin extends State { default: return InkWell( - onTap: () => { + onTap: () => + { setState(() { isMoreOption = true; }) @@ -1041,12 +1070,14 @@ class _ConfirmLogin extends State { ), projectViewModel.isArabic ? SizedBox( - height: 15, - ) + height: 15, + ) : SizedBox( - height: 20, - ), - Texts(TranslationBase.of(context).moreVerification, + height: 20, + ), + Texts(TranslationBase + .of(context) + .moreVerification, fontSize: SizeConfig.textMultiplier! * 1.8, textAlign: TextAlign.center, color: Colors.black) @@ -1061,19 +1092,29 @@ class _ConfirmLogin extends State { getType(type, context) { switch (type) { case 1: - return TranslationBase.of(context).verifySMS; + return TranslationBase + .of(context) + .verifySMS; break; case 2: - return TranslationBase.of(context).verifyFingerprint; + return TranslationBase + .of(context) + .verifyFingerprint; break; case 3: - return TranslationBase.of(context).verifyFaceID; + return TranslationBase + .of(context) + .verifyFaceID; break; case 4: - return TranslationBase.of(context).verifyWhatsApp; + return TranslationBase + .of(context) + .verifyWhatsApp; break; default: - return TranslationBase.of(context).verifySMS; + return TranslationBase + .of(context) + .verifySMS; break; } } diff --git a/pubspec.yaml b/pubspec.yaml index 8dfd227a..1c48b1f5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,7 +51,7 @@ dependencies: pull_to_refresh: ^2.0.0 # Native - local_auth: ^2.1.7 + local_auth: ^2.2.0 localstorage: ^4.0.0+1 maps_launcher: ^2.0.1 url_launcher: ^6.0.15