From 2e71706cabfde4279ca44ff774f9001194a5a374 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 10 May 2021 15:07:03 +0300 Subject: [PATCH] add UNVERIFIED status --- lib/core/service/authentication_service.dart | 3 + .../viewModel/authentication_view_model.dart | 95 +- .../viewModel/doctor_profile_view_model.dart | 13 - lib/locator.dart | 1 - lib/main.dart | 6 +- lib/root_page.dart | 17 +- lib/screens/auth/login_screen.dart | 880 ++++++++---------- .../auth/verification_methods_screen.dart | 590 ++++++------ lib/screens/home/home_screen.dart | 5 +- .../auth/verification_methods_list.dart | 8 +- 10 files changed, 798 insertions(+), 820 deletions(-) diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index d20f5dbf..ffa22f33 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -35,6 +35,9 @@ class AuthenticationService extends BaseService { List _doctorProfilesList = []; List get doctorProfilesList => _doctorProfilesList; + + + Future selectDeviceImei(imei) async { try { await baseAppClient.post(SELECT_DEVICE_IMEI, diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index b5f61b05..c35c4e12 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; @@ -20,8 +22,10 @@ import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; +import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/services.dart'; import 'package:local_auth/auth_strings.dart'; import 'package:local_auth/local_auth.dart'; @@ -29,6 +33,8 @@ import 'package:provider/provider.dart'; import 'doctor_profile_view_model.dart'; +enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED, UNVERIFIED } + class AuthenticationViewModel extends BaseViewModel { AuthenticationService _authService = locator(); HospitalsService _hospitalsService = locator(); @@ -38,18 +44,20 @@ class AuthenticationViewModel extends BaseViewModel { List get hospitals => _hospitalsService.hospitals; NewLoginInformationModel get loginInfo => _authService.loginInfo; + List get doctorProfilesList => _authService.doctorProfilesList; + SendActivationCodeForDoctorAppResponseModel - get activationCodeVerificationScreenRes => - _authService.activationCodeVerificationScreenRes; + get activationCodeVerificationScreenRes => + _authService.activationCodeVerificationScreenRes; SendActivationCodeForDoctorAppResponseModel - get activationCodeForDoctorAppRes => - _authService.activationCodeForDoctorAppRes; + get activationCodeForDoctorAppRes => + _authService.activationCodeForDoctorAppRes; CheckActivationCodeForDoctorAppResponseModel - get checkActivationCodeForDoctorAppRes => - _authService.checkActivationCodeForDoctorAppRes; + get checkActivationCodeForDoctorAppRes => + _authService.checkActivationCodeForDoctorAppRes; NewLoginInformationModel loggedUser; GetIMEIDetailsModel user; @@ -57,7 +65,14 @@ class AuthenticationViewModel extends BaseViewModel { UserModel userInfo = UserModel(); final LocalAuthentication auth = LocalAuthentication(); List _availableBiometrics; + final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); + + bool isLogin = false; + bool unverified = false; + AuthenticationViewModel({bool checkDeviceInfo = false}) { + getDeviceInfoFromFirebase(); + } Future selectDeviceImei(imei) async { setState(ViewState.Busy); @@ -70,7 +85,6 @@ class AuthenticationViewModel extends BaseViewModel { } Future insertDeviceImei() async { - var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); var user = await sharedPref.getObj(LAST_LOGIN_USER); if (user != null) { @@ -116,6 +130,7 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.ErrorLocal); } else { sharedPref.setInt(PROJECT_ID, userInfo.projectID); + loggedUser = loginInfo; saveObjToString(LOGGED_IN_USER, loginInfo); sharedPref.remove(LAST_LOGIN_USER); sharedPref.setString(TOKEN, loginInfo.logInTokenID); @@ -183,7 +198,6 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.ErrorLocal); } else { setState(ViewState.Idle); - } } @@ -238,8 +252,7 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } - setDataAfterSendActivationSuccsess( - SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { + setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); sharedPref.setString(VIDA_AUTH_TOKEN_ID, @@ -300,28 +313,26 @@ class AuthenticationViewModel extends BaseViewModel { onCheckActivationCodeSuccess() async { sharedPref.setString( TOKEN, - checkActivationCodeForDoctorAppRes.authenticationTokenID); + checkActivationCodeForDoctorAppRes.authenticationTokenID); if (checkActivationCodeForDoctorAppRes.listDoctorProfile != null && checkActivationCodeForDoctorAppRes.listDoctorProfile .isNotEmpty) { localSetDoctorProfile( - checkActivationCodeForDoctorAppRes.listDoctorProfile[0]); - - + checkActivationCodeForDoctorAppRes.listDoctorProfile[0]); } else { sharedPref.setObj( CLINIC_NAME, checkActivationCodeForDoctorAppRes.listDoctorsClinic); ClinicModel clinic = ClinicModel.fromJson( - checkActivationCodeForDoctorAppRes.listDoctorsClinic[0] + checkActivationCodeForDoctorAppRes.listDoctorsClinic[0] .toJson()); - await getDoctorProfileBasedOnClinic(clinic); + await getDoctorProfileBasedOnClinic(clinic); } } Future checkIfBiometricAvailable(BiometricType biometricType) async { bool isAvailable = false; - await _getAvailableBiometrics(); + await _getAvailableBiometrics(); if (_availableBiometrics != null) { for (var i = 0; i < _availableBiometrics.length; i++) { if (biometricType == _availableBiometrics[i]) isAvailable = true; @@ -338,4 +349,54 @@ class AuthenticationViewModel extends BaseViewModel { } } + + getDeviceInfoFromFirebase() async { + _firebaseMessaging.setAutoInitEnabled(true); + if (Platform.isIOS) { + _firebaseMessaging.requestNotificationPermissions(); + } + setState(ViewState.Busy); + + _firebaseMessaging.getToken().then((String token) async { + if (DEVICE_TOKEN == "") { + DEVICE_TOKEN = token; + + await _authService.selectDeviceImei(DEVICE_TOKEN); + if (_authService.hasError) { + error = _authService.error; + setState(ViewState.ErrorLocal); + } else { + if (_authService.dashboardItemsList.length > 0) { + user =_authService.dashboardItemsList[0]; + sharedPref.setObj( + LAST_LOGIN_USER, _authService.dashboardItemsList[0]); + this.unverified = true; + // Navigator.of(AppGlobal.CONTEX).pushReplacement(MaterialPageRoute( + // builder: (BuildContext context) => VerificationMethodsScreen( + // password: null, + // ))); + } + setState(ViewState.Idle); + } + } else { + setState(ViewState.Idle); + } + }); + } + + + APP_STATUS get stutas { + if (state == ViewState.Busy) { + return APP_STATUS.LOADING; + } else { + if (this.unverified) { + return APP_STATUS.UNVERIFIED; + } else if (this.isLogin) { + return APP_STATUS.AUTHENTICATED; + } else { + return APP_STATUS.UNAUTHENTICATED; + } + } + } + } diff --git a/lib/core/viewModel/doctor_profile_view_model.dart b/lib/core/viewModel/doctor_profile_view_model.dart index 4dcaf050..6210951e 100644 --- a/lib/core/viewModel/doctor_profile_view_model.dart +++ b/lib/core/viewModel/doctor_profile_view_model.dart @@ -8,7 +8,6 @@ import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import '../../locator.dart'; -enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } class DoctorProfileViewModel extends BaseViewModel { List doctorsClinicList = []; @@ -41,18 +40,6 @@ class DoctorProfileViewModel extends BaseViewModel { } notifyListeners(); } -//TODO Elham move it auth view model - APP_STATUS get stutas { - if (isLoading) { - return APP_STATUS.LOADING; - } else { - if (this.isLogin) { - return APP_STATUS.AUTHENTICATED; - } else { - return APP_STATUS.UNAUTHENTICATED; - } - } - } Future getDocProfiles(docInfo, {bool allowChangeProfile = true}) async { diff --git a/lib/locator.dart b/lib/locator.dart index 3032c49d..869eadc2 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -90,7 +90,6 @@ void setupLocator() { /// View Model locator.registerFactory(() => DoctorReplayViewModel()); - locator.registerFactory(() => AuthenticationViewModel()); locator.registerFactory(() => ScheduleViewModel()); locator.registerFactory(() => ReferralPatientViewModel()); locator.registerFactory(() => ReferredPatientViewModel()); diff --git a/lib/main.dart b/lib/main.dart index 7c70061c..b7acdd80 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,6 +11,7 @@ import 'package:provider/provider.dart'; import './config/size_config.dart'; import './routes.dart'; import 'config/config.dart'; +import 'core/viewModel/authentication_view_model.dart'; import 'core/viewModel/doctor_profile_view_model.dart'; import 'core/viewModel/hospitals_view_model.dart'; import 'locator.dart'; @@ -23,7 +24,6 @@ void main() async { } class MyApp extends StatelessWidget { - // This widget is the root of your application. @override Widget build(BuildContext context) { AppGlobal.CONTEX = context; @@ -33,10 +33,10 @@ class MyApp extends StatelessWidget { SizeConfig().init(constraints, orientation); return MultiProvider( providers: [ + ChangeNotifierProvider( + create: (context) => AuthenticationViewModel()), ChangeNotifierProvider( create: (context) => DoctorProfileViewModel()), - // ChangeNotifierProvider( - // create: (context) => HospitalViewModel()), ChangeNotifierProvider( create: (context) => ProjectViewModel(), ), diff --git a/lib/root_page.dart b/lib/root_page.dart index 3b47290b..6040b160 100644 --- a/lib/root_page.dart +++ b/lib/root_page.dart @@ -1,25 +1,30 @@ -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; +import 'package:doctor_app_flutter/locator.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; +import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'core/viewModel/authentication_view_model.dart'; import 'landing_page.dart'; class RootPage extends StatelessWidget { @override Widget build(BuildContext context) { - DoctorProfileViewModel authProvider = Provider.of(context); + AuthenticationViewModel authenticationViewModel = Provider.of(context); + // ignore: missing_return Widget buildRoot() { - switch (authProvider.stutas) { + switch (authenticationViewModel.stutas) { case APP_STATUS.LOADING: return Scaffold( - body: Center( - child: DrAppCircularProgressIndeicator(), - ), + body: AppLoaderWidget(), ); break; + case APP_STATUS.UNVERIFIED: + return VerificationMethodsScreen(password: null,); + break; case APP_STATUS.UNAUTHENTICATED: return LoginScreen(); break; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 429aff5a..7fbf47af 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,32 +1,20 @@ -import 'dart:io'; - -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; -import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; -import 'package:doctor_app_flutter/screens/base/base_view.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/app_loader_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/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart'; -import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; -import '../../util/dr_app_shared_pref.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; -//TODO Elham remove it -DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); class LoginScreen extends StatefulWidget { @override @@ -35,10 +23,6 @@ class LoginScreen extends StatefulWidget { class _LoginScreenState extends State { String platformImei; - final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); - bool _isLoading = true; - ProjectViewModel projectViewModel; - AuthenticationService authService = AuthenticationService(); //TODO change AppTextFormField to AppTextFormFieldCustom final loginFormKey = GlobalKey(); @@ -46,463 +30,410 @@ class _LoginScreenState extends State { List projectsList = []; FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); - - - @override - void initState() { - super.initState(); - //TODO Elham move it root page and the logic in the view model - _firebaseMessaging.setAutoInitEnabled(true); - if (Platform.isIOS) { - _firebaseMessaging.requestNotificationPermissions(); - } - - _firebaseMessaging.getToken().then((String token) async { - if (DEVICE_TOKEN == "" && projectViewModel.isLogin == false) { - DEVICE_TOKEN = token; - changeLoadingState(true); - authService.selectDeviceImei(DEVICE_TOKEN).then((value) { - print(authService.dashboardItemsList); - - if (authService.dashboardItemsList.length > 0) { - sharedPref.setObj( - LAST_LOGIN_USER, authService.dashboardItemsList[0]); - Navigator.of(context).pushReplacement(MaterialPageRoute( - builder: (BuildContext context) => VerificationMethodsScreen( - password: null, - ))); - } else { - changeLoadingState(false); - } - }); - } else { - changeLoadingState(false); - } - }).catchError((err) { - print(err); - }); - } - - //TODO Elham change it to GIF - void changeLoadingState(isLoading) { - setState(() { - _isLoading = isLoading; - }); - } + AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { - projectViewModel = Provider.of(context); - return BaseView( - builder: (_, model, w) => - AppScaffold( - baseViewModel: model, - isShowAppBar: false, - backgroundColor: HexColor('#F8F8F8'), - body: SafeArea( - child: (_isLoading == false) - ? ListView(children: [ + authenticationViewModel = Provider.of(context); + return AppScaffold( + isShowAppBar: false, + backgroundColor: HexColor('#F8F8F8'), + body: SafeArea( + child: ListView(children: [ + Container( + margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 30), + alignment: Alignment.topLeft, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + //TODO Use App Text rather than text Container( - margin: - EdgeInsetsDirectional.fromSTEB(30, 0, 30, 30), - alignment: Alignment.topLeft, + child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - //TODO Use App Text rather than text - Container( + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + SizedBox( + height: 30, + ), + ], + ), + Column( + crossAxisAlignment: CrossAxisAlignment + .start, children: [ + SizedBox( + height: 10, + ), + Text( + TranslationBase + .of(context) + .welcomeTo, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight + .w600, + fontFamily: 'Poppins'), + ), + Text( + TranslationBase + .of(context) + .drSulaimanAlHabib, + style: TextStyle( + fontWeight: FontWeight + .w800, + fontSize: SizeConfig + .isMobile + ? 24 + : SizeConfig + .realScreenWidth * + 0.029, + fontFamily: 'Poppins'), + ), - child: Column( - crossAxisAlignment: CrossAxisAlignment - .start, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment - .start, - children: [ - SizedBox( - height: 30, - ), - ], - ), - Column( - crossAxisAlignment: CrossAxisAlignment - .start, children: [ - SizedBox( - height: 10, - ), - Text( + Text( + "Doctor App", + style: TextStyle( + fontSize: + SizeConfig.isMobile + ? 16 + : SizeConfig + .realScreenWidth * + 0.030, + fontWeight: FontWeight + .w800, + color: HexColor( + '#B8382C')), + ), + ]), + ], + )), + SizedBox( + height: 40, + ), + Form( + key: loginFormKey, + child: Column( + mainAxisAlignment: MainAxisAlignment + .spaceBetween, + children: [ + Container( + width: SizeConfig + .realScreenWidth * 0.90, + height: SizeConfig + .realScreenHeight * 0.65, + child: + Column( + crossAxisAlignment: CrossAxisAlignment + .start, children: [ + buildSizedBox(), + Padding( + child: AppText( + TranslationBase + .of(context) + .enterCredentials, + fontSize: 18, + fontWeight: FontWeight + .bold, + ), + padding: EdgeInsets.only( + top: 10, bottom: 10)), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius + .all( + Radius.circular( + 6.0)), + border: Border.all( + width: 1.0, + color: HexColor( + "#CCCCCC"), + ), + color: Colors.white), + child: Column( + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + Padding( + padding: EdgeInsets + .only( + left: 10, + top: 10), + child: AppText( TranslationBase .of(context) - .welcomeTo, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight - .w600, - fontFamily: 'Poppins'), - ), - Text( + .enterId, + fontWeight: FontWeight + .w800, + fontSize: 14, + )), + AppTextFormField( + labelText: '', + borderColor: Colors + .white, + textInputAction: TextInputAction + .next, + + validator: (value) { + if (value != + null && value + .isEmpty) { + return TranslationBase + .of(context) + .pleaseEnterYourID; + } + return null; + }, + onSaved: (value) { + if (value != + null) setState(() { + authenticationViewModel.userInfo + .userID = + value + .trim(); + }); + }, + onChanged: (value) { + if (value != null) + setState(() { + authenticationViewModel.userInfo + .userID = + value + .trim(); + }); + }, + onFieldSubmitted: (_) { + focusPass + .nextFocus(); + }, + ) + ])), + buildSizedBox(), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius + .all( + Radius.circular( + 6.0)), + border: Border.all( + width: 1.0, + color: HexColor( + "#CCCCCC"), + ), + color: Colors.white), + child: Column( + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + Padding( + padding: EdgeInsets + .only( + left: 10, + top: 10), + child: AppText( TranslationBase .of(context) - .drSulaimanAlHabib, - style: TextStyle( - fontWeight: FontWeight - .w800, - fontSize: SizeConfig - .isMobile - ? 24 - : SizeConfig - .realScreenWidth * - 0.029, - fontFamily: 'Poppins'), - ), - - Text( - "Doctor App", - style: TextStyle( - fontSize: - SizeConfig.isMobile - ? 16 - : SizeConfig - .realScreenWidth * - 0.030, - fontWeight: FontWeight - .w800, - color: HexColor( - '#B8382C')), - ), - ]), - ], - )), - SizedBox( - height: 40, - ), - Form( - key: loginFormKey, - child: Column( - mainAxisAlignment: MainAxisAlignment - .spaceBetween, - children: [ - Container( - width: SizeConfig - .realScreenWidth * 0.90, - height: SizeConfig - .realScreenHeight * 0.65, - child: - Column( - crossAxisAlignment: CrossAxisAlignment - .start, children: [ - buildSizedBox(), - Padding( - child: AppText( - TranslationBase - .of(context) - .enterCredentials, - fontSize: 18, - fontWeight: FontWeight - .bold, - ), - padding: EdgeInsets.only( - top: 10, bottom: 10)), - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius - .all( - Radius.circular( - 6.0)), - border: Border.all( - width: 1.0, - color: HexColor( - "#CCCCCC"), - ), - color: Colors.white), - child: Column( - crossAxisAlignment: CrossAxisAlignment - .start, - children: [ - Padding( - padding: EdgeInsets - .only( - left: 10, - top: 10), - child: AppText( - TranslationBase - .of(context) - .enterId, - fontWeight: FontWeight - .w800, - fontSize: 14, - )), - AppTextFormField( - labelText: '', - borderColor: Colors - .white, - textInputAction: TextInputAction - .next, - - validator: (value) { - if (value != - null && value - .isEmpty) { - return TranslationBase - .of(context) - .pleaseEnterYourID; - } - return null; - }, - onSaved: (value) { - if (value != - null) setState(() { - model.userInfo - .userID = - value - .trim(); - }); - }, - onChanged: (value) { - if (value != null) - setState(() { - model.userInfo - .userID = - value - .trim(); - }); - }, - onFieldSubmitted: ( - _) { - focusPass - .nextFocus(); - }, - ) - ])), - buildSizedBox(), - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius - .all( - Radius.circular( - 6.0)), - border: Border.all( - width: 1.0, - color: HexColor( - "#CCCCCC"), - ), - color: Colors.white), - child: Column( - crossAxisAlignment: CrossAxisAlignment - .start, - children: [ - Padding( - padding: EdgeInsets - .only( - left: 10, - top: 10), - child: AppText( - TranslationBase - .of(context) - .enterPassword, - fontWeight: FontWeight - .w800, - fontSize: 14, - )), - AppTextFormField( - focusNode: focusPass, - obscureText: true, - borderColor: Colors - .white, - textInputAction: TextInputAction - .next, - validator: (value) { - if (value != - null && value - .isEmpty) { - return TranslationBase - .of(context) - .pleaseEnterPassword; - } - return null; - }, - onSaved: (value) { - if (value != - null) - setState(() { - model.userInfo - .password = - value; - }); - - }, - onChanged: (value){ - if (value != - null) - setState(() { - model.userInfo - .password = - value; - }); - }, - onFieldSubmitted: ( - _) { - focusPass - .nextFocus(); - Helpers - .showCupertinoPicker( - context, - projectsList, - 'facilityName', - onSelectProject, - model); - }, - onTap: () { - this.getProjects( - model.userInfo - .userID, model); - }, - ) - ])), - buildSizedBox(), - projectsList.length > 0 - ? Container( - decoration: BoxDecoration( - borderRadius: BorderRadius - .all( - Radius.circular( - 6.0)), - border: Border.all( - width: 1.0, - color: HexColor( - "#CCCCCC"), - ), - color: Colors.white), - child: Column( - crossAxisAlignment: CrossAxisAlignment - .start, - children: [ - Padding( - padding: EdgeInsets - .only( - left: 10, - top: 10), - child: AppText( - TranslationBase - .of(context) - .selectYourProject, - fontWeight: FontWeight - .w600, - )), - AppTextFormField( - focusNode: focusProject, - controller: projectIdController, - borderColor: Colors - .white, - suffixIcon: Icons - .arrow_drop_down, - onTap: () { - Helpers - .showCupertinoPicker( - context, - projectsList, - 'facilityName', - onSelectProject, - model); - }, - validator: ( - value) { - if (value != - null && - value - .isEmpty) { - return TranslationBase - .of( - context) - .pleaseEnterYourProject; - } - return null; - }) - ])) - : Container( - decoration: BoxDecoration( - borderRadius: BorderRadius - .all( - Radius.circular( - 6.0)), - border: Border.all( - width: 1.0, - color: HexColor( - "#CCCCCC"), - ), - color: Colors.white), - child: Column( - crossAxisAlignment: CrossAxisAlignment - .start, - children: [ - Padding( - padding: EdgeInsets - .only( - left: 10, - top: 10), - child: AppText( - TranslationBase - .of(context) - .selectYourProject, - fontWeight: FontWeight - .w800, - fontSize: 14, - )), - AppTextFormField( - readOnly: true, - borderColor: Colors - .white, - prefix: IconButton( - icon: Icon(Icons - .arrow_drop_down), - iconSize: 30, - padding: EdgeInsets - .only( - bottom: 30), - ), - ) - ])), - ]), - ), - Row( - mainAxisAlignment: MainAxisAlignment - .end, - children: [ - Expanded( - child: AppButton( - title: TranslationBase - .of(context) - .login, - color: HexColor( - '#D02127'), - disabled: model.userInfo - .userID == null || - model.userInfo - .password == - null, - fontWeight: FontWeight - .bold, - onPressed: () { - login(context, model); - }, - )), - ], + .enterPassword, + fontWeight: FontWeight + .w800, + fontSize: 14, + )), + AppTextFormField( + focusNode: focusPass, + obscureText: true, + borderColor: Colors + .white, + textInputAction: TextInputAction + .next, + validator: (value) { + if (value != + null && value + .isEmpty) { + return TranslationBase + .of(context) + .pleaseEnterPassword; + } + return null; + }, + onSaved: (value) { + if (value != + null) + setState(() { + authenticationViewModel.userInfo + .password = + value; + }); + }, + onChanged: (value){ + if (value != + null) + setState(() { + authenticationViewModel.userInfo + .password = + value; + }); + }, + onFieldSubmitted: (_) { + focusPass + .nextFocus(); + Helpers + .showCupertinoPicker( + context, + projectsList, + 'facilityName', + onSelectProject, + authenticationViewModel); + }, + onTap: () { + this.getProjects( + authenticationViewModel.userInfo + .userID); + }, ) - ], - ), - ) - ], - ) - ])) - ]) - : Center(child: AppLoaderWidget()), - ), - ), ); + ])), + buildSizedBox(), + projectsList.length > 0 + ? Container( + decoration: BoxDecoration( + borderRadius: BorderRadius + .all( + Radius.circular( + 6.0)), + border: Border.all( + width: 1.0, + color: HexColor( + "#CCCCCC"), + ), + color: Colors.white), + child: Column( + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + Padding( + padding: EdgeInsets + .only( + left: 10, + top: 10), + child: AppText( + TranslationBase + .of(context) + .selectYourProject, + fontWeight: FontWeight + .w600, + )), + AppTextFormField( + focusNode: focusProject, + controller: projectIdController, + borderColor: Colors + .white, + suffixIcon: Icons + .arrow_drop_down, + onTap: () { + Helpers + .showCupertinoPicker( + context, + projectsList, + 'facilityName', + onSelectProject, + authenticationViewModel); + }, + validator: (value) { + if (value != + null && + value + .isEmpty) { + return TranslationBase + .of( + context) + .pleaseEnterYourProject; + } + return null; + }) + ])) + : Container( + decoration: BoxDecoration( + borderRadius: BorderRadius + .all( + Radius.circular( + 6.0)), + border: Border.all( + width: 1.0, + color: HexColor( + "#CCCCCC"), + ), + color: Colors.white), + child: Column( + crossAxisAlignment: CrossAxisAlignment + .start, + children: [ + Padding( + padding: EdgeInsets + .only( + left: 10, + top: 10), + child: AppText( + TranslationBase + .of(context) + .selectYourProject, + fontWeight: FontWeight + .w800, + fontSize: 14, + )), + AppTextFormField( + readOnly: true, + borderColor: Colors + .white, + prefix: IconButton( + icon: Icon(Icons + .arrow_drop_down), + iconSize: 30, + padding: EdgeInsets + .only( + bottom: 30), + ), + ) + ])), + ]), + ), + Row( + mainAxisAlignment: MainAxisAlignment + .end, + children: [ + Expanded( + child: AppButton( + title: TranslationBase + .of(context) + .login, + color: HexColor( + '#D02127'), + disabled: authenticationViewModel.userInfo + .userID == null || + authenticationViewModel.userInfo + .password == + null, + fontWeight: FontWeight + .bold, + onPressed: () { + login(context); + }, + )), + ], + ) + ], + ), + ) + ], + ) + ])) + ]), + ), + ); } SizedBox buildSizedBox() { @@ -511,15 +442,14 @@ class _LoginScreenState extends State { ); } - login(context, - AuthenticationViewModel model,) async { + login(context,) async { if (loginFormKey.currentState.validate()) { loginFormKey.currentState.save(); GifLoaderDialogUtils.showMyDialog(context); - await model.login(model.userInfo); - if (model.state == ViewState.ErrorLocal) { + await authenticationViewModel.login(authenticationViewModel.userInfo); + if (authenticationViewModel.state == ViewState.ErrorLocal) { GifLoaderDialogUtils.hideDialog(context); - Helpers.showErrorToast(model.error); + Helpers.showErrorToast(authenticationViewModel.error); } else { GifLoaderDialogUtils.hideDialog(context); @@ -527,7 +457,7 @@ class _LoginScreenState extends State { MaterialPageRoute( builder: (BuildContext context) => VerificationMethodsScreen( - password: model.userInfo.password, + password: authenticationViewModel.userInfo.password, ), ), ); @@ -535,23 +465,23 @@ class _LoginScreenState extends State { } } - onSelectProject(index, AuthenticationViewModel model) { + onSelectProject(index) { setState(() { - model.userInfo.projectID = projectsList[index].facilityId; + authenticationViewModel.userInfo.projectID = projectsList[index].facilityId; projectIdController.text = projectsList[index].facilityName; }); primaryFocus.unfocus(); } - getProjects(memberID, AuthenticationViewModel model)async { + getProjects(memberID)async { if (memberID != null && memberID != '') { if (projectsList.length == 0) { - await model.getHospitalsList(memberID); - if(model.state == ViewState.Idle) { - projectsList = model.hospitals; + await authenticationViewModel.getHospitalsList(memberID); + if(authenticationViewModel.state == ViewState.Idle) { + projectsList = authenticationViewModel.hospitals; setState(() { - model.userInfo.projectID = projectsList[0].facilityId; + authenticationViewModel.userInfo.projectID = projectsList[0].facilityId; projectIdController.text = projectsList[0].facilityName; }); } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 1c16bda9..40749b84 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -4,8 +4,8 @@ import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; -import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/date-utils.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/auth/sms-popup.dart'; @@ -19,7 +19,6 @@ import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; import '../../config/size_config.dart'; -import '../../core/viewModel/doctor_profile_view_model.dart'; import '../../landing_page.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; @@ -46,28 +45,25 @@ class _VerificationMethodsScreenState extends State { DoctorProfileViewModel doctorProfileViewModel; AuthMethodTypes fingerPrintBefore; AuthMethodTypes selectedOption; - AuthenticationViewModel model; + AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { doctorProfileViewModel = Provider.of(context); projectsProvider = Provider.of(context); - return BaseView( - onModelReady: (model) async { - this.model = model; - await model.getInitUserInfo(); - }, - builder: (_, model, w) => AppScaffold( - isShowAppBar: false, - baseViewModel: model, - body: SingleChildScrollView( - child: Center( - child: FractionallySizedBox( - child: Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - height: SizeConfig.realScreenHeight * .95, - width: SizeConfig.realScreenWidth, - child: Column( + authenticationViewModel = Provider.of(context); + + return AppScaffold( + isShowAppBar: false, + // baseViewModel: model, + body: SingleChildScrollView( + child: Center( + child: FractionallySizedBox( + child: Container( + margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), + height: SizeConfig.realScreenHeight * .95, + width: SizeConfig.realScreenWidth, + child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -77,284 +73,280 @@ class _VerificationMethodsScreenState extends State { SizedBox( height: 100, ), - model.user != null && isMoreOption == false + authenticationViewModel.user != null && isMoreOption == false + ? Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AppText( + TranslationBase.of(context).welcomeBack), + AppText( + Helpers.capitalize(authenticationViewModel.user.doctorName), + fontSize: SizeConfig.textMultiplier * 3.5, + fontWeight: FontWeight.bold, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).accountInfo, + fontSize: SizeConfig.textMultiplier * 2.5, + fontWeight: FontWeight.w600, + ), + SizedBox( + height: 20, + ), + Card( + color: Colors.white, + child: Row( + children: [ + Flexible( + flex: 3, + child: ListTile( + title: Text( + TranslationBase.of(context) + .lastLoginAt, + overflow: + TextOverflow.ellipsis, + style: TextStyle( + fontFamily: 'Poppins', + fontWeight: + FontWeight + .w800, + fontSize: 14), + ), + subtitle: AppText( + authenticationViewModel.getType( + authenticationViewModel.user + .logInTypeID, + context), + fontSize: 14, + ))), + Flexible( + flex: 2, + child: ListTile( + title: AppText( + authenticationViewModel.user.editedOn != + null + ? DateUtils.getDayMonthYearDateFormatted( + DateUtils.convertStringToDate( + authenticationViewModel.user + .editedOn)) + : authenticationViewModel.user.createdOn != + null + ? DateUtils.getDayMonthYearDateFormatted( + DateUtils.convertStringToDate(authenticationViewModel.user + .createdOn)) + : '--', + textAlign: + TextAlign.right, + fontSize: 14, + fontWeight: + FontWeight.w800, + ), + subtitle: AppText( + authenticationViewModel.user.editedOn != + null + ? DateUtils.getHour( + DateUtils.convertStringToDate( + authenticationViewModel.user + .editedOn)) + : authenticationViewModel.user.createdOn != + null + ? DateUtils.getHour( + DateUtils.convertStringToDate(authenticationViewModel.user + .createdOn)) + : '--', + textAlign: + TextAlign.right, + fontSize: 14, + ), + )) + ], + )), + ], + ) + : Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + this.onlySMSBox == false + ? AppText( + TranslationBase.of(context) + .verifyLoginWith, + fontSize: + SizeConfig.textMultiplier * 3.5, + textAlign: TextAlign.left, + ) + : AppText( + TranslationBase.of(context) + .verifyFingerprint2, + fontSize: + SizeConfig.textMultiplier * 2.5, + textAlign: TextAlign.start, + ), + ]), + authenticationViewModel.user != null && isMoreOption == false ? Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + child: InkWell( + onTap: () => + { + // TODO check this logic it seem it will create bug to us + authenticateUser( + AuthMethodTypes + .Fingerprint, true) + }, + child: VerificationMethodsList( + authenticationViewModel:authenticationViewModel, + authMethodType: SelectedAuthMethodTypesService + .getMethodsTypeService( + authenticationViewModel.user + .logInTypeID), + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )), + ), + Expanded( + child: VerificationMethodsList( + authenticationViewModel:authenticationViewModel, + authMethodType: + AuthMethodTypes.MoreOptions, + onShowMore: () { + setState(() { + isMoreOption = true; + }); + }, + )) + ]), + ]) + : Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + onlySMSBox == false + ? Row( mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, + MainAxisAlignment.center, children: [ - AppText( - TranslationBase.of(context).welcomeBack), - AppText( - Helpers.capitalize(model.user.doctorName), - fontSize: SizeConfig.textMultiplier * 3.5, - fontWeight: FontWeight.bold, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).accountInfo, - fontSize: SizeConfig.textMultiplier * 2.5, - fontWeight: FontWeight.w600, - ), - SizedBox( - height: 20, - ), - Card( - color: Colors.white, - child: Row( - children: [ - Flexible( - flex: 3, - child: ListTile( - title: Text( - TranslationBase.of(context) - .lastLoginAt, - overflow: - TextOverflow.ellipsis, - style: TextStyle( - fontFamily: 'Poppins', - fontWeight: - FontWeight - .w800, - fontSize: 14), - ), - subtitle: AppText( - model.getType( - model.user - .logInTypeID, - context), - fontSize: 14, - ))), - Flexible( - flex: 2, - child: ListTile( - title: AppText( - model.user.editedOn != - null - ? DateUtils.getDayMonthYearDateFormatted( - DateUtils.convertStringToDate( - model.user - .editedOn)) - : model.user.createdOn != - null - ? DateUtils.getDayMonthYearDateFormatted( - DateUtils.convertStringToDate(model - .user - .createdOn)) - : '--', - textAlign: - TextAlign.right, - fontSize: 14, - fontWeight: - FontWeight.w800, - ), - subtitle: AppText( - model.user.editedOn != - null - ? DateUtils.getHour( - DateUtils.convertStringToDate( - model.user - .editedOn)) - : model.user.createdOn != - null - ? DateUtils.getHour( - DateUtils.convertStringToDate(model - .user - .createdOn)) - : '--', - textAlign: - TextAlign.right, - fontSize: 14, - ), - )) - ], - )), + Expanded( + child: VerificationMethodsList( + authenticationViewModel:authenticationViewModel, + authMethodType: + AuthMethodTypes.Fingerprint, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )), + Expanded( + child: VerificationMethodsList( + authenticationViewModel:authenticationViewModel, + authMethodType: + AuthMethodTypes.FaceID, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )) ], ) - : Column( + : SizedBox(), + Row( mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - this.onlySMSBox == false - ? AppText( - TranslationBase.of(context) - .verifyLoginWith, - fontSize: - SizeConfig.textMultiplier * 3.5, - textAlign: TextAlign.left, - ) - : AppText( - TranslationBase.of(context) - .verifyFingerprint2, - fontSize: - SizeConfig.textMultiplier * 2.5, - textAlign: TextAlign.start, - ), - ]), - model.user != null && isMoreOption == false - ? Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, + MainAxisAlignment.center, children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: InkWell( - onTap: () => - { - // TODO check this logic it seem it will create bug to us - authenticateUser( - AuthMethodTypes - .Fingerprint, true) - }, - child: VerificationMethodsList( - model: model, - authMethodType: SelectedAuthMethodTypesService - .getMethodsTypeService( - model.user - .logInTypeID), - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => - authenticateUser( - authMethodType, - isActive), - )), - ), - Expanded( - child: VerificationMethodsList( - model: model, - authMethodType: - AuthMethodTypes.MoreOptions, - onShowMore: () { - setState(() { - isMoreOption = true; - }); - }, - )) - ]), - ]) - : Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - onlySMSBox == false - ? Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: VerificationMethodsList( - model: model, - authMethodType: - AuthMethodTypes.Fingerprint, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => - authenticateUser( - authMethodType, - isActive), - )), - Expanded( - child: VerificationMethodsList( - model: model, - authMethodType: - AuthMethodTypes.FaceID, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => - authenticateUser( - authMethodType, - isActive), - )) - ], - ) - : SizedBox(), - Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: VerificationMethodsList( - model: model, - authMethodType: AuthMethodTypes - .SMS, - authenticateUser: - ( - AuthMethodTypes authMethodType, - isActive) => - authenticateUser( - authMethodType, isActive), - )), - Expanded( - child: VerificationMethodsList( - model: model, - authMethodType: - AuthMethodTypes.WhatsApp, - authenticateUser: - ( - AuthMethodTypes authMethodType, - isActive) => - authenticateUser( - authMethodType, isActive), - )) - ], - ), - ]), + Expanded( + child: VerificationMethodsList( + authenticationViewModel:authenticationViewModel, + authMethodType: AuthMethodTypes + .SMS, + authenticateUser: + ( + AuthMethodTypes authMethodType, + isActive) => + authenticateUser( + authMethodType, isActive), + )), + Expanded( + child: VerificationMethodsList( + authenticationViewModel:authenticationViewModel, + authMethodType: + AuthMethodTypes.WhatsApp, + authenticateUser: + ( + AuthMethodTypes authMethodType, + isActive) => + authenticateUser( + authMethodType, isActive), + )) + ], + ), + ]), // ) ], ), ), ], - ), - ), ), ), ), - bottomSheet: model.user == null ? SizedBox(height: 0,) : Container( - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all( - Radius.circular(0.0), - ), - border: Border.all( - color: HexColor('#707070'), - width: 0), - ), - height: 90, - width: double.infinity, - child: Center( - child: FractionallySizedBox( - widthFactor: 0.9, - child: Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - AppButton( - title: TranslationBase - .of(context) - .useAnotherAccount, - color: Colors.red[700], - onPressed: () { - Navigator.of(context).pushNamed(LOGIN); - }, - ), - - SizedBox(height: 25,) - ], + ), + ), + bottomSheet: authenticationViewModel.user == null ? SizedBox(height: 0,) : Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all( + Radius.circular(0.0), + ), + border: Border.all( + color: HexColor('#707070'), + width: 0), + ), + height: 90, + width: double.infinity, + child: Center( + child: FractionallySizedBox( + widthFactor: 0.9, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + AppButton( + title: TranslationBase + .of(context) + .useAnotherAccount, + color: Colors.red[700], + onPressed: () { + Navigator.of(context).pushNamed(LOGIN); + }, ), - ), - ),), - ) + SizedBox(height: 25,) + ], + ), + ), + ),), ); } @@ -365,12 +357,12 @@ class _VerificationMethodsScreenState extends State { GifLoaderDialogUtils.showMyDialog(context); - await model.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password ); - if (model.state == ViewState.ErrorLocal) { - Helpers.showErrorToast(model.error); + await authenticationViewModel.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password ); + if (authenticationViewModel.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(authenticationViewModel.error); GifLoaderDialogUtils.hideDialog(context); } else { - model.setDataAfterSendActivationSuccsess(model.activationCodeForDoctorAppRes); + authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeForDoctorAppRes); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); @@ -385,14 +377,14 @@ class _VerificationMethodsScreenState extends State { sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { GifLoaderDialogUtils.showMyDialog(context); - await model + await authenticationViewModel .sendActivationCodeVerificationScreen(authMethodType); - if (model.state == ViewState.ErrorLocal) { + if (authenticationViewModel.state == ViewState.ErrorLocal) { GifLoaderDialogUtils.hideDialog(context); - Helpers.showErrorToast(model.error); + Helpers.showErrorToast(authenticationViewModel.error); } else { - model.setDataAfterSendActivationSuccsess(model.activationCodeVerificationScreenRes); + authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeVerificationScreenRes); if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.hideDialog(context); @@ -432,7 +424,7 @@ class _VerificationMethodsScreenState extends State { } sendActivationCode(AuthMethodTypes authMethodType) async { - if (model.user != null) { + if (authenticationViewModel.user != null) { sendActivationCodeVerificationScreen(authMethodType); } else { sendActivationCodeByOtpNotificationType(authMethodType); @@ -444,7 +436,7 @@ class _VerificationMethodsScreenState extends State { new SMSOTP( context, type, - model.loggedUser != null ? model.loggedUser.mobileNumber : model.user.mobile, + authenticationViewModel.loggedUser != null ? authenticationViewModel.loggedUser.mobileNumber : authenticationViewModel.user.mobile, (value) { showDialog( context: context, @@ -465,14 +457,14 @@ class _VerificationMethodsScreenState extends State { loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async { if (isActive) { - await model.showIOSAuthMessages(); + await authenticationViewModel.showIOSAuthMessages(); if (!mounted) return; - if (model.user != null && + if (authenticationViewModel.user != null && (SelectedAuthMethodTypesService.getMethodsTypeService( - model.user.logInTypeID) == + authenticationViewModel.user.logInTypeID) == AuthMethodTypes.Fingerprint || SelectedAuthMethodTypesService.getMethodsTypeService( - model.user.logInTypeID) == AuthMethodTypes.FaceID)) { + authenticationViewModel.user.logInTypeID) == AuthMethodTypes.FaceID)) { this.sendActivationCode(authMethodTypes); } else { setState(() { @@ -483,19 +475,19 @@ class _VerificationMethodsScreenState extends State { } checkActivationCode({value}) async { - await model.checkActivationCodeForDoctorApp(activationCode: value); - if (model.state == ViewState.ErrorLocal) { + await authenticationViewModel.checkActivationCodeForDoctorApp(activationCode: value); + if (authenticationViewModel.state == ViewState.ErrorLocal) { Navigator.pop(context); - Helpers.showErrorToast(model.error); + Helpers.showErrorToast(authenticationViewModel.error); } else { - await model.onCheckActivationCodeSuccess(); + await authenticationViewModel.onCheckActivationCodeSuccess(); navigateToLandingPage(); } } navigateToLandingPage() { - if (model.state == ViewState.ErrorLocal) { - Helpers.showErrorToast(model.error); + if (authenticationViewModel.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(authenticationViewModel.error); } else { projectsProvider.isLogin = true; diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 167abc61..d48e6417 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -75,13 +75,14 @@ class _HomeScreenState extends State { var clinicId; var _patientSearchFormValues; - AuthenticationViewModel _IMEIViewModel = locator(); + AuthenticationViewModel authenticationViewModel; void didChangeDependencies() async { super.didChangeDependencies(); if (_isInit) { projectsProvider = Provider.of(context); + authenticationViewModel = Provider.of(context); projectsProvider.getDoctorClinicsList(); // _firebaseMessaging.setAutoInitEnabled(true); @@ -97,7 +98,7 @@ class _HomeScreenState extends State { _firebaseMessaging.getToken().then((String token) async { if (token != '') { DEVICE_TOKEN = token; - await _IMEIViewModel.insertDeviceImei(); + await authenticationViewModel.insertDeviceImei(); changeIsLoading(false); } diff --git a/lib/widgets/auth/verification_methods_list.dart b/lib/widgets/auth/verification_methods_list.dart index e42e33ba..de867cde 100644 --- a/lib/widgets/auth/verification_methods_list.dart +++ b/lib/widgets/auth/verification_methods_list.dart @@ -11,14 +11,14 @@ class VerificationMethodsList extends StatefulWidget { final AuthMethodTypes authMethodType; final Function(AuthMethodTypes type, bool isActive) authenticateUser; final Function onShowMore; - final AuthenticationViewModel model; + final AuthenticationViewModel authenticationViewModel; const VerificationMethodsList( {Key key, this.authMethodType, this.authenticateUser, this.onShowMore, - this.model}) + this.authenticationViewModel}) : super(key: key); @override @@ -54,7 +54,7 @@ class _VerificationMethodsListState extends State { return MethodTypeCard( assetPath: 'assets/images/verification_fingerprint_icon.png', onTap: () async { - if (await widget.model + if (await widget.authenticationViewModel .checkIfBiometricAvailable(BiometricType.fingerprint)) { widget.authenticateUser(AuthMethodTypes.Fingerprint, true); @@ -67,7 +67,7 @@ class _VerificationMethodsListState extends State { return MethodTypeCard( assetPath: 'assets/images/verification_faceid_icon.png', onTap: () async { - if (await widget.model + if (await widget.authenticationViewModel .checkIfBiometricAvailable(BiometricType.face)) { widget.authenticateUser(AuthMethodTypes.FaceID, true); }