@ -13,6 +13,7 @@ import 'package:mohem_flutter_app/classes/consts.dart';
import ' package:mohem_flutter_app/classes/utils.dart ' ;
import ' package:mohem_flutter_app/classes/utils.dart ' ;
import ' package:mohem_flutter_app/config/routes.dart ' ;
import ' package:mohem_flutter_app/config/routes.dart ' ;
import ' package:mohem_flutter_app/dialogs/otp_dialog.dart ' ;
import ' package:mohem_flutter_app/dialogs/otp_dialog.dart ' ;
import ' package:mohem_flutter_app/extensions/int_extensions.dart ' ;
import ' package:mohem_flutter_app/extensions/string_extensions.dart ' ;
import ' package:mohem_flutter_app/extensions/string_extensions.dart ' ;
import ' package:mohem_flutter_app/generated/locale_keys.g.dart ' ;
import ' package:mohem_flutter_app/generated/locale_keys.g.dart ' ;
import ' package:mohem_flutter_app/models/basic_member_information_model.dart ' ;
import ' package:mohem_flutter_app/models/basic_member_information_model.dart ' ;
@ -20,6 +21,11 @@ import 'package:mohem_flutter_app/models/generic_response_model.dart';
import ' package:mohem_flutter_app/models/member_information_list_model.dart ' ;
import ' package:mohem_flutter_app/models/member_information_list_model.dart ' ;
import ' package:mohem_flutter_app/models/privilege_list_model.dart ' ;
import ' package:mohem_flutter_app/models/privilege_list_model.dart ' ;
/ / WhatsApp 4
/ / SMS 1
/ / Face ID 3
/ / Finger Print 2
class VerifyLoginScreen extends StatefulWidget {
class VerifyLoginScreen extends StatefulWidget {
VerifyLoginScreen ( { Key ? key } ) : super ( key: key ) ;
VerifyLoginScreen ( { Key ? key } ) : super ( key: key ) ;
@ -35,6 +41,10 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
String ? firebaseToken ;
String ? firebaseToken ;
/ / For face and finger print verification
int selectedFlag = 0 ;
bool isNeedVerifyWithFaceIDAndBiometrics = false ;
@ override
@ override
void initState ( ) {
void initState ( ) {
_getAvailableBiometrics ( ) ;
_getAvailableBiometrics ( ) ;
@ -59,15 +69,16 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
physics: const BouncingScrollPhysics ( ) ,
physics: const BouncingScrollPhysics ( ) ,
children: [
children: [
LocaleKeys . pleaseVerify . tr ( ) . toText16 ( ) ,
LocaleKeys . pleaseVerify . tr ( ) . toText16 ( ) ,
if ( isNeedVerifyWithFaceIDAndBiometrics ) LocaleKeys . pleaseVerifyForBio . tr ( ) . toText12 ( ) ,
GridView (
GridView (
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount ( crossAxisCount: 2 , crossAxisSpacing: 13 , mainAxisSpacing: 9 ) ,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount ( crossAxisCount: 2 , crossAxisSpacing: 13 , mainAxisSpacing: 9 ) ,
physics: const NeverScrollableScrollPhysics ( ) ,
physics: const NeverScrollableScrollPhysics ( ) ,
padding: const EdgeInsets . only ( top: 9 ) ,
padding: const EdgeInsets . only ( top: 9 ) ,
shrinkWrap: true ,
shrinkWrap: true ,
children: [
children: [
getButton ( 3 ) ,
if ( ! isNeedVerifyWithFaceIDAndBiometrics ) getButton ( 3 ) ,
if ( ! isNeedVerifyWithFaceIDAndBiometrics ) getButton ( 2 ) ,
getButton ( 4 ) ,
getButton ( 4 ) ,
getButton ( 2 ) ,
getButton ( 1 ) ,
getButton ( 1 ) ,
] ,
] ,
)
)
@ -500,6 +511,7 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
/ / }
/ / }
/ /
/ /
Future < bool > loginWithFaceIDAndBiometrics ( ) async {
Future < bool > loginWithFaceIDAndBiometrics ( ) async {
IOSAuthMessages iosStrings =
IOSAuthMessages iosStrings =
const IOSAuthMessages ( cancelButton: ' cancel ' , goToSettingsButton: ' settings ' , goToSettingsDescription: ' Please set up your Touch ID. ' , lockOut: ' Please reenable your Touch ID ' ) ;
const IOSAuthMessages ( cancelButton: ' cancel ' , goToSettingsButton: ' settings ' , goToSettingsDescription: ' Please set up your Touch ID. ' , lockOut: ' Please reenable your Touch ID ' ) ;
@ -525,69 +537,22 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
/ / isMoreOption = true ;
/ / isMoreOption = true ;
} ) ;
} ) ;
} else {
} else {
try {
if ( _flag = = 2 | | _flag = = 3 ) {
Utils . showLoading ( context ) ;
bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics ( ) ;
if ( _flag = = 4 | | _flag = = 3 ) {
if ( ! authenticateWithFaceAndTouchID ) {
bool authenticateWithFaceAndTouchID = await loginWithFaceIDAndBiometrics ( ) ;
return ;
if ( ! authenticateWithFaceAndTouchID ) {
} else {
isNeedVerifyWithFaceIDAndBiometrics = true ;
selectedFlag = _flag ;
setState ( ( ) {
return ;
return ;
}
} ) ;
}
}
await LoginApiClient ( ) . checkMobileAppVersion ( ) ;
} else {
await LoginApiClient ( ) . memberLogin ( AppState ( ) . getUserName ! , AppState ( ) . password ! ) ;
if ( isNeedVerifyWithFaceIDAndBiometrics )
BasicMemberInformationModel ? memberInformationModel = await LoginApiClient ( ) . mohemmSendActivationCodeByOTPNotificationType (
performApiCall ( _title , _icon , selectedFlag ) ;
checkBiometricIsAvailable ( BiometricType . fingerprint ) ? 1 : 0 , AppState ( ) . memberLoginList ? . pMOBILENUMBER , _flag , AppState ( ) . getUserName ) ;
else
Utils . hideLoading ( context ) ;
performApiCall ( _title , _icon , _flag ) ;
OtpDialog (
context ,
_flag ,
int . tryParse ( AppState ( ) . memberLoginList ? . pMOBILENUMBER ? ? " " ) ,
( value ) async {
Utils . showLoading ( context ) ;
try {
GenericResponseModel ? genericResponseModel = await LoginApiClient ( ) . checkActivationCode ( true , AppState ( ) . memberLoginList ? . pMOBILENUMBER , value , AppState ( ) . getUserName ) ;
GenericResponseModel ? genericResponseModel1 = await LoginApiClient ( ) . insertMobileLoginInfoNEW (
AppState ( ) . memberLoginList ? . pEMAILADDRESS ? ? " " ,
genericResponseModel ? . pSESSIONID ? ? 0 ,
genericResponseModel ? . memberInformationList ! [ 0 ] . eMPLOYEENAME ? ? " " ,
_flag ,
AppState ( ) . memberLoginList ? . pMOBILENUMBER ? ? " " ,
AppState ( ) . getUserName ! ,
firebaseToken ! ,
Platform . isAndroid ? " android " : " ios " ) ;
if ( genericResponseModel ? . errorMessage ! = null ) {
Utils . showToast ( genericResponseModel ? . errorMessage ? ? " " ) ;
} else {
AppState ( ) . setPrivilegeListModel = genericResponseModel ! . privilegeList ? ? [ ] ;
AppState ( ) . setMemberInformationListModel = genericResponseModel . memberInformationList ? . first ;
MemberInformationListModel . saveToPrefs ( genericResponseModel . memberInformationList ? ? [ ] ) ;
genericResponseModel . privilegeList ! . forEach ( ( element ) {
print ( element . serviceName . toString ( ) + " " + element . previlege . toString ( ) ) ; / / Check availability
} ) ;
PrivilegeListModel . saveToPrefs ( genericResponseModel . privilegeList ? ? [ ] ) ;
AppState ( ) . setMohemmWifiSSID = genericResponseModel . mohemmWifiSSID ;
AppState ( ) . setMohemmWifiPassword = genericResponseModel . mohemmWifiPassword ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . username , AppState ( ) . getUserName ! ) ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . password , AppState ( ) . password ! ) ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . mohemmWifiSSID , genericResponseModel . mohemmWifiSSID ! ) ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . mohemmWifiPassword , genericResponseModel . mohemmWifiPassword ! ) ;
}
Utils . hideLoading ( context ) ;
Navigator . pop ( context ) ;
Navigator . pushNamedAndRemoveUntil ( context , AppRoutes . dashboard , ( Route < dynamic > route ) = > false ) ;
} catch ( ex ) {
print ( ex ) ;
Utils . hideLoading ( context ) ;
Utils . handleException ( ex , context , null ) ;
}
} ,
( ) = > {
Navigator . pop ( context ) ,
} ,
) . displayDialog ( context ) ;
} catch ( ex ) {
Utils . hideLoading ( context ) ;
Utils . handleException ( ex , context , null ) ;
}
}
}
}
} ,
} ,
@ -617,14 +582,14 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
Widget getButton ( int flag ) {
Widget getButton ( int flag ) {
switch ( flag ) {
switch ( flag ) {
case 2 :
return _loginOptionButton ( LocaleKeys . verifyThroughWhatsapp . tr ( ) , ' assets/images/login/verify_whatsapp.svg ' , flag , null ) ;
case 1 :
case 1 :
return _loginOptionButton ( LocaleKeys . verifyThroughSMS . tr ( ) , ' assets/images/login/verify_sms.svg ' , flag , null ) ;
return _loginOptionButton ( LocaleKeys . verifyThroughSMS . tr ( ) , ' assets/images/login/verify_sms.svg ' , flag , null ) ;
case 4 :
case 2 :
return _loginOptionButton ( LocaleKeys . verifyThroughFingerprint . tr ( ) , ' assets/images/login/verify_thumb.svg ' , flag , BiometricType . fingerprint . index ) ;
return _loginOptionButton ( LocaleKeys . verifyThroughFingerprint . tr ( ) , ' assets/images/login/verify_thumb.svg ' , flag , BiometricType . fingerprint . index ) ;
case 3 :
case 3 :
return _loginOptionButton ( LocaleKeys . verifyThroughFace . tr ( ) , ' assets/images/login/verify_face.svg ' , flag , BiometricType . face . index ) ;
return _loginOptionButton ( LocaleKeys . verifyThroughFace . tr ( ) , ' assets/images/login/verify_face.svg ' , flag , BiometricType . face . index ) ;
case 4 :
return _loginOptionButton ( LocaleKeys . verifyThroughWhatsapp . tr ( ) , ' assets/images/login/verify_whatsapp.svg ' , flag , null ) ;
default :
default :
return const SizedBox ( ) ;
return const SizedBox ( ) ;
}
}
@ -640,6 +605,67 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
}
}
return isAvailable ;
return isAvailable ;
}
}
Future < void > performApiCall ( String _title , String _icon , int _flag ) async {
try {
Utils . showLoading ( context ) ;
await LoginApiClient ( ) . checkMobileAppVersion ( ) ;
await LoginApiClient ( ) . memberLogin ( AppState ( ) . getUserName ! , AppState ( ) . password ! ) ;
BasicMemberInformationModel ? memberInformationModel = await LoginApiClient ( )
. mohemmSendActivationCodeByOTPNotificationType ( checkBiometricIsAvailable ( BiometricType . fingerprint ) ? 1 : 0 , AppState ( ) . memberLoginList ? . pMOBILENUMBER , _flag , AppState ( ) . getUserName ) ;
Utils . hideLoading ( context ) ;
OtpDialog (
context ,
_flag ,
int . tryParse ( AppState ( ) . memberLoginList ? . pMOBILENUMBER ? ? " " ) ,
( value ) async {
Utils . showLoading ( context ) ;
try {
GenericResponseModel ? genericResponseModel = await LoginApiClient ( ) . checkActivationCode ( true , AppState ( ) . memberLoginList ? . pMOBILENUMBER , value , AppState ( ) . getUserName ) ;
GenericResponseModel ? genericResponseModel1 = await LoginApiClient ( ) . insertMobileLoginInfoNEW (
AppState ( ) . memberLoginList ? . pEMAILADDRESS ? ? " " ,
genericResponseModel ? . pSESSIONID ? ? 0 ,
genericResponseModel ? . memberInformationList ! [ 0 ] . eMPLOYEENAME ? ? " " ,
_flag ,
AppState ( ) . memberLoginList ? . pMOBILENUMBER ? ? " " ,
AppState ( ) . getUserName ! ,
firebaseToken ! ,
Platform . isAndroid ? " android " : " ios " ) ;
if ( genericResponseModel ? . errorMessage ! = null ) {
Utils . showToast ( genericResponseModel ? . errorMessage ? ? " " ) ;
} else {
AppState ( ) . setPrivilegeListModel = genericResponseModel ! . privilegeList ? ? [ ] ;
AppState ( ) . setMemberInformationListModel = genericResponseModel . memberInformationList ? . first ;
MemberInformationListModel . saveToPrefs ( genericResponseModel . memberInformationList ? ? [ ] ) ;
genericResponseModel . privilegeList ! . forEach ( ( element ) {
print ( element . serviceName . toString ( ) + " " + element . previlege . toString ( ) ) ; / / Check availability
} ) ;
PrivilegeListModel . saveToPrefs ( genericResponseModel . privilegeList ? ? [ ] ) ;
AppState ( ) . setMohemmWifiSSID = genericResponseModel . mohemmWifiSSID ;
AppState ( ) . setMohemmWifiPassword = genericResponseModel . mohemmWifiPassword ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . username , AppState ( ) . getUserName ! ) ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . password , AppState ( ) . password ! ) ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . mohemmWifiSSID , genericResponseModel . mohemmWifiSSID ! ) ;
Utils . saveStringFromPrefs ( SharedPrefsConsts . mohemmWifiPassword , genericResponseModel . mohemmWifiPassword ! ) ;
}
Utils . hideLoading ( context ) ;
Navigator . pop ( context ) ;
Navigator . pushNamedAndRemoveUntil ( context , AppRoutes . dashboard , ( Route < dynamic > route ) = > false ) ;
} catch ( ex ) {
print ( ex ) ;
Utils . hideLoading ( context ) ;
Utils . handleException ( ex , context , null ) ;
}
} ,
( ) = > {
Navigator . pop ( context ) ,
} ,
) . displayDialog ( context ) ;
} catch ( ex ) {
Utils . hideLoading ( context ) ;
Utils . handleException ( ex , context , null ) ;
}
}
/ /
/ /
/ / formatDate ( date ) {
/ / formatDate ( date ) {
/ / return date ;
/ / return date ;