implement basic verifecation type

merge-requests/1/merge
Elham Rababah 6 years ago
parent 5bdae16684
commit cfa0162109

@ -9,7 +9,7 @@ const LOGIN_URL =
'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New'; 'https://hmgwebservices.com/Services/Sentry.svc/REST/MemberLogIN_New';
const INSERT_DEVICE_IMEI = const INSERT_DEVICE_IMEI =
'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI'; 'https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_INSERTDeviceIMEI';
const SELECT_DEVICE_IMEI ='https://hmgwebservices.com/Services/Sentry.svc/REST/DoctorApplication_SELECTDeviceIMEIbyIMEI';
class AuthProvider with ChangeNotifier { class AuthProvider with ChangeNotifier {
Future<Map> login(UserModel userInfo) async { Future<Map> login(UserModel userInfo) async {
Map<String, String> requestHeaders = { Map<String, String> requestHeaders = {
@ -54,4 +54,21 @@ class AuthProvider with ChangeNotifier {
throw error; throw error;
} }
} }
Future<Map> selectDeviceImei(imei) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
const url = SELECT_DEVICE_IMEI;
try {
final response = await http.post(url,
headers: requestHeaders, body: json.encode(imei));
return Future.value(json.decode(response.body));
} catch (error) {
print(error);
throw error;
}
}
} }

@ -1,20 +1,22 @@
import 'dart:collection'; import 'package:doctor_app_flutter/lookups/auth_lookup.dart';
import 'dart:ffi'; import 'package:doctor_app_flutter/providers/auth_provider.dart';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:local_auth/local_auth.dart'; import 'package:local_auth/local_auth.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../config/config.dart';
import '../../routes.dart';
import '../../util/dr_app_shared_pref.dart';
import '../../util/dr_app_toast_msg.dart';
import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart';
DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
DrAppToastMsg toastMsg = DrAppToastMsg(); DrAppToastMsg toastMsg = DrAppToastMsg();
class KnownUserLogin extends StatefulWidget { class KnownUserLogin extends StatefulWidget {
@override @override
_KnownUserLoginState createState() => _KnownUserLoginState(); _KnownUserLoginState createState() => _KnownUserLoginState();
@ -23,32 +25,49 @@ class KnownUserLogin extends StatefulWidget {
class _KnownUserLoginState extends State<KnownUserLogin> { class _KnownUserLoginState extends State<KnownUserLogin> {
Future<SharedPreferences> _prefs = SharedPreferences.getInstance(); Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final LocalAuthentication auth = LocalAuthentication(); final LocalAuthentication auth = LocalAuthentication();
String _authorized = "not Authorized"; String _authorized = "not Authorized";
bool _isAuthenticating = false; bool _isAuthenticating = false;
Future<String> loggedUserFuture; Future<String> _loggedUserFuture;
var loggedUser; var _loggedUser;
int _loginType;
Map _loginTypeMap = {
1: {
"name": "SMS",
'imageUrl': 'assets/images/verification_sms_lg_icon.png',
},
2: {
"name": "FingerPrint",
'imageUrl': 'assets/images/verification_fingerprint_lg_icon.png'
},
3: {"name": "Face", 'imageUrl': 'assets/images/verification_faceid_lg_icon.png'},
4: {"name": "WhatsApp", 'imageUrl': 'assets/images/verification_whatsapp_lg_icon.png'}
};
Future<void> getSharedPref() async { Future<void> getSharedPref() async {
sharedPref.getObj('loggedUser').then((userInfo) { sharedPref.getObj('loggedUser').then((userInfo) {
// if(loggedUser == null){} _loggedUser = userInfo;
loggedUser = userInfo;
// print('dddddddddddddddd${loggedUser}');
}); });
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
loggedUserFuture = _prefs.then((SharedPreferences prefs) { _loggedUserFuture = _prefs.then((SharedPreferences prefs) {
return (prefs.getString('platformImei')); return (prefs.getString('platformImei'));
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
getSharedPref(); getSharedPref();
AuthProvider authProv = Provider.of<AuthProvider>(context);
selectDeviceImei(authProv);
return FutureBuilder( return FutureBuilder(
future: loggedUserFuture, future: _loggedUserFuture,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
switch (snapshot.connectionState) { switch (snapshot.connectionState) {
case ConnectionState.waiting: case ConnectionState.waiting:
@ -99,7 +118,7 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text( Text(
loggedUser['List_MemberInformation'][0] _loggedUser['List_MemberInformation'][0]
['MemberName'], ['MemberName'],
style: TextStyle( style: TextStyle(
color: Hexcolor('515A5D'), color: Hexcolor('515A5D'),
@ -130,15 +149,7 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
fit: BoxFit.cover, fit: BoxFit.cover,
)) ))
]), ]),
Container( buildVerificationTypeImageContainer(),
height: 200,
width: 200,
child: Center(
child: Image.asset(
'assets/images/verification_fingerprint_lg_icon.png',
fit: BoxFit.cover,
),
)),
buildButtonsContainer( buildButtonsContainer(
isSmallScreen, constraints, context) isSmallScreen, constraints, context)
], ],
@ -150,6 +161,19 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
}); });
} }
Container buildVerificationTypeImageContainer() {
print('${_loginTypeMap[_loginType]}');
return Container(
height: 200,
width: 200,
child: Center(
child: Image.asset(
_loginTypeMap[_loginType]['imageUrl'],
fit: BoxFit.cover,
),
));
}
// //
Container buildButtonsContainer( Container buildButtonsContainer(
bool isSmallScreen, BoxConstraints constraints, BuildContext context) { bool isSmallScreen, BoxConstraints constraints, BuildContext context) {
@ -159,14 +183,15 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
RaisedButton( RaisedButton(
onPressed: _silentLogin, onPressed: _authenticate,
elevation: 0.0, elevation: 0.0,
child: Container( child: Container(
width: double.infinity, width: double.infinity,
height: 50, height: 50,
child: Center( child: Center(
child: Text( child: Text(
"Verify using FingerPRint".toUpperCase(), "Verify using ${_loginTypeMap[_loginType]['name']}"
.toUpperCase(),
// textAlign: TextAlign.center, // textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
@ -213,14 +238,22 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
Navigator.of(context).pushNamed('routeName'); Navigator.of(context).pushNamed('routeName');
} }
_silentLogin() { _authenticate(){
_authenticate().then((_) { if(_loginType ==1) {
// print('$val'); _authenticateBySMS();
print(_authorized);
});
} }
if(_loginType ==2) {
_authenticateByFingerPrint();
}
if(_loginType ==3) {
_authenticateByFace();
}
if(_loginType ==4) {
_authenticateByWhatsApp();
}
}
Future<void> _authenticate() async { Future<void> _authenticateByFingerPrint() async {
_getAvailableBiometrics(); _getAvailableBiometrics();
bool authenticated = false; bool authenticated = false;
try { try {
@ -252,6 +285,17 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
}); });
} }
Future<void> _authenticateBySMS(){
print('_authenticateBySMS');
}
Future<void> _authenticateByFace(){
print('_authenticateByFace');
}
Future<void> _authenticateByWhatsApp(){
print('_authenticateByWhatsApp');
}
Future<void> _getAvailableBiometrics() async { Future<void> _getAvailableBiometrics() async {
List<BiometricType> availableBiometrics; List<BiometricType> availableBiometrics;
try { try {
@ -273,4 +317,19 @@ class _KnownUserLoginState extends State<KnownUserLogin> {
showErorrMsg(localMsg) { showErorrMsg(localMsg) {
toastMsg.showErrorToast(localMsg); toastMsg.showErrorToast(localMsg);
} }
selectDeviceImei(AuthProvider authProv) {
sharedPref.getString('platformImei').then((imei) {
var imeiModel = {'IMEI': imei};
authProv.selectDeviceImei(imeiModel).then((res) {
// setState(() {
_loginType = 4;//res['SELECTDeviceIMEIbyIMEI_List'][0]['LogInType'];
// });
print(_loginType.toString());
}).catchError((err) {
print('${err}');
});
});
}
} }

@ -63,6 +63,9 @@ flutter:
- assets/images/login_btn_arrow_icon.png - assets/images/login_btn_arrow_icon.png
- assets/images/dr_avatar.png - assets/images/dr_avatar.png
- assets/images/verification_fingerprint_lg_icon.png - assets/images/verification_fingerprint_lg_icon.png
- assets/images/verification_faceid_lg_icon.png
- assets/images/verification_sms_lg_icon.png
- assets/images/verification_whatsapp_lg_icon.png
- assets/images/close_icon.png - assets/images/close_icon.png
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg

Loading…
Cancel
Save