From 969cdce55ca834bfe3220d93a863541684c0040e Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 26 Mar 2020 16:18:05 +0200 Subject: [PATCH] wait for 2 future --- lib/widgets/auth/known_user_login.dart | 74 ++++++++++++++------------ 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/lib/widgets/auth/known_user_login.dart b/lib/widgets/auth/known_user_login.dart index 1888f7ba..1fd5c4d6 100644 --- a/lib/widgets/auth/known_user_login.dart +++ b/lib/widgets/auth/known_user_login.dart @@ -16,7 +16,6 @@ import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); DrAppToastMsg toastMsg = DrAppToastMsg(); - class KnownUserLogin extends StatefulWidget { @override _KnownUserLoginState createState() => _KnownUserLoginState(); @@ -28,9 +27,10 @@ class _KnownUserLoginState extends State { String _authorized = "not Authorized"; bool _isAuthenticating = false; - Future _loggedUserFuture; + Future _loggedUserFuture; var _loggedUser; - int _loginType; + int _loginType = 1; + Future _loginTypeFuture; Map _loginTypeMap = { 1: { @@ -41,8 +41,14 @@ class _KnownUserLoginState extends State { "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'} + 3: { + "name": "Face", + 'imageUrl': 'assets/images/verification_faceid_lg_icon.png' + }, + 4: { + "name": "WhatsApp", + 'imageUrl': 'assets/images/verification_whatsapp_lg_icon.png' + } }; Future getSharedPref() async { @@ -61,14 +67,13 @@ class _KnownUserLoginState extends State { @override Widget build(BuildContext context) { - getSharedPref(); AuthProvider authProv = Provider.of(context); selectDeviceImei(authProv); - + return FutureBuilder( - future: _loggedUserFuture, - builder: (BuildContext context, AsyncSnapshot snapshot) { + future: Future.wait([_loginTypeFuture,_loggedUserFuture]), + builder: (BuildContext context, AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: return DrAppCircularProgressIndeicator(); @@ -238,20 +243,20 @@ class _KnownUserLoginState extends State { Navigator.of(context).pushNamed('routeName'); } -_authenticate(){ - if(_loginType ==1) { - _authenticateBySMS(); - } - if(_loginType ==2) { - _authenticateByFingerPrint(); - } - if(_loginType ==3) { - _authenticateByFace(); - } - if(_loginType ==4) { - _authenticateByWhatsApp(); + _authenticate() { + if (_loginType == 1) { + _authenticateBySMS(); + } + if (_loginType == 2) { + _authenticateByFingerPrint(); + } + if (_loginType == 3) { + _authenticateByFace(); + } + if (_loginType == 4) { + _authenticateByWhatsApp(); + } } -} Future _authenticateByFingerPrint() async { _getAvailableBiometrics(); @@ -285,16 +290,17 @@ _authenticate(){ }); } -Future _authenticateBySMS(){ - print('_authenticateBySMS'); -} -Future _authenticateByFace(){ - print('_authenticateByFace'); -} -Future _authenticateByWhatsApp(){ - print('_authenticateByWhatsApp'); + Future _authenticateBySMS() { + print('_authenticateBySMS'); + } -} + Future _authenticateByFace() { + print('_authenticateByFace'); + } + + Future _authenticateByWhatsApp() { + print('_authenticateByWhatsApp'); + } Future _getAvailableBiometrics() async { List availableBiometrics; @@ -321,10 +327,10 @@ Future _authenticateByWhatsApp(){ selectDeviceImei(AuthProvider authProv) { sharedPref.getString('platformImei').then((imei) { var imeiModel = {'IMEI': imei}; - authProv.selectDeviceImei(imeiModel).then((res) { + _loginTypeFuture = authProv.selectDeviceImei(imeiModel).then((res) { // setState(() { - _loginType = 4;//res['SELECTDeviceIMEIbyIMEI_List'][0]['LogInType']; - + _loginType = 2; //res['SELECTDeviceIMEIbyIMEI_List'][0]['LogInType']; + // }); print(_loginType.toString()); }).catchError((err) {