diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 1fb6de2d..3a3e2b9b 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -104,7 +104,7 @@ class BaseAppClient { if (body['OTP_SendType'] != null) { onFailure(getError(parsed), statusCode); } else if (!isAllowAny) { - await Provider.of(AppGlobal.CONTEX, listen: false).logout(isSessionTimeout: true); + await Provider.of(AppGlobal.CONTEX, listen: false).logout(); Helpers.showErrorToast('Your session expired Please login again'); } if (isAllowAny) { diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index f033d4f7..49e89881 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -127,6 +127,7 @@ class AuthenticationService extends BaseService { Future insertDeviceImei(InsertIMEIDetailsModel insertIMEIDetailsModel)async { hasError = false; + // insertIMEIDetailsModel.tokenID = "@dm!n"; _insertDeviceImeiRes = {}; try { await baseAppClient.post(INSERT_DEVICE_IMEI, diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 223b303b..232d9619 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -72,6 +72,8 @@ class AuthenticationViewModel extends BaseViewModel { bool isLogin = false; bool unverified = false; + bool isFromLogin = false; + APP_STATUS app_status = APP_STATUS.LOADING; AuthenticationViewModel({bool checkDeviceInfo = false}) { getDeviceInfoFromFirebase(); @@ -386,27 +388,41 @@ class AuthenticationViewModel extends BaseViewModel { /// determine the status of the app APP_STATUS get status { if (state == ViewState.Busy) { - return APP_STATUS.LOADING; + app_status = APP_STATUS.LOADING; } else { - if (this.unverified) { - return APP_STATUS.UNVERIFIED; + if(this.doctorProfile !=null) + app_status = APP_STATUS.AUTHENTICATED; + else if (this.unverified) { + app_status = APP_STATUS.UNVERIFIED; } else if (this.isLogin) { - return APP_STATUS.AUTHENTICATED; + app_status = APP_STATUS.AUTHENTICATED; } else { - return APP_STATUS.UNAUTHENTICATED; + app_status = APP_STATUS.UNAUTHENTICATED; } } + return app_status; + } + setAppStatus(APP_STATUS status){ + this.app_status = status; + notifyListeners(); + } + + setUnverified(bool unverified,{bool isFromLogin = false}){ + this.unverified = unverified; + this.isFromLogin = isFromLogin; + notifyListeners(); } /// logout function - logout({bool isSessionTimeout = false}) async { + logout({bool isFromLogin = false}) async { DEVICE_TOKEN = ""; String lang = await sharedPref.getString(APP_Language); await Helpers.clearSharedPref(); + doctorProfile = null; sharedPref.setString(APP_Language, lang); deleteUser(); - if(isSessionTimeout) await getDeviceInfoFromFirebase(); + this.isFromLogin = isFromLogin; Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( @@ -419,7 +435,7 @@ class AuthenticationViewModel extends BaseViewModel { user = null; unverified = false; isLogin = false; - notifyListeners(); + // notifyListeners(); } } diff --git a/lib/core/viewModel/base_view_model.dart b/lib/core/viewModel/base_view_model.dart index fe4dbd22..9d4fe36d 100644 --- a/lib/core/viewModel/base_view_model.dart +++ b/lib/core/viewModel/base_view_model.dart @@ -47,8 +47,8 @@ class BaseViewModel extends ChangeNotifier { } } - setDoctorProfile(DoctorProfileModel doctorProfile){ - sharedPref.setObj(DOCTOR_PROFILE, doctorProfile); - doctorProfile = doctorProfile; + setDoctorProfile(DoctorProfileModel doctorProfile)async { + await sharedPref.setObj(DOCTOR_PROFILE, doctorProfile); + this.doctorProfile = doctorProfile; } } diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index f3f03fe8..9563b29c 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -259,15 +259,16 @@ class _LoginScreenState extends State { Helpers.showErrorToast(authenticationViewModel.error); } else { GifLoaderDialogUtils.hideDialog(context); - - Navigator.of(context).pushReplacement( - MaterialPageRoute( - builder: (BuildContext context) => - VerificationMethodsScreen( - password: authenticationViewModel.userInfo.password, - ), - ), - ); + authenticationViewModel.setUnverified(true,isFromLogin: true); + // Navigator.of(context).pushReplacement( + // MaterialPageRoute( + // builder: (BuildContext context) => + // VerificationMethodsScreen( + // password: authenticationViewModel.userInfo.password, + // isFromLogin: true, + // ), + // ), + // ); } } } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 0ec7f5ee..8257ebf0 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -13,6 +13,7 @@ import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/buttons/secondary_button.dart'; import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; @@ -32,10 +33,13 @@ DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); class VerificationMethodsScreen extends StatefulWidget { - VerificationMethodsScreen({this.password}); + final password; + + VerificationMethodsScreen({this.password, }); + @override _VerificationMethodsScreenState createState() => _VerificationMethodsScreenState(); } @@ -72,9 +76,11 @@ class _VerificationMethodsScreenState extends State { SizedBox( height: 80, ), + if(authenticationViewModel.isFromLogin) InkWell( onTap: (){ - Navigator.of(context).pop(); + authenticationViewModel.setUnverified(false,isFromLogin: false); + authenticationViewModel.setAppStatus(APP_STATUS.UNAUTHENTICATED); }, child: Icon(Icons.arrow_back_ios,color: Color(0xFF2B353E),) @@ -392,20 +398,21 @@ class _VerificationMethodsScreenState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.end, children: [ - AppButton( - title: TranslationBase + SecondaryButton( + label: TranslationBase .of(context) .useAnotherAccount, - color: Color(0xFFD02127),fontWeight: FontWeight.w700, - onPressed: () { + color: Color(0xFFD02127), + //fontWeight: FontWeight.w700, + onTap: () { authenticationViewModel.deleteUser(); - - Navigator.pushAndRemoveUntil( - AppGlobal.CONTEX, - FadePage( - page: RootPage(), - ), - (r) => false); + authenticationViewModel.setAppStatus(APP_STATUS.UNAUTHENTICATED); + // Navigator.pushAndRemoveUntil( + // AppGlobal.CONTEX, + // FadePage( + // page: RootPage(), + // ), + // (r) => false); // Navigator.of(context).pushNamed(LOGIN); }, ), @@ -425,13 +432,13 @@ class _VerificationMethodsScreenState extends State { GifLoaderDialogUtils.showMyDialog(context); - await authenticationViewModel.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password ); + await authenticationViewModel.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: authenticationViewModel.userInfo.password ); if (authenticationViewModel.state == ViewState.ErrorLocal) { Helpers.showErrorToast(authenticationViewModel.error); GifLoaderDialogUtils.hideDialog(context); } else { authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeForDoctorAppRes); - sharedPref.setString(PASSWORD, widget.password); + sharedPref.setString(PASSWORD, authenticationViewModel.userInfo.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); } diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 3fa348d2..7ba6ea0a 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -1,3 +1,4 @@ +import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/patient_muse/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; @@ -19,6 +20,7 @@ import 'package:doctor_app_flutter/screens/patients/patient_search/patient_searc import 'package:doctor_app_flutter/screens/patients/profile/referral/patient_referral_screen.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; +import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/patients/profile/profile-welcome-widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; @@ -69,6 +71,7 @@ class _HomeScreenState extends State { await model.setFirebaseNotification( projectsProvider, authenticationViewModel); await model.getDashboard(); + await model.getDoctorProfile(isGetProfile: true); }, builder: (_, model, w) => AppScaffold( baseViewModel: model, diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index e350e39d..64791b26 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -4,6 +4,7 @@ import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/screens/reschedule-leaves/add-rescheduleleave.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; @@ -172,7 +173,8 @@ class _AppDrawerState extends State { ), onTap: () async { Navigator.pop(context); - await authenticationViewModel.logout(); + GifLoaderDialogUtils.showMyDialog(context); + await authenticationViewModel.logout(isFromLogin: false); }, ), ],