|
|
|
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
|
|
|
|
import 'package:diplomaticquarterapp/config/size_config.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/check_paitent_authentication_req.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_request.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/get_mobile_info_response.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/Authentication/send_activation_request.dart';
|
|
|
|
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/card/rounded_container.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
|
|
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:diplomaticquarterapp/routes.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:local_auth/local_auth.dart';
|
|
|
|
|
|
|
|
class ConfirmLogin extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_ConfirmLogin createState() => _ConfirmLogin();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ConfirmLogin extends State<ConfirmLogin> {
|
|
|
|
final LocalAuthentication auth = LocalAuthentication();
|
|
|
|
List<BiometricType> _availableBiometrics;
|
|
|
|
var sharedPref = new AppSharedPreferences();
|
|
|
|
bool authenticated;
|
|
|
|
final authService = new AuthProvider();
|
|
|
|
int mobileNumber;
|
|
|
|
|
|
|
|
var user;
|
|
|
|
|
|
|
|
CheckPatientAuthenticationReq registerd_data;
|
|
|
|
|
|
|
|
var zipCode;
|
|
|
|
|
|
|
|
var patientOutSA;
|
|
|
|
|
|
|
|
var loginTokenID;
|
|
|
|
|
|
|
|
var loginType;
|
|
|
|
|
|
|
|
var deviceToken;
|
|
|
|
|
|
|
|
var lastLogin;
|
|
|
|
|
|
|
|
int selectedOption;
|
|
|
|
|
|
|
|
bool onlySMSBox;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_getAvailableBiometrics();
|
|
|
|
setDefault();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AppScaffold(
|
|
|
|
appBarTitle: TranslationBase.of(context).welcome,
|
|
|
|
isShowAppBar: true,
|
|
|
|
body: Padding(
|
|
|
|
padding: EdgeInsets.all(20),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
flex: 3,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/images/habib-logo.png',
|
|
|
|
height: 80,
|
|
|
|
width: 80,
|
|
|
|
),
|
|
|
|
AppText(
|
|
|
|
TranslationBase.of(context).verifyLoginWith,
|
|
|
|
fontSize: SizeConfig.textMultiplier * 3.5,
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
),
|
|
|
|
])),
|
|
|
|
Expanded(
|
|
|
|
flex: 4,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => {
|
|
|
|
authenticateUser(
|
|
|
|
3, BiometricType.face.index)
|
|
|
|
},
|
|
|
|
child: RoundedContainer(
|
|
|
|
backgroundColor:
|
|
|
|
BiometricType.face.index == 1
|
|
|
|
? Colors.white
|
|
|
|
: Colors.white.withOpacity(.7),
|
|
|
|
borderColor: Colors.grey,
|
|
|
|
showBorder: true,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
20, 10, 20, 10),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/images/login/101.png',
|
|
|
|
height: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
13,
|
|
|
|
width: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
16,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
AppText(
|
|
|
|
TranslationBase.of(context)
|
|
|
|
.verifyFaceID,
|
|
|
|
fontSize:
|
|
|
|
SizeConfig.textMultiplier *
|
|
|
|
2,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)))),
|
|
|
|
Expanded(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => {
|
|
|
|
authenticateUser(2,
|
|
|
|
BiometricType.fingerprint.index)
|
|
|
|
},
|
|
|
|
child: RoundedContainer(
|
|
|
|
backgroundColor:
|
|
|
|
BiometricType.fingerprint.index == 1
|
|
|
|
? Colors.white
|
|
|
|
: Colors.white.withOpacity(.7),
|
|
|
|
borderColor: Colors.grey,
|
|
|
|
showBorder: true,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
25, 10, 25, 10),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/images/login/102.png',
|
|
|
|
height: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
13,
|
|
|
|
width: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
16,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
AppText(
|
|
|
|
TranslationBase.of(context)
|
|
|
|
.verifyFingerprint,
|
|
|
|
fontSize:
|
|
|
|
SizeConfig.textMultiplier *
|
|
|
|
2,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
))))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => {authenticateUser(1, true)},
|
|
|
|
child: RoundedContainer(
|
|
|
|
borderColor: Colors.grey,
|
|
|
|
showBorder: true,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
20, 10, 20, 10),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/images/login/103.png',
|
|
|
|
height: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
13,
|
|
|
|
width: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
16,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
AppText(
|
|
|
|
TranslationBase.of(context)
|
|
|
|
.verifySMS,
|
|
|
|
fontSize:
|
|
|
|
SizeConfig.textMultiplier *
|
|
|
|
2,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)))),
|
|
|
|
Expanded(
|
|
|
|
child: InkWell(
|
|
|
|
onTap: () => {authenticateUser(4, true)},
|
|
|
|
child: RoundedContainer(
|
|
|
|
borderColor: Colors.grey,
|
|
|
|
showBorder: true,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(
|
|
|
|
25, 10, 25, 10),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/images/login/104.png',
|
|
|
|
height: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
13,
|
|
|
|
width: SizeConfig
|
|
|
|
.imageSizeMultiplier *
|
|
|
|
16,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
AppText(
|
|
|
|
TranslationBase.of(context)
|
|
|
|
.verifyWhatsApp,
|
|
|
|
fontSize:
|
|
|
|
SizeConfig.textMultiplier *
|
|
|
|
2,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
))))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: <Widget>[
|
|
|
|
// Row(
|
|
|
|
// children: <Widget>[
|
|
|
|
// Expanded(
|
|
|
|
// child: RaisedButton(
|
|
|
|
// color: Colors.grey,
|
|
|
|
// textColor: Colors.white,
|
|
|
|
// child:
|
|
|
|
// Text(TranslationBase.of(context).registerNow),
|
|
|
|
// onPressed: () => {
|
|
|
|
// Navigator.of(context).pushNamed(
|
|
|
|
// REGISTER,
|
|
|
|
// )
|
|
|
|
// },
|
|
|
|
// ))
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
],
|
|
|
|
))
|
|
|
|
],
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _getAvailableBiometrics() async {
|
|
|
|
List<BiometricType> availableBiometrics;
|
|
|
|
try {
|
|
|
|
availableBiometrics = await auth.getAvailableBiometrics();
|
|
|
|
} on PlatformException catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_availableBiometrics = availableBiometrics;
|
|
|
|
print(_availableBiometrics);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticateUser(type, isActive) {
|
|
|
|
this.selectedOption =
|
|
|
|
type; //this.selectedOption && !this.onlySMSBox ? this.selectedOption : this.fingrePrintBefore ? this.fingrePrintBefore : el.value;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 1:
|
|
|
|
this.loginWithSMS(type, isActive);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this.loginWithFingurePrintFace(type, isActive);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
this.loginWithFingurePrintFace(type, isActive);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
this.loginWithWhatsapp(type, isActive);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sharedPref.setInt(LAST_LOGIN,
|
|
|
|
type); //this.cs.sharedService.setStorage(this.selectedOption, AuthenticationService.LAST_LOGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
loginWithSMS(type, isActive) {}
|
|
|
|
loginWithFingurePrintFace(type, isActive) async {
|
|
|
|
if (isActive == 1) {
|
|
|
|
// this.startBiometricLoginIfAvailable();
|
|
|
|
authenticated = await auth.authenticateWithBiometrics(
|
|
|
|
localizedReason: 'Scan your fingerprint to authenticate',
|
|
|
|
useErrorDialogs: true,
|
|
|
|
stickyAuth: true);
|
|
|
|
print(authenticated);
|
|
|
|
if (authenticated == true) {
|
|
|
|
var request = this.getCommonRequest();
|
|
|
|
this.getMobileInfo(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loginWithWhatsapp(type, isActive) {}
|
|
|
|
getMobileInfo(request) {
|
|
|
|
this
|
|
|
|
.authService
|
|
|
|
.getLoginInfo(request)
|
|
|
|
.then((GetMobileLoginInfoResponse result) => {
|
|
|
|
if (!result.sMSLoginRequired)
|
|
|
|
{
|
|
|
|
this.loginTokenID = result.logInTokenID,
|
|
|
|
this.patientOutSA = result.patientOutSA,
|
|
|
|
// sms for register the biometric
|
|
|
|
if (result.isSMSSent)
|
|
|
|
{
|
|
|
|
this.onlySMSBox = false,
|
|
|
|
//this.button();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//this.checkActivationCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (result.isAuthenticated)
|
|
|
|
{
|
|
|
|
// this.onlySMSBox = false;
|
|
|
|
// this.cs.sharedService.setSharedData(true, AuthenticationService.ONLY_SMS);
|
|
|
|
// this.cs.sharedService.setSharedData(this.selectedOption, AuthenticationService.FINGUREPRINT_BEFORE);
|
|
|
|
// this.cs.confirmLogin();
|
|
|
|
// this.button();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this.cs.presentAlert(result.ErrorEndUserMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setDefault() async {
|
|
|
|
// this.user = this.cs.sharedService.getSharedData(
|
|
|
|
// AuthenticationService.IMEI_USER_DATA,
|
|
|
|
// false
|
|
|
|
// );
|
|
|
|
this.registerd_data = await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN);
|
|
|
|
this.mobileNumber = this.registerd_data != null
|
|
|
|
? this.registerd_data.patientMobileNumber
|
|
|
|
: int.parse(this.user.Mobile);
|
|
|
|
this.zipCode = this.registerd_data != null
|
|
|
|
? this.registerd_data.zipCode
|
|
|
|
: this.user.OutSA ? "971" : "966";
|
|
|
|
this.patientOutSA = this.registerd_data != null
|
|
|
|
? this.registerd_data.zipCode == "966" ? 0 : 1
|
|
|
|
: this.user.OutSA;
|
|
|
|
if (this.registerd_data != null) {
|
|
|
|
this.loginTokenID = sharedPref.getString(LOGIN_TOKEN_ID);
|
|
|
|
this.loginType = this.registerd_data.searchType;
|
|
|
|
}
|
|
|
|
this.deviceToken = sharedPref.getString(PUSH_TOKEN);
|
|
|
|
this.lastLogin = sharedPref.getInt(
|
|
|
|
LAST_LOGIN); //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCommonRequest() {
|
|
|
|
var request = SendActivationRequest();
|
|
|
|
request.patientMobileNumber = this.mobileNumber;
|
|
|
|
request.mobileNo = '0' + this.mobileNumber.toString();
|
|
|
|
request.deviceToken = this.deviceToken;
|
|
|
|
request.projectOutSA = this.patientOutSA;
|
|
|
|
request.loginType = this.selectedOption;
|
|
|
|
request.zipCode = this.zipCode;
|
|
|
|
request.isRegister = false;
|
|
|
|
request.logInTokenID = this.loginTokenID ?? "";
|
|
|
|
if (this.registerd_data != null) {
|
|
|
|
request.searchType = this.registerd_data.searchType == 1
|
|
|
|
? this.registerd_data.searchType
|
|
|
|
: 1;
|
|
|
|
request.patientID = this.registerd_data.patientID != 0
|
|
|
|
? this.registerd_data.patientID
|
|
|
|
: 0;
|
|
|
|
request.patientIdentificationID =
|
|
|
|
request.nationalID = this.registerd_data.patientIdentificationID;
|
|
|
|
} else {
|
|
|
|
request.searchType = request.searchType == 1 ? request.searchType : 2;
|
|
|
|
request.patientID = int.parse(this.user.PatientID);
|
|
|
|
request.patientID = request.nationalID =
|
|
|
|
request.nationalID != null ? request.nationalID : 0;
|
|
|
|
}
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
}
|