diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index ef560b92..22bf76fd 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -10,7 +10,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../../widgets/auth/auth_header.dart'; import '../../widgets/auth/login_form.dart'; -DrAppSharedPreferances SharedPref = new DrAppSharedPreferances(); +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); class Loginsreen extends StatefulWidget { @override _LoginsreenState createState() => _LoginsreenState(); @@ -25,7 +25,7 @@ class _LoginsreenState extends State { Future platformImeiFuture; Future getSharedPref() async { - SharedPref.getString('platformImei').then((imei){ + sharedPref.getString('platformImei').then((imei){ platformImei = imei; }); } diff --git a/lib/util/dr_app_toast_msg.dart b/lib/util/dr_app_toast_msg.dart index e0342106..5980e146 100644 --- a/lib/util/dr_app_toast_msg.dart +++ b/lib/util/dr_app_toast_msg.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_flexible_toast/flutter_flexible_toast.dart'; - mixin DrAppToastMsg { + class DrAppToastMsg { void showLongToast(msg) { FlutterFlexibleToast.showToast( message: msg, diff --git a/lib/widgets/auth/known_user_login.dart b/lib/widgets/auth/known_user_login.dart index 97cb4012..881df25c 100644 --- a/lib/widgets/auth/known_user_login.dart +++ b/lib/widgets/auth/known_user_login.dart @@ -2,7 +2,9 @@ import 'dart:collection'; import 'dart:ffi'; 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/services.dart'; @@ -10,7 +12,8 @@ import 'package:hexcolor/hexcolor.dart'; import 'package:local_auth/local_auth.dart'; import 'package:shared_preferences/shared_preferences.dart'; -DrAppSharedPreferances SharedPref = new DrAppSharedPreferances(); +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +DrAppToastMsg toastMsg = DrAppToastMsg(); class KnownUserLogin extends StatefulWidget { @override @@ -25,7 +28,7 @@ class _KnownUserLoginState extends State { Future loggedUserFuture; var loggedUser; Future getSharedPref() async { - SharedPref.getObj('loggedUser').then((userInfo) { + sharedPref.getObj('loggedUser').then((userInfo) { // if(loggedUser == null){} loggedUser = userInfo; // print('dddddddddddddddd${loggedUser}'); @@ -156,14 +159,14 @@ class _KnownUserLoginState extends State { child: Column( children: [ RaisedButton( - onPressed:_authenticate, + onPressed: _silentLogin, elevation: 0.0, child: Container( width: double.infinity, height: 50, child: Center( child: Text( - "Verify using FingerPRint ${_authorized}".toUpperCase(), + "Verify using FingerPRint".toUpperCase(), // textAlign: TextAlign.center, style: TextStyle( color: Colors.white, @@ -210,13 +213,15 @@ class _KnownUserLoginState extends State { Navigator.of(context).pushNamed('routeName'); } - silentLogin() { - _authenticate(); + _silentLogin() { + _authenticate().then((_) { + // print('$val'); + print(_authorized); + }); } - - - Future _authenticate() async { - _getAvailableBiometrics(); + + Future _authenticate() async { + _getAvailableBiometrics(); bool authenticated = false; try { setState(() { @@ -226,7 +231,7 @@ class _KnownUserLoginState extends State { authenticated = await auth.authenticateWithBiometrics( localizedReason: 'Scan your fingerprint to authenticate', useErrorDialogs: true, - stickyAuth: true); + stickyAuth: false); setState(() { _isAuthenticating = false; _authorized = 'Authenticating'; @@ -237,13 +242,17 @@ class _KnownUserLoginState extends State { if (!mounted) return; final String message = authenticated ? 'Authorized' : 'Not Authorized'; + if (message == 'Authorized') { + navigateToHome(); + } setState(() { - print('_authorized'+_authorized); + print('_authorized' + _authorized); _authorized = message; + print('_authorized' + _authorized); }); } - Future _getAvailableBiometrics() async { + Future _getAvailableBiometrics() async { List availableBiometrics; try { availableBiometrics = await auth.getAvailableBiometrics(); @@ -256,4 +265,12 @@ class _KnownUserLoginState extends State { print('availableBiometrics $availableBiometrics'); }); } + + navigateToHome() { + Navigator.of(context).pushNamed(HOME); + } + + showErorrMsg(localMsg) { + toastMsg.showErrorToast(localMsg); + } } diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index ff7a0abd..f746f609 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -12,7 +12,8 @@ import '../../providers/auth_provider.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; -DrAppSharedPreferances SharedPref = DrAppSharedPreferances(); +DrAppSharedPreferances sharedPref = DrAppSharedPreferances(); +DrAppToastMsg toastMsg = DrAppToastMsg(); class LoginForm extends StatefulWidget with DrAppToastMsg { LoginForm({ @@ -309,8 +310,8 @@ class _LoginFormState extends State { } Future setSharedPref(key, value) async { - SharedPref.setString(key, value).then(( success) { - print("SharedPref.setString" + success.toString()); + sharedPref.setString(key, value).then(( success) { + print("sharedPref.setString" + success.toString()); }); } @@ -337,10 +338,10 @@ class _LoginFormState extends State { localMsg = msg.toString(); } - widget.showErrorToast(localMsg); + toastMsg.showErrorToast(localMsg); } saveObjToString(String key, value) async { - SharedPref.setObj(key, value); + sharedPref.setObj(key, value); } }