From 663d2a942f339ef41f839bbc564cf5c1797d8981 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 3 May 2021 16:18:00 +0300 Subject: [PATCH 01/28] first step from refactoring auth part --- .../get_hospitals_request_model.dart | 48 ++ .../get_hospitals_response_model.dart | 0 lib/core/service/auth_service.dart | 14 - .../service/hospitals/hospitals_service.dart | 23 + lib/core/viewModel/auth_view_model.dart | 72 +-- lib/core/viewModel/hospital_view_model.dart | 32 -- lib/core/viewModel/hospitals_view_model.dart | 27 ++ lib/core/viewModel/imei_view_model.dart | 20 +- lib/locator.dart | 4 + lib/main.dart | 6 +- lib/screens/auth/change_password_screen.dart | 29 -- lib/screens/auth/login_screen.dart | 430 +++++++++++++++++- .../auth/verification_methods_screen.dart | 19 +- lib/screens/home/home_screen.dart | 2 +- .../medicine/medicine_search_screen.dart | 4 +- lib/util/helpers.dart | 1 + lib/widgets/auth/auth_header.dart | 85 ---- lib/widgets/auth/change_password.dart | 159 ------- lib/widgets/auth/known_user_login.dart | 328 ------------- lib/widgets/auth/login_form.dart | 312 ------------- lib/widgets/auth/show_timer_text.dart | 105 ----- lib/widgets/auth/verfiy_account.dart | 386 ---------------- lib/widgets/auth/verification_methods.dart | 47 +- 23 files changed, 562 insertions(+), 1591 deletions(-) create mode 100644 lib/core/model/hospitals/get_hospitals_request_model.dart create mode 100644 lib/core/model/hospitals/get_hospitals_response_model.dart create mode 100644 lib/core/service/hospitals/hospitals_service.dart delete mode 100644 lib/core/viewModel/hospital_view_model.dart create mode 100644 lib/core/viewModel/hospitals_view_model.dart delete mode 100644 lib/screens/auth/change_password_screen.dart delete mode 100644 lib/widgets/auth/change_password.dart delete mode 100644 lib/widgets/auth/known_user_login.dart delete mode 100644 lib/widgets/auth/login_form.dart delete mode 100644 lib/widgets/auth/show_timer_text.dart delete mode 100644 lib/widgets/auth/verfiy_account.dart diff --git a/lib/core/model/hospitals/get_hospitals_request_model.dart b/lib/core/model/hospitals/get_hospitals_request_model.dart new file mode 100644 index 00000000..8a5f1bc1 --- /dev/null +++ b/lib/core/model/hospitals/get_hospitals_request_model.dart @@ -0,0 +1,48 @@ +class GetHospitalsRequestModel { + int languageID; + String stamp; + String iPAdress; + double versionID; + int channel; + String tokenID; + String sessionID; + bool isLoginForDoctorApp; + String memberID; + + GetHospitalsRequestModel( + {this.languageID, + this.stamp, + this.iPAdress, + this.versionID, + this.channel, + this.tokenID, + this.sessionID, + this.isLoginForDoctorApp, + this.memberID}); + + GetHospitalsRequestModel.fromJson(Map json) { + languageID = json['LanguageID']; + stamp = json['stamp']; + iPAdress = json['IPAdress']; + versionID = json['VersionID']; + channel = json['Channel']; + tokenID = json['TokenID']; + sessionID = json['SessionID']; + isLoginForDoctorApp = json['IsLoginForDoctorApp']; + memberID = json['MemberID']; + } + + Map toJson() { + final Map data = new Map(); + data['LanguageID'] = this.languageID; + data['stamp'] = this.stamp; + data['IPAdress'] = this.iPAdress; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['TokenID'] = this.tokenID; + data['SessionID'] = this.sessionID; + data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp; + data['MemberID'] = this.memberID; + return data; + } +} diff --git a/lib/core/model/hospitals/get_hospitals_response_model.dart b/lib/core/model/hospitals/get_hospitals_response_model.dart new file mode 100644 index 00000000..e69de29b diff --git a/lib/core/service/auth_service.dart b/lib/core/service/auth_service.dart index adb2d646..ec56bed7 100644 --- a/lib/core/service/auth_service.dart +++ b/lib/core/service/auth_service.dart @@ -44,19 +44,5 @@ class AuthService extends BaseService { super.error = error; } - // await baseAppClient.post(SELECT_DEVICE_IMEI, - // onSuccess: (dynamic response, int statusCode) { - // _imeiDetails = []; - // response['List_DoctorDeviceDetails'].forEach((v) { - // _imeiDetails.add(GetIMEIDetailsModel.fromJson(v)); - // }); - // }, onFailure: (String error, int statusCode) { - // hasError = true; - // super.error = error; - // }, body: {}); - // } catch (error) { - // hasError = true; - // super.error = error; - // } } } diff --git a/lib/core/service/hospitals/hospitals_service.dart b/lib/core/service/hospitals/hospitals_service.dart new file mode 100644 index 00000000..2c670e09 --- /dev/null +++ b/lib/core/service/hospitals/hospitals_service.dart @@ -0,0 +1,23 @@ +import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; +import 'package:doctor_app_flutter/core/service/base/base_service.dart'; + +class HospitalsService extends BaseService { + +List hospitals; + + Future getHospitals(GetHospitalsRequestModel getHospitalsRequestModel) async { + hasError = false; + await baseAppClient.post( + GET_PROJECTS, + onSuccess: (dynamic response, int statusCode) { + hospitals = response['ProjectInfo']; + }, + onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, + body: getHospitalsRequestModel.toJson(), + ); + } +} diff --git a/lib/core/viewModel/auth_view_model.dart b/lib/core/viewModel/auth_view_model.dart index 4e40fe31..48f4661d 100644 --- a/lib/core/viewModel/auth_view_model.dart +++ b/lib/core/viewModel/auth_view_model.dart @@ -56,23 +56,23 @@ class AuthViewModel extends BaseViewModel { } } - Future login(UserModel userInfo) async { - try { - dynamic localRes; - - await baseAppClient.post(LOGIN_URL, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - }, onFailure: (String error, int statusCode) { - throw error; - }, body: userInfo.toJson()); - - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } + // Future login(UserModel userInfo) async { + // try { + // dynamic localRes; + // + // await baseAppClient.post(LOGIN_URL, + // onSuccess: (dynamic response, int statusCode) { + // localRes = response; + // }, onFailure: (String error, int statusCode) { + // throw error; + // }, body: userInfo.toJson()); + // + // return Future.value(localRes); + // } catch (error) { + // print(error); + // throw error; + // } + // } Future insertDeviceImei(request) async { var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); @@ -112,22 +112,6 @@ class AuthViewModel extends BaseViewModel { } } - Future sendActivationCodeByOtpNotificationType(activationCodeModel) async { - try { - var localRes; - await baseAppClient.post(SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - }, onFailure: (String error, int statusCode) { - throw error; - }, body: activationCodeModel); - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } - Future sendActivationCodeForDoctorApp( ActivationCodeModel activationCodeModel) async { try { @@ -145,28 +129,6 @@ class AuthViewModel extends BaseViewModel { } } - Future memberCheckActivationCodeNew(activationCodeModel) async { - try { - dynamic localRes; - await baseAppClient.post(MEMBER_CHECK_ACTIVATION_CODE_NEW, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - selectedClinicName = - ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; - - response['List_DoctorsClinic'].forEach((v) { - doctorsClinicList.add(new ClinicModel.fromJson(v)); - }); - }, onFailure: (String error, int statusCode) { - throw error; - }, body: activationCodeModel); - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } - Future checkActivationCodeForDoctorApp( CheckActivationCodeRequestModel checkActivationCodeRequestModel) async { try { diff --git a/lib/core/viewModel/hospital_view_model.dart b/lib/core/viewModel/hospital_view_model.dart deleted file mode 100644 index a49b85e5..00000000 --- a/lib/core/viewModel/hospital_view_model.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:doctor_app_flutter/client/base_app_client.dart'; -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:flutter/cupertino.dart'; - -// TODO change it when change login -class HospitalViewModel with ChangeNotifier { - BaseAppClient baseAppClient = BaseAppClient(); - - Future getProjectsList(memberID) async { - const url = GET_PROJECTS; - // TODO create model or remove it if no info need - var info = { - "LanguageID": 1, - "stamp": "2020-02-26T13:51:44.111Z", - "IPAdress": "11.11.11.11", - "VersionID": 5.8, - "Channel": 9, - "TokenID": "", - "SessionID": "i1UJwCTSqt", - "IsLoginForDoctorApp": true, - "MemberID": memberID - }; - dynamic localRes; - - await baseAppClient.post(url, onSuccess: (response, statusCode) async { - localRes = response; - }, onFailure: (String error, int statusCode) { - throw error; - }, body: info); - return Future.value(localRes); - } -} diff --git a/lib/core/viewModel/hospitals_view_model.dart b/lib/core/viewModel/hospitals_view_model.dart new file mode 100644 index 00000000..c0ce1bc4 --- /dev/null +++ b/lib/core/viewModel/hospitals_view_model.dart @@ -0,0 +1,27 @@ +import 'package:doctor_app_flutter/client/base_app_client.dart'; +import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; +import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; +import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; +import 'package:flutter/cupertino.dart'; + +import '../../locator.dart'; +import 'base_view_model.dart'; + + +class HospitalViewModel extends BaseViewModel { + HospitalsService _hospitalsService = locator(); + // List get imeiDetails => _authService.dashboardItemsList; + // get loginInfo => _authService.loginInfo; + Future getHospitalsList(memberID) async { + GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); + getHospitalsRequestModel.memberID = memberID; + setState(ViewState.Busy); + await _hospitalsService.getHospitals(getHospitalsRequestModel); + if (_hospitalsService.hasError) { + error = _hospitalsService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } +} diff --git a/lib/core/viewModel/imei_view_model.dart b/lib/core/viewModel/imei_view_model.dart index c2d16206..ba462553 100644 --- a/lib/core/viewModel/imei_view_model.dart +++ b/lib/core/viewModel/imei_view_model.dart @@ -1,6 +1,8 @@ import 'package:doctor_app_flutter/core/enum/viewstate.dart'; +import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/service/auth_service.dart'; +import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; @@ -8,7 +10,10 @@ import 'package:doctor_app_flutter/util/helpers.dart'; class IMEIViewModel extends BaseViewModel { AuthService _authService = locator(); + HospitalsService _hospitalsService = locator(); + List get imeiDetails => _authService.dashboardItemsList; + List get hospitals => _hospitalsService.hospitals; get loginInfo => _authService.loginInfo; Future selectDeviceImei(imei) async { setState(ViewState.Busy); @@ -21,13 +26,24 @@ class IMEIViewModel extends BaseViewModel { } Future login(UserModel userInfo) async { - setState(ViewState.Busy); + setState(ViewState.BusyLocal); await _authService.login(userInfo); if (_authService.hasError) { error = _authService.error; - Helpers.showErrorToast(error); setState(ViewState.ErrorLocal); } else setState(ViewState.Idle); } + + Future getHospitalsList(memberID) async { + GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); + getHospitalsRequestModel.memberID = memberID; + // setState(ViewState.Busy); + await _hospitalsService.getHospitals(getHospitalsRequestModel); + if (_hospitalsService.hasError) { + error = _hospitalsService.error; + setState(ViewState.Error); + } else + setState(ViewState.Idle); + } } diff --git a/lib/locator.dart b/lib/locator.dart index 13b51d95..d0d76ea3 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -6,6 +6,7 @@ import 'package:doctor_app_flutter/core/service/prescription_service.dart'; import 'package:doctor_app_flutter/core/service/procedure_service.dart'; import 'package:doctor_app_flutter/core/service/sickleave_service.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/medical_file_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; @@ -21,6 +22,7 @@ import 'core/service/PatientMuseService.dart'; import 'core/service/ReferralService.dart'; import 'core/service/SOAP_service.dart'; import 'core/service/doctor_reply_service.dart'; +import 'core/service/hospitals/hospitals_service.dart'; import 'core/service/labs_service.dart'; import 'core/service/medicine_service.dart'; import 'core/service/patient-admission-request-service.dart'; @@ -84,6 +86,7 @@ void setupLocator() { locator.registerLazySingleton(() => DischargedPatientService()); locator.registerLazySingleton(() => PatientInPatientService()); locator.registerLazySingleton(() => OutPatientService()); + locator.registerLazySingleton(() => HospitalsService()); /// View Model locator.registerFactory(() => DoctorReplayViewModel()); @@ -110,4 +113,5 @@ void setupLocator() { locator.registerFactory(() => PrescriptionsViewModel()); locator.registerFactory(() => DischargedPatientViewModel()); locator.registerFactory(() => PatientSearchViewModel()); + locator.registerFactory(() => HospitalViewModel()); } diff --git a/lib/main.dart b/lib/main.dart index 4e140920..83c2a450 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,7 +12,7 @@ import './config/size_config.dart'; import './routes.dart'; import 'config/config.dart'; import 'core/viewModel/auth_view_model.dart'; -import 'core/viewModel/hospital_view_model.dart'; +import 'core/viewModel/hospitals_view_model.dart'; import 'locator.dart'; void main() async { @@ -35,8 +35,8 @@ class MyApp extends StatelessWidget { providers: [ ChangeNotifierProvider( create: (context) => AuthViewModel()), - ChangeNotifierProvider( - create: (context) => HospitalViewModel()), + // ChangeNotifierProvider( + // create: (context) => HospitalViewModel()), ChangeNotifierProvider( create: (context) => ProjectViewModel(), ), diff --git a/lib/screens/auth/change_password_screen.dart b/lib/screens/auth/change_password_screen.dart deleted file mode 100644 index 1a502b68..00000000 --- a/lib/screens/auth/change_password_screen.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:doctor_app_flutter/lookups/auth_lookup.dart'; -import 'package:doctor_app_flutter/widgets/auth/auth_header.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; -import 'package:flutter/material.dart'; - -import '../../widgets/auth/change_password.dart'; - -class ChangePasswordScreen extends StatelessWidget { - @override - Widget build(BuildContext context) { - - return AppScaffold( - isShowAppBar: false, - body: SafeArea( - child: ListView(children: [ - Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 0, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - AuthHeader(loginType.changePassword), - ChangePassword(), - ], - ), - ), - ]), - )); - } -} diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index fbba6360..b49b492f 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -3,22 +3,30 @@ 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/service/auth_service.dart'; +import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_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/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 'package:shared_preferences/shared_preferences.dart'; import '../../lookups/auth_lookup.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../widgets/auth/auth_header.dart'; -import '../../widgets/auth/login_form.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); @@ -29,14 +37,22 @@ class Loginsreen extends StatefulWidget { } class _LoginsreenState extends State { - Future _prefs = SharedPreferences.getInstance(); String platformImei; - // Future platformImeiFuture; final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); bool _isLoading = true; ProjectViewModel projectViewModel; AuthService authService = AuthService(); + + //TODO change AppTextFormField to AppTextFormFieldCustom + final loginFormKey = GlobalKey(); + var projectIdController = TextEditingController(); + var projectsList = []; + FocusNode focusPass = FocusNode(); + FocusNode focusProject = FocusNode(); + // HospitalViewModel hospitalViewModel; + var userInfo = UserModel(); + @override void initState() { super.initState(); @@ -49,7 +65,7 @@ class _LoginsreenState extends State { _firebaseMessaging.getToken().then((String token) async { if (DEVICE_TOKEN == "" && projectViewModel.isLogin == false) { DEVICE_TOKEN = token; - changeLoadingStata(true); + changeLoadingState(true); authService.selectDeviceImei(DEVICE_TOKEN).then((value) { print(authService.dashboardItemsList); @@ -61,30 +77,18 @@ class _LoginsreenState extends State { password: null, ))); } else { - changeLoadingStata(false); + changeLoadingState(false); } - //changeLoadingStata(false); }); } else { - changeLoadingStata(false); + changeLoadingState(false); } - - // else if (projectViewModel.isLogin) { - // getNotificationCount(token); - // } }).catchError((err) { print(err); }); } -/* - *@author: Elham Rababah - *@Date:19/4/2020 - *@param: isLoading - *@return: - *@desc: Change Isloading attribute in order to show or hide loader - */ - void changeLoadingStata(isLoading) { + void changeLoadingState(isLoading) { setState(() { _isLoading = isLoading; }); @@ -94,9 +98,11 @@ class _LoginsreenState extends State { Widget build(BuildContext context) { projectViewModel = Provider.of(context); + return BaseView( onModelReady: (model) => {}, - builder: (_, model, w) => AppScaffold( + builder: (_, model, w) => + AppScaffold( baseViewModel: model, isShowAppBar: false, backgroundColor: HexColor('#F8F8F8'), @@ -118,15 +124,389 @@ class _LoginsreenState extends State { SizedBox( height: 40, ), - LoginForm( - model: model, - ), + 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(() { + userInfo + .userID = + value + .trim(); + }); + }, + onChanged: (value) { + if (value != null) + setState(() { + 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) { + setState(() { + userInfo + .password = + value; + }); + + }, + onChanged: (value){ + setState(() { + userInfo + .password = + value; + }); + }, + onFieldSubmitted: ( + _) { + focusPass + .nextFocus(); + Helpers + .showCupertinoPicker( + context, + projectsList, + 'facilityName', + onSelectProject); + }, + onTap: () { + this.getProjects( + 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); + }, + 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: userInfo + .userID == null || + userInfo.password == + null, + fontWeight: FontWeight + .bold, + onPressed: () { + login(context, model); + }, + )), + ], + ) + ], + ), + ) ], ) ])) - ]) + ]) : Center(child: AppLoaderWidget()), ), )); } + + SizedBox buildSizedBox() { + return SizedBox( + height: 20, + ); + } + + login(context, + IMEIViewModel model,) async { + if (loginFormKey.currentState.validate()) { + loginFormKey.currentState.save(); + GifLoaderDialogUtils.showMyDialog(context); + sharedPref.setInt(PROJECT_ID, userInfo.projectID); + await model.login(userInfo); + if (model.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(model.error); + } else { + if (model.loginInfo['MessageStatus'] == 1) { + saveObjToString(LOGGED_IN_USER, model.loginInfo); + sharedPref.remove(LAST_LOGIN_USER); + sharedPref.setString(TOKEN, model.loginInfo['LogInTokenID']); + Navigator.of(AppGlobal.CONTEX).pushReplacement(MaterialPageRoute( + builder: (BuildContext context) => + VerificationMethodsScreen( + password: userInfo.password, + ))); + } + } + GifLoaderDialogUtils.hideDialog(context); + } + } + + Future setSharedPref(key, value) async { + sharedPref.setString(key, value).then((success) { + print("sharedPref.setString" + success.toString()); + }); + } + + + saveObjToString(String key, value) async { + sharedPref.setObj(key, value); + } + + onSelectProject(index) { + setState(() { + userInfo.projectID = projectsList[index]["facilityId"]; + projectIdController.text = projectsList[index]['facilityName']; + }); + + primaryFocus.unfocus(); + } + + getProjects(memberID, IMEIViewModel model) { + if (memberID != null && memberID != '') { + if (projectsList.length == 0) { + model.getHospitalsList(memberID).then((res) { + if (res['MessageStatus'] == 1) { + projectsList = res['ProjectInfo']; + setState(() { + userInfo.projectID = projectsList[0]["facilityId"]; + projectIdController.text = projectsList[0]['facilityName']; + }); + } else { + print(res); + } + }); + } + } + } } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 0ad71b76..7503a70e 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -4,13 +4,6 @@ import 'package:hexcolor/hexcolor.dart'; import '../../widgets/auth/verification_methods.dart'; -/* - *@author: Elham Rababah - *@Date:4/7/2020 - *@param: - *@return: - *@desc: Verification Methods screen - */ class VerificationMethodsScreen extends StatefulWidget { const VerificationMethodsScreen({Key key, this.password}) : super(key: key); @@ -24,14 +17,7 @@ class VerificationMethodsScreen extends StatefulWidget { class _VerificationMethodsScreenState extends State { bool _isLoading = false; - /* - *@author: Elham Rababah - *@Date:19/4/2020 - *@param: isLoading - *@return: - *@desc: Change Isloading attribute in order to show or hide loader - */ - void changeLoadingStata(isLoading) { + void changeLoadingState(isLoading) { setState(() { _isLoading = isLoading; }); @@ -50,13 +36,12 @@ class _VerificationMethodsScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - // AuthHeader(loginType.verificationMethods), SizedBox( height: 50, ), VerificationMethods( password: widget.password, - changeLoadingStata: changeLoadingStata, + changeLoadingState: changeLoadingState, ), ], ), diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index fdc4e3df..284fa1ed 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -6,7 +6,7 @@ import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/hospital_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; diff --git a/lib/screens/medicine/medicine_search_screen.dart b/lib/screens/medicine/medicine_search_screen.dart index 3ce5c1be..f1bb4c7b 100644 --- a/lib/screens/medicine/medicine_search_screen.dart +++ b/lib/screens/medicine/medicine_search_screen.dart @@ -29,9 +29,9 @@ import '../../util/extenstions.dart'; DrAppSharedPreferances sharedPref = DrAppSharedPreferances(); class MedicineSearchScreen extends StatefulWidget with DrAppToastMsg { - MedicineSearchScreen({this.changeLoadingStata}); + MedicineSearchScreen({this.changeLoadingState}); - final Function changeLoadingStata; + final Function changeLoadingState; @override _MedicineSearchState createState() => _MedicineSearchState(); diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 13b7b2ae..625a31c6 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -128,6 +128,7 @@ class Helpers { } static generateContactAdminMsg([err = null]) { + //TODO: Add translation String localMsg = 'Something wrong happened, please contact the admin'; if (err != null) { localMsg = localMsg + '\n \n' + err.toString(); diff --git a/lib/widgets/auth/auth_header.dart b/lib/widgets/auth/auth_header.dart index f84e9425..47e128be 100644 --- a/lib/widgets/auth/auth_header.dart +++ b/lib/widgets/auth/auth_header.dart @@ -24,18 +24,9 @@ class AuthHeader extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - // Container( - // margin: SizeConfig.isMobile - // ? EdgeInsetsDirectional.fromSTEB( - // 0, SizeConfig.realScreenHeight * 0.03, 0, 0) - // : EdgeInsetsDirectional.fromSTEB( - // SizeConfig.realScreenWidth * 0.13, 0, 0, 0), - // child: buildImageLogo(), - // ), SizedBox( height: 30, ), - //buildTextUnderLogo(context), ], ), Column( @@ -67,78 +58,6 @@ class AuthHeader extends StatelessWidget { return screen; } - Image buildImageLogo() { - String img = 'assets/images/dr_app_logo.png'; - return Image.asset( - img, - fit: BoxFit.cover, - height: SizeConfig.isMobile ? null : SizeConfig.realScreenWidth * 0.09, - ); - } - - Widget buildTextUnderLogo(context) { - Widget finalWid; - double textFontSize = - SizeConfig.isMobile ? 30 : SizeConfig.textMultiplier * 3; - EdgeInsetsDirectional containerMargin; - if (userType == loginType.knownUser || userType == loginType.unknownUser) { - finalWid = Text( - TranslationBase.of(context).login, - style: TextStyle(fontSize: textFontSize, fontWeight: FontWeight.w800), - ); - } else { - String text1; - String text2; - if (userType == loginType.changePassword) { - text1 = 'Change '; - text2 = 'Password!'; - } - if (userType == loginType.verifyPassword) { - text1 = TranslationBase.of(context).verify1; - text2 = TranslationBase.of(context).yourAccount; - } - if (userType == loginType.verificationMethods) { - text1 = TranslationBase.of(context).choose; - text2 = TranslationBase.of(context).verification; - } - List childrens = [ - Text( - text1, - style: TextStyle(fontSize: textFontSize, fontWeight: FontWeight.w800), - ), - Text( - text2, - style: TextStyle( - color: HexColor('#B8382C'), - fontSize: textFontSize, - fontWeight: FontWeight.w800), - ) - ]; - - if (!SizeConfig.isMobile) { - finalWid = Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: childrens, - ); - } else { - finalWid = Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: childrens, - ); - } - } - if (!SizeConfig.isMobile) { - double start = SizeConfig.realScreenWidth * 0.13; - if (loginType.verifyPassword == userType || - loginType.changePassword == userType || - userType == loginType.verificationMethods) { - start = 0; - } - containerMargin = EdgeInsetsDirectional.fromSTEB(start, 0, 0, 0); - } - - return Container(margin: containerMargin, child: finalWid); - } Container buildDrAppContainer(BuildContext context) { if (userType == loginType.changePassword || @@ -147,10 +66,6 @@ class AuthHeader extends StatelessWidget { return Container(); } return Container( - // margin: SizeConfig.isMobile - // ? null - // : EdgeInsetsDirectional.fromSTEB( - // SizeConfig.realScreenWidth * 0.13, 0, 0, 0), child: Text( "Doctor App", style: TextStyle( diff --git a/lib/widgets/auth/change_password.dart b/lib/widgets/auth/change_password.dart deleted file mode 100644 index 3eb9b975..00000000 --- a/lib/widgets/auth/change_password.dart +++ /dev/null @@ -1,159 +0,0 @@ -import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; - -class ChangePassword extends StatelessWidget { - final changePassFormKey = GlobalKey(); - var changePassFormValues = { - 'currentPass': null, - 'newPass': null, - 'repeatedPass': null - }; - - @override - Widget build(BuildContext context) { - return Form( - key: changePassFormKey, - child: Container( - width: SizeConfig.realScreenWidth * 0.90, - child: - Column(crossAxisAlignment: CrossAxisAlignment.start, children: < - Widget>[ - buildSizedBox(), - TextFormField( - keyboardType: TextInputType.number, - decoration: InputDecoration( - // ts/images/password_icon.png - prefixIcon: Image.asset('assets/images/password_icon.png'), - hintText: 'Current Password', - hintStyle: - TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - borderSide: BorderSide(color: HexColor('#CCCCCC')), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: - BorderSide(color: Theme.of(context).primaryColor), - ) - //BorderRadius.all(Radius.circular(20)); - ), - validator: (value) { - if (value.isEmpty) { - return 'Please enter your Current Password'; - } - return null; - }, - onSaved: (value) { - // changePassFormValues. = value; - }, - ), - buildSizedBox(40), - // buildSizedBox(), - Text( - "New Password", - style: TextStyle( - fontSize: 2.8 * SizeConfig.textMultiplier, - fontWeight: FontWeight.w800), - ), - buildSizedBox(10.0), - // Text() - TextFormField( - keyboardType: TextInputType.number, - decoration: InputDecoration( - // ts/images/password_icon.png - prefixIcon: Image.asset('assets/images/password_icon.png'), - hintText: 'New Password', - hintStyle: - TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - borderSide: BorderSide(color: HexColor('#CCCCCC')), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: - BorderSide(color: Theme.of(context).primaryColor), - ) - //BorderRadius.all(Radius.circular(20)); - ), - validator: (value) { - if (value.isEmpty) { - return 'Please enter your New Password'; - } - return null; - }, - onSaved: (value) { - // userInfo.UserID = value; - }, - ), - buildSizedBox(), - TextFormField( - keyboardType: TextInputType.number, - decoration: InputDecoration( - prefixIcon: Image.asset('assets/images/password_icon.png'), - hintText: 'Repeat Password', - hintStyle: - TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(20)), - borderSide: BorderSide(color: HexColor('#CCCCCC')), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: - BorderSide(color: Theme.of(context).primaryColor), - ) - //BorderRadius.all(Radius.circular(20)); - ), - validator: (value) { - if (value.isEmpty) { - return 'Please enter your Repeat Password'; - } - return null; - }, - onSaved: (value) { - // userInfo.UserID = value; - }, - ), - buildSizedBox(), - RaisedButton( - onPressed:changePass, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 50, - child: Center( - child: Text( - 'Change Password' - .toUpperCase(), - // textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontSize: 2.5 * SizeConfig.textMultiplier), - ), - ), - ), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: BorderSide(width: 0.5, color: HexColor('#CCCCCC'))), - ), - SizedBox( - height: 10, - ), - ]))); - } - - SizedBox buildSizedBox([double height = 20]) { - return SizedBox( - height: height, - ); - } - changePass(){ - if(changePassFormKey.currentState.validate()){ - changePassFormKey.currentState.save(); - // call Api - } - } -} diff --git a/lib/widgets/auth/known_user_login.dart b/lib/widgets/auth/known_user_login.dart deleted file mode 100644 index cbf3c71a..00000000 --- a/lib/widgets/auth/known_user_login.dart +++ /dev/null @@ -1,328 +0,0 @@ -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:hexcolor/hexcolor.dart'; -import 'package:local_auth/error_codes.dart' as auth_error; -import 'package:local_auth/local_auth.dart'; -import 'package:provider/provider.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - -import '../../config/size_config.dart'; -import '../../core/viewModel/auth_view_model.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(); - -class KnownUserLogin extends StatefulWidget { - @override - _KnownUserLoginState createState() => _KnownUserLoginState(); -} - -class _KnownUserLoginState extends State { - Future _prefs = SharedPreferences.getInstance(); - final LocalAuthentication auth = LocalAuthentication(); - - String _authorized = "not Authorized"; - bool _isAuthenticating = false; - Future _loggedUserFuture; - var _loggedUser; - int _loginType = 1; - String _platformImei; - Future _loginTypeFuture; - - 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 getSharedPref() async { - sharedPref.getObj(LOGGED_IN_USER).then((userInfo) { - _loggedUser = userInfo; - }); - sharedPref.getString('platformImei').then((imei) { - _platformImei = imei; - }); - } - - @override - void initState() { - super.initState(); - _loggedUserFuture = getSharedPref(); - } - - @override - Widget build(BuildContext context) { - AuthViewModel authProv = Provider.of(context); - // var imeiModel = {'IMEI': _platformImei}; - // _loginTypeFuture = authProv.selectDeviceImei(imeiModel); - return FutureBuilder( - future: Future.wait([_loggedUserFuture, _loginTypeFuture]), - builder: (BuildContext context, AsyncSnapshot snapshot) { - _loginTypeFuture.then((res) { - _loginType = - 2; //res['SELECTDeviceIMEIbyIMEI_List'][0]['LogInType']; - }).catchError((err) { - print('${err}'); - DrAppToastMsg.showErrorToast(err); - }); - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return DrAppCircularProgressIndeicator(); - default: - if (snapshot.hasError) { - DrAppToastMsg.showErrorToast('Error: ${snapshot.error}'); - return Text('Error: ${snapshot.error}'); - } else { - return Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Stack(children: [ - Container( - decoration: BoxDecoration( - border: Border.all( - color: HexColor('#CCCCCC'), - ), - borderRadius: BorderRadius.circular(50)), - margin: const EdgeInsets.fromLTRB(0, 20.0, 30, 0), - child: Row( - // mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - height: 100, - width: 100, - decoration: new BoxDecoration( - // color: Colors.green, // border color - shape: BoxShape.circle, - border: - Border.all(color: HexColor('#CCCCCC'))), - child: CircleAvatar( - child: Image.asset( - 'assets/images/dr_avatar.png', - fit: BoxFit.cover, - ), - )), - Container( - margin: EdgeInsets.symmetric( - vertical: 3, horizontal: 15), - child: Column( - // mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - _loggedUser['List_MemberInformation'][0] - ['MemberName'], - style: TextStyle( - color: HexColor('515A5D'), - fontSize: - 2.5 * SizeConfig.textMultiplier, - fontWeight: FontWeight.w800), - ), - Text( - 'ENT Spec', - style: TextStyle( - color: HexColor('515A5D'), - fontSize: - 1.5 * SizeConfig.textMultiplier), - ) - ], - ), - ) - ], - ), - ), - Positioned( - top: 7, - right: 70, - child: Image.asset( - 'assets/images/close_icon.png', - fit: BoxFit.cover, - )) - ]), - buildVerificationTypeImageContainer(), - buildButtonsContainer(context) - ], - ); - } - } - }); - } - - Container buildVerificationTypeImageContainer() { - print('${_loginTypeMap[_loginType]}'); - return Container( - height: 200, - width: 200, - child: Center( - child: Image.asset( - _loginTypeMap[_loginType]['imageUrl'], - fit: BoxFit.cover, - ), - )); - } - - // - Container buildButtonsContainer(BuildContext context) { - return Container( - margin: EdgeInsetsDirectional.fromSTEB(0, 0, 30, 0), - width: double.infinity, - child: Column( - children: [ - RaisedButton( - onPressed: _authenticate, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 50, - child: Center( - child: Text( - "Verify using ${_loginTypeMap[_loginType]['name']}" - .toUpperCase(), - // textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontSize: 2.5 * SizeConfig.textMultiplier), - ), - ), - ), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: BorderSide(width: 0.5, color: HexColor('#CCCCCC'))), - ), - SizedBox( - height: 10, - ), - Container( - width: double.infinity, - height: 50, - child: FlatButton( - onPressed: () { - navigateToMoreOption(); - }, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: BorderSide( - width: 1, color: Theme.of(context).primaryColor)), - child: Text( - "More verification Options".toUpperCase(), - style: TextStyle( - color: Theme.of(context).primaryColor, - fontSize: 2.5 * SizeConfig.textMultiplier), - )), - ), - SizedBox( - height: 20, - ), - ], - ), - ); - } - - navigateToMoreOption() { - Navigator.of(context).pushNamed(VERIFICATION_METHODS); - } - - _authenticate() { - if (_loginType == 1) { - _authenticateBySMS(); - } - if (_loginType == 2) { - _authenticateByFingerPrint(); - } - if (_loginType == 3) { - _authenticateByFace(); - } - if (_loginType == 4) { - _authenticateByWhatsApp(); - } - } - - Future _authenticateByFingerPrint() async { - _getAvailableBiometrics(); - bool authenticated = false; - try { - setState(() { - _isAuthenticating = true; - _authorized = 'Authenticating'; - }); - authenticated = await auth.authenticateWithBiometrics( - localizedReason: 'Scan your fingerprint to authenticate', - useErrorDialogs: true, - stickyAuth: false); - setState(() { - _isAuthenticating = false; - _authorized = 'Authenticating'; - }); - } on PlatformException catch (e) { - print(e); - } - if (!mounted) return; - - final String message = authenticated ? 'Authorized' : 'Not Authorized'; - if (message == 'Authorized') { - navigateToHome(); - } - setState(() { - print('_authorized' + _authorized); - _authorized = message; - print('_authorized' + _authorized); - }); - } - - Future _authenticateBySMS() { - print('_authenticateBySMS'); - } - - Future _authenticateByFace() { - print('_authenticateByFace'); - } - - Future _authenticateByWhatsApp() { - print('_authenticateByWhatsApp'); - } - - Future _getAvailableBiometrics() async { - List availableBiometrics; - try { - availableBiometrics = await auth.getAvailableBiometrics(); - } on PlatformException catch (e) { - print(e); - if (e.code == auth_error.notAvailable) { - showErorrMsg("Auth Methods Not Available"); - } else if (e.code == auth_error.passcodeNotSet) { - showErorrMsg("Auth Methods Not passcodeNotSet"); - } else if (e.code == auth_error.permanentlyLockedOut) { - showErorrMsg("Auth Methods Not permanentlyLockedOut"); - } - } - if (!mounted) return; - - setState(() { - print('availableBiometrics $availableBiometrics'); - }); - } - - navigateToHome() { - Navigator.of(context).pushReplacementNamed(HOME); - } - - showErorrMsg(localMsg) { - DrAppToastMsg.showErrorToast(localMsg); - } -} diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart deleted file mode 100644 index a2c200cb..00000000 --- a/lib/widgets/auth/login_form.dart +++ /dev/null @@ -1,312 +0,0 @@ -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; -import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; -import 'package:doctor_app_flutter/util/translations_delegate_base.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/text_fields/app_text_form_field.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:flutter/services.dart'; -import 'package:hexcolor/hexcolor.dart'; -import 'package:provider/provider.dart'; - -import '../../config/shared_pref_kay.dart'; -import '../../config/size_config.dart'; -import '../../core/viewModel/hospital_view_model.dart'; -import '../../models/doctor/user_model.dart'; -import '../../util/dr_app_shared_pref.dart'; -import '../../util/dr_app_toast_msg.dart'; -import '../../util/helpers.dart'; - -DrAppSharedPreferances sharedPref = DrAppSharedPreferances(); -DrAppToastMsg toastMsg = DrAppToastMsg(); -Helpers helpers = Helpers(); - -class LoginForm extends StatefulWidget with DrAppToastMsg { - LoginForm({this.model}); - - final IMEIViewModel model; - - @override - _LoginFormState createState() => _LoginFormState(); -} - -class _LoginFormState extends State { - final loginFormKey = GlobalKey(); - var projectIdController = TextEditingController(); - var projectsList = []; - FocusNode focusPass = FocusNode(); - FocusNode focusProject = FocusNode(); - HospitalViewModel projectsProv; - var userInfo = UserModel(); - @override - void initState() { - super.initState(); - } - - @override - Widget build(BuildContext context) { - projectsProv = Provider.of(context); - return 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, - // keyboardType: TextInputType.number, - textInputAction: TextInputAction.next, - - validator: (value) { - if (value != null && value.isEmpty) { - return TranslationBase.of(context) - .pleaseEnterYourID; - } - return null; - }, - onSaved: (value) { - if (value != null) userInfo.userID = value.trim(); - }, - onChanged: (value) { - if (value != null) 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) { - userInfo.password = value; - }, - onFieldSubmitted: (_) { - focusPass.nextFocus(); - Helpers.showCupertinoPicker(context, projectsList, - 'facilityName', onSelectProject); - }, - onTap: () { - this.getProjects(userInfo.userID); - }, - ) - ])), - 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); - }, - 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'), - fontWeight: FontWeight.bold, - onPressed: () { - login(context, this.widget.model); - }, - )), - ], - ) - ], - ), - ); - //)); - } - - SizedBox buildSizedBox() { - return SizedBox( - height: 20, - ); - } - - login( - context, - model, - ) { - if (loginFormKey.currentState.validate()) { - loginFormKey.currentState.save(); - sharedPref.setInt(PROJECT_ID, userInfo.projectID); - model.login(userInfo).then((res) { - if (model.loginInfo['MessageStatus'] == 1) { - saveObjToString(LOGGED_IN_USER, model.loginInfo); - sharedPref.remove(LAST_LOGIN_USER); - sharedPref.setString(TOKEN, model.loginInfo['LogInTokenID']); - Navigator.of(AppGlobal.CONTEX).pushReplacement(MaterialPageRoute( - builder: (BuildContext context) => VerificationMethodsScreen( - password: userInfo.password, - ))); - } - }); - } - } - - Future setSharedPref(key, value) async { - sharedPref.setString(key, value).then((success) { - print("sharedPref.setString" + success.toString()); - }); - } - - getProjectsList(memberID) { - projectsProv.getProjectsList(memberID).then((res) { - if (res['MessageStatus'] == 1) { - projectsList = res['ProjectInfo']; - setState(() { - userInfo.projectID = projectsList[0]["facilityId"]; - projectIdController.text = projectsList[0]['facilityName']; - }); - } else { - print(res); - } - }); - } - - saveObjToString(String key, value) async { - sharedPref.setObj(key, value); - } - - onSelectProject(index) { - setState(() { - userInfo.projectID = projectsList[index]["facilityId"]; - projectIdController.text = projectsList[index]['facilityName']; - }); - - primaryFocus.unfocus(); - } - - getProjects(value) { - if (value != null && value != '') { - if (projectsList.length == 0) { - getProjectsList(value); - } - } - } -} diff --git a/lib/widgets/auth/show_timer_text.dart b/lib/widgets/auth/show_timer_text.dart deleted file mode 100644 index a418e1b5..00000000 --- a/lib/widgets/auth/show_timer_text.dart +++ /dev/null @@ -1,105 +0,0 @@ -import 'dart:async'; - -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/config/size_config.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; -import 'package:doctor_app_flutter/routes.dart'; -import 'package:doctor_app_flutter/util/helpers.dart'; -import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; -import 'package:provider/provider.dart'; -Helpers helpers = Helpers(); - -class ShowTimerText extends StatefulWidget { - ShowTimerText({Key key, this.model}); - final model; - - @override - _ShowTimerTextState createState() => _ShowTimerTextState(); -} - -class _ShowTimerTextState extends State { - String timerText = (TIMER_MIN - 1).toString() + ':59'; - int min = TIMER_MIN - 1; - int sec = 59; - Timer _timer; - - AuthViewModel authProv; - - resendCode() { - min = TIMER_MIN - 1; - sec = 59; - _timer = Timer.periodic(Duration(seconds: 1), (Timer timer) { - if (min <= 0 && sec <= 0) { - timer.cancel(); - } else { - setState(() { - sec = sec - 1; - if (sec == 0 && min == 0) { - Navigator.of(context).pushNamed(LOGIN); - - min = 0; - sec = 0; - } else if (sec == 0) { - min = min - 1; - sec = 59; - } - timerText = min.toString() + ':' + sec.toString(); - }); - } - }); - } - - @override - void initState() { - super.initState(); - resendCode(); - } - - @override - void dispose() { - _timer.cancel(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - authProv = Provider.of(context); - return Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - InkWell( - onTap: min != 0 || sec != 0 - ? null - : () { - resendActivatioinCode(); - }, - child: Text( - timerText, - style: TextStyle( - fontSize: 3.0 * SizeConfig.textMultiplier, - color: HexColor('#B8382C'), - fontWeight: FontWeight.bold), - ), - ), - ], - ), - ); - } - - resendActivatioinCode() { - authProv - .sendActivationCodeByOtpNotificationType(widget.model) - .then((res) => { - // print('$value') - if (res['MessageStatus'] == 1) - {resendCode()} - else - {Helpers.showErrorToast(res['ErrorEndUserMessage'])} - }) - .catchError((err) { - Helpers.showErrorToast(); - }); - } -} diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart deleted file mode 100644 index 1574d3d4..00000000 --- a/lib/widgets/auth/verfiy_account.dart +++ /dev/null @@ -1,386 +0,0 @@ -import 'dart:async'; - -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; -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/util/translations_delegate_base.dart'; -import 'package:doctor_app_flutter/widgets/auth/show_timer_text.dart'; -import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; -import 'package:provider/provider.dart'; - -import '../../config/size_config.dart'; -import '../../core/viewModel/auth_view_model.dart'; -import '../../routes.dart'; -import '../../util/dr_app_shared_pref.dart'; -import '../../util/dr_app_toast_msg.dart'; -import '../../util/helpers.dart'; -import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; - -DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); -Helpers helpers = Helpers(); - -class VerifyAccount extends StatefulWidget { - VerifyAccount({this.changeLoadingStata}); - - final Function changeLoadingStata; - - @override - _VerifyAccountState createState() => _VerifyAccountState(); -} - -class _VerifyAccountState extends State { - final verifyAccountForm = GlobalKey(); - Map verifyAccountFormValue = { - 'digit1': null, - 'digit2': null, - 'digit3': null, - 'digit4': null, - }; - Future _loggedUserFuture; - var _loggedUser; - AuthViewModel authProv; - bool _isInit = true; - var model; - TextEditingController digit1 = TextEditingController(text: ""); - TextEditingController digit2 = TextEditingController(text: ""); - TextEditingController digit3 = TextEditingController(text: ""); - TextEditingController digit4 = TextEditingController(text: ""); - - @override - void initState() { - super.initState(); - _loggedUserFuture = getSharedPref(); - } - - Future getSharedPref() async { - sharedPref.getObj(LOGGED_IN_USER).then((userInfo) { - _loggedUser = userInfo; - }); - } - - @override - void didChangeDependencies() { - super.didChangeDependencies(); - if (_isInit) { - authProv = Provider.of(context); - final routeArgs = ModalRoute.of(context).settings.arguments as Map; - model = routeArgs['model']; - } - _isInit = false; - } - - @override - Widget build(BuildContext context) { - authProv = Provider.of(context); - final focusD1 = FocusNode(); - final focusD2 = FocusNode(); - final focusD3 = FocusNode(); - final focusD4 = FocusNode(); - return FutureBuilder( - future: Future.wait([_loggedUserFuture]), - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return DrAppCircularProgressIndeicator(); - default: - if (snapshot.hasError) { - DrAppToastMsg.showErrorToast('Error: ${snapshot.error}'); - return Text('Error: ${snapshot.error}'); - } else { - return Form( - key: verifyAccountForm, - child: Container( - width: SizeConfig.realScreenWidth * 0.95, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - buildSizedBox(30), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceAround, - children: [ - Container( - width: SizeConfig.realScreenWidth * 0.20, - child: TextFormField( - textInputAction: TextInputAction.next, - style: buildTextStyle(), - autofocus: true, - maxLength: 1, - controller: digit1, - textAlign: TextAlign.center, - keyboardType: TextInputType.number, - decoration: buildInputDecoration(context), - onSaved: (val) { - verifyAccountFormValue['digit1'] = val; - }, - validator: validateCodeDigit, - onFieldSubmitted: (_) { - FocusScope.of(context) - .requestFocus(focusD2); - }, - onChanged: (val) { - if (val.length == 1) { - FocusScope.of(context) - .requestFocus(focusD2); - } - }, - ), - ), - Container( - width: SizeConfig.realScreenWidth * 0.20, - child: TextFormField( - focusNode: focusD2, - controller: digit2, - textInputAction: TextInputAction.next, - maxLength: 1, - textAlign: TextAlign.center, - style: buildTextStyle(), - keyboardType: TextInputType.number, - decoration: - buildInputDecoration(context), - onSaved: (val) { - verifyAccountFormValue['digit2'] = - val; - }, - onFieldSubmitted: (_) { - FocusScope.of(context) - .requestFocus(focusD3); - }, - onChanged: (val) { - if (val.length == 1) { - FocusScope.of(context) - .requestFocus(focusD3); - } - }, - validator: validateCodeDigit), - ), - Container( - width: SizeConfig.realScreenWidth * 0.20, - child: TextFormField( - focusNode: focusD3, - controller: digit3, - textInputAction: TextInputAction.next, - maxLength: 1, - textAlign: TextAlign.center, - style: buildTextStyle(), - keyboardType: TextInputType.number, - decoration: - buildInputDecoration(context), - onSaved: (val) { - verifyAccountFormValue['digit3'] = - val; - }, - onFieldSubmitted: (_) { - FocusScope.of(context) - .requestFocus(focusD4); - }, - onChanged: (val) { - if (val.length == 1) { - FocusScope.of(context) - .requestFocus(focusD4); - } - }, - validator: validateCodeDigit)), - Container( - width: SizeConfig.realScreenWidth * 0.20, - child: TextFormField( - focusNode: focusD4, - controller: digit4, - maxLength: 1, - textAlign: TextAlign.center, - style: buildTextStyle(), - keyboardType: TextInputType.number, - decoration: - buildInputDecoration(context), - onSaved: (val) { - verifyAccountFormValue['digit4'] = - val; - }, - validator: validateCodeDigit)) - ], - ), - buildSizedBox(20), - buildText(), - buildSizedBox(40), - RaisedButton( - onPressed: () { - verifyAccount( - authProv, widget.changeLoadingStata); - }, - elevation: 0.0, - child: Container( - width: double.infinity, - height: 50, - child: Center( - child: Text( - TranslationBase.of(context).verify, - style: TextStyle( - color: Colors.white, - fontSize: - 3 * SizeConfig.textMultiplier), - ), - ), - ), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - side: BorderSide( - width: 0.5, - color: HexColor('#CCCCCC'))), - ), - buildSizedBox(20), - ShowTimerText(model: model), - buildSizedBox(10), - ]))); - } - } - }); - } - - TextStyle buildTextStyle() { - return TextStyle( - fontSize: SizeConfig.textMultiplier * 3, - ); - } - - String validateCodeDigit(value) { - if (value.isEmpty) { - return 'Please enter your Password'; - } - - return null; - } - - InputDecoration buildInputDecoration(BuildContext context) { - return InputDecoration( - contentPadding: EdgeInsets.only(top: 30, bottom: 30), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10)), - borderSide: BorderSide(color: Colors.black), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide(color: Theme.of(context).primaryColor), - ), - errorBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide(color: Theme.of(context).errorColor), - ), - focusedErrorBorder: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(10.0)), - borderSide: BorderSide(color: Theme.of(context).errorColor), - ), - ); - } - - RichText buildText() { - String medthodName; - switch (model['OTP_SendType']) { - case 1: - medthodName = TranslationBase.of(context).smsBy; - break; - case 2: - medthodName = TranslationBase.of(context).whatsAppBy; - break; - default: - } - var text = RichText( - text: new TextSpan( - style: new TextStyle( - fontSize: 3.0 * SizeConfig.textMultiplier, color: Colors.black), - children: [ - new TextSpan(text: TranslationBase.of(context).youWillReceiveA), - new TextSpan( - text: TranslationBase.of(context).loginCode, - style: TextStyle(fontWeight: FontWeight.w700)), - new TextSpan(text: ' ${medthodName},'), - TextSpan(text: TranslationBase.of(context).pleaseEnterTheCode) - ])); - return text; - } - - SizedBox buildSizedBox([double height = 20]) { - return SizedBox( - height: height, - ); - } - - verifyAccount(AuthViewModel authProv, Function changeLoadingStata) async { - if (verifyAccountForm.currentState.validate()) { - changeLoadingStata(true); - - verifyAccountForm.currentState.save(); - final activationCode = verifyAccountFormValue['digit1'] + - verifyAccountFormValue['digit2'] + - verifyAccountFormValue['digit3'] + - verifyAccountFormValue['digit4']; - - CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = - new CheckActivationCodeRequestModel( - zipCode: _loggedUser['ZipCode'], - mobileNumber: _loggedUser['MobileNumber'], - projectID: await sharedPref.getInt(PROJECT_ID), - logInTokenID: await sharedPref.getString(LOGIN_TOKEN_ID), - activationCode: activationCode, - generalid: "Cs2020@2016\$2958"); - - authProv - .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp) - .then((res) async { - if (res['MessageStatus'] == 1) { - sharedPref.setString(TOKEN, res['AuthenticationTokenID']); - if (res['List_DoctorProfile'] != null) { - loginProcessCompleted( - res['List_DoctorProfile'][0], changeLoadingStata); - } else { - ClinicModel clinic = - ClinicModel.fromJson(res['List_DoctorsClinic'][0]); - getDocProfiles(clinic, changeLoadingStata); - } - } else { - changeLoadingStata(false); - Helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - changeLoadingStata(false); - Helpers.showErrorToast(err); - }); - } - } - - loginProcessCompleted( - Map profile, Function changeLoadingStata) { - var doctor = DoctorProfileModel.fromJson(profile); - authProv.setDoctorProfile(doctor); - sharedPref.setObj(DOCTOR_PROFILE, profile); - this.getDashboard(doctor, changeLoadingStata); - } - - getDashboard(doctor, Function changeLoadingStata) { - changeLoadingStata(false); - Navigator.of(context).pushReplacementNamed(HOME); - } - - getDocProfiles(ClinicModel clinicInfo, Function changeLoadingStata) { - ProfileReqModel docInfo = new ProfileReqModel( - doctorID: clinicInfo.doctorID, - clinicID: clinicInfo.clinicID, - license: true, - projectID: clinicInfo.projectID, - tokenID: '', - languageID: 2); - authProv.getDocProfiles(docInfo.toJson()).then((res) { - if (res['MessageStatus'] == 1) { - loginProcessCompleted(res['DoctorProfileList'][0], changeLoadingStata); - } else { - changeLoadingStata(false); - Helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - changeLoadingStata(false); - Helpers.showErrorToast(err); - }); - } -} diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 48d93f54..91d80a71 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -34,18 +34,11 @@ import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); -/* - *@author: Elham Rababah - *@Date:4/7/2020 - *@param: - *@return: - *@desc: Verification Methods widget - */ class VerificationMethods extends StatefulWidget { - VerificationMethods({this.changeLoadingStata, this.password}); + VerificationMethods({this.changeLoadingState, this.password}); final password; - final Function changeLoadingStata; + final Function changeLoadingState; @override _VerificationMethodsState createState() => _VerificationMethodsState(); @@ -62,7 +55,6 @@ class _VerificationMethodsState extends State { ProjectViewModel projectsProvider; var isMoreOption = false; var onlySMSBox = false; - static BuildContext _context; var loginTokenID; bool authenticated; @@ -254,11 +246,6 @@ class _VerificationMethodsState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ - // Expanded( - // child: - // getButton(3, authProv)), - // Expanded( - // child: getButton(4, authProv)) Expanded( child: InkWell( onTap: () => { @@ -343,7 +330,7 @@ class _VerificationMethodsState extends State { oTPSendType, AuthViewModel authProv) async { // TODO : build enum for verfication method if (oTPSendType == 1 || oTPSendType == 2) { - widget.changeLoadingStata(true); + widget.changeLoadingState(true); int projectID = await sharedPref.getInt(PROJECT_ID); ActivationCodeModel activationCodeModel = ActivationCodeModel( facilityId: projectID, @@ -371,7 +358,7 @@ class _VerificationMethodsState extends State { } }).catchError((err) { print('$err'); - widget.changeLoadingStata(false); + widget.changeLoadingState(false); Helpers.showErrorToast(); }); @@ -393,9 +380,7 @@ class _VerificationMethodsState extends State { sendActivationCodeVerificationScreen( oTPSendType, AuthViewModel authProv) async { - // TODO : build enum for verfication method - //if (oTPSendType == 1 || oTPSendType == 2) { - widget.changeLoadingStata(true); + widget.changeLoadingState(true); ActivationCodeModel2 activationCodeModel = ActivationCodeModel2( iMEI: user.iMEI, facilityId: user.projectID, @@ -418,7 +403,7 @@ class _VerificationMethodsState extends State { VIDA_REFRESH_TOKEN_ID, res["VidaRefreshTokenID"]); sharedPref.setString(LOGIN_TOKEN_ID, res["LogInTokenID"]); if (oTPSendType == 1 || oTPSendType == 2) { - widget.changeLoadingStata(false); + widget.changeLoadingState(false); this.startSMSService(oTPSendType, authProv); } else { checkActivationCode(authProv); @@ -429,7 +414,7 @@ class _VerificationMethodsState extends State { } }).catchError((err) { print('$err'); - widget.changeLoadingStata(false); + widget.changeLoadingState(false); Helpers.showErrorToast(); }); @@ -557,12 +542,6 @@ class _VerificationMethodsState extends State { } }, child: - // RoundedContainer( - // backgroundColor: checkIfBiometricAvailable(BiometricType.face) - // ? Colors.white - // : Colors.white.withOpacity(.7), - // borderColor: Colors.grey, - // showBorder: false, Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), @@ -601,9 +580,6 @@ class _VerificationMethodsState extends State { }) }, child: Container( - // backgroundColor: Colors.white, - // borderColor: Colors.grey, - // showBorder: false, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Colors.white, @@ -630,7 +606,6 @@ class _VerificationMethodsState extends State { TranslationBase.of(context).moreVerification, fontSize: 14, fontWeight: FontWeight.w600, - // textAlign: TextAlign.center, ) ], ), @@ -743,7 +718,7 @@ class _VerificationMethodsState extends State { this.checkActivationCode(authProv, value: value); }, () => { - widget.changeLoadingStata(false), + widget.changeLoadingState(false), print('Faild..'), }, ).displayDialog(context); @@ -798,7 +773,7 @@ class _VerificationMethodsState extends State { authProv .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp) .then((res) async { - widget.changeLoadingStata(false); + widget.changeLoadingState(false); if (res['MessageStatus'] == 1) { sharedPref.setString(TOKEN, res['AuthenticationTokenID']); if (res['List_DoctorProfile'] != null) { @@ -846,11 +821,11 @@ class _VerificationMethodsState extends State { if (res['MessageStatus'] == 1) { loginProcessCompleted(res['DoctorProfileList'][0], authProv); } else { - // changeLoadingStata(false); + // changeLoadingState(false); Helpers.showErrorToast(res['ErrorEndUserMessage']); } }).catchError((err) { - // changeLoadingStata(false); + // changeLoadingState(false); Helpers.showErrorToast(err); }); } From c72ef3f58569cefd27cb685a076c847c9065c82c Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 3 May 2021 17:16:29 +0300 Subject: [PATCH 02/28] finish refactoring login --- lib/screens/auth/login_screen.dart | 31 ++++++++++++++++-------------- lib/screens/home/home_screen.dart | 2 -- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index b49b492f..1d27e31e 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -270,6 +270,8 @@ class _LoginsreenState extends State { return null; }, onSaved: (value) { + if (value != + null) setState(() { userInfo .password = @@ -278,6 +280,8 @@ class _LoginsreenState extends State { }, onChanged: (value){ + if (value != + null) setState(() { userInfo .password = @@ -456,19 +460,21 @@ class _LoginsreenState extends State { await model.login(userInfo); if (model.state == ViewState.ErrorLocal) { Helpers.showErrorToast(model.error); + } else { if (model.loginInfo['MessageStatus'] == 1) { saveObjToString(LOGGED_IN_USER, model.loginInfo); sharedPref.remove(LAST_LOGIN_USER); sharedPref.setString(TOKEN, model.loginInfo['LogInTokenID']); - Navigator.of(AppGlobal.CONTEX).pushReplacement(MaterialPageRoute( + GifLoaderDialogUtils.hideDialog(context); + + Navigator.of(context).pushReplacement(MaterialPageRoute( builder: (BuildContext context) => VerificationMethodsScreen( password: userInfo.password, ))); } } - GifLoaderDialogUtils.hideDialog(context); } } @@ -492,20 +498,17 @@ class _LoginsreenState extends State { primaryFocus.unfocus(); } - getProjects(memberID, IMEIViewModel model) { + getProjects(memberID, IMEIViewModel model)async { if (memberID != null && memberID != '') { if (projectsList.length == 0) { - model.getHospitalsList(memberID).then((res) { - if (res['MessageStatus'] == 1) { - projectsList = res['ProjectInfo']; - setState(() { - userInfo.projectID = projectsList[0]["facilityId"]; - projectIdController.text = projectsList[0]['facilityName']; - }); - } else { - print(res); - } - }); + await model.getHospitalsList(memberID); + if(model.state == ViewState.Idle) { + projectsList = model.hospitals; + setState(() { + userInfo.projectID = projectsList[0]["facilityId"]; + projectIdController.text = projectsList[0]['facilityName']; + }); + } } } } diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 1ecbe637..1fc4c795 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -61,7 +61,6 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); - HospitalViewModel hospitalProvider; AuthViewModel authProvider; bool isLoading = false; ProjectViewModel projectsProvider; @@ -108,7 +107,6 @@ class _HomeScreenState extends State { @override Widget build(BuildContext context) { myContext = context; - hospitalProvider = Provider.of(context); authProvider = Provider.of(context); projectsProvider = Provider.of(context); FocusScopeNode currentFocus = FocusScope.of(context); From b20d936933c5249dffaec464276cf0a3c9b1202f Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Tue, 4 May 2021 13:09:48 +0300 Subject: [PATCH 03/28] fix hospitals_service --- .../get_hospitals_response_model.dart | 22 +++++++++++++++++++ .../service/hospitals/hospitals_service.dart | 8 +++++-- lib/core/viewModel/auth_view_model.dart | 17 -------------- lib/core/viewModel/imei_view_model.dart | 16 ++++++++++++-- lib/screens/auth/login_screen.dart | 12 +++++----- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/lib/core/model/hospitals/get_hospitals_response_model.dart b/lib/core/model/hospitals/get_hospitals_response_model.dart index e69de29b..edbc3fe5 100644 --- a/lib/core/model/hospitals/get_hospitals_response_model.dart +++ b/lib/core/model/hospitals/get_hospitals_response_model.dart @@ -0,0 +1,22 @@ +class GetHospitalsResponseModel { + String facilityGroupId; + int facilityId; + String facilityName; + + GetHospitalsResponseModel( + {this.facilityGroupId, this.facilityId, this.facilityName}); + + GetHospitalsResponseModel.fromJson(Map json) { + facilityGroupId = json['facilityGroupId']; + facilityId = json['facilityId']; + facilityName = json['facilityName']; + } + + Map toJson() { + final Map data = new Map(); + data['facilityGroupId'] = this.facilityGroupId; + data['facilityId'] = this.facilityId; + data['facilityName'] = this.facilityName; + return data; + } +} diff --git a/lib/core/service/hospitals/hospitals_service.dart b/lib/core/service/hospitals/hospitals_service.dart index 2c670e09..f8a7579d 100644 --- a/lib/core/service/hospitals/hospitals_service.dart +++ b/lib/core/service/hospitals/hospitals_service.dart @@ -1,17 +1,21 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; +import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; class HospitalsService extends BaseService { -List hospitals; +List hospitals =List(); Future getHospitals(GetHospitalsRequestModel getHospitalsRequestModel) async { hasError = false; await baseAppClient.post( GET_PROJECTS, onSuccess: (dynamic response, int statusCode) { - hospitals = response['ProjectInfo']; + hospitals.clear(); + response['ProjectInfo'].forEach((hospital) { + hospitals.add(GetHospitalsResponseModel.fromJson(hospital)); + }); }, onFailure: (String error, int statusCode) { hasError = true; diff --git a/lib/core/viewModel/auth_view_model.dart b/lib/core/viewModel/auth_view_model.dart index 48f4661d..c1410fe6 100644 --- a/lib/core/viewModel/auth_view_model.dart +++ b/lib/core/viewModel/auth_view_model.dart @@ -56,23 +56,6 @@ class AuthViewModel extends BaseViewModel { } } - // Future login(UserModel userInfo) async { - // try { - // dynamic localRes; - // - // await baseAppClient.post(LOGIN_URL, - // onSuccess: (dynamic response, int statusCode) { - // localRes = response; - // }, onFailure: (String error, int statusCode) { - // throw error; - // }, body: userInfo.toJson()); - // - // return Future.value(localRes); - // } catch (error) { - // print(error); - // throw error; - // } - // } Future insertDeviceImei(request) async { var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); diff --git a/lib/core/viewModel/imei_view_model.dart b/lib/core/viewModel/imei_view_model.dart index ba462553..6499cfac 100644 --- a/lib/core/viewModel/imei_view_model.dart +++ b/lib/core/viewModel/imei_view_model.dart @@ -1,10 +1,12 @@ import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; +import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/service/auth_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; +import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; @@ -13,7 +15,7 @@ class IMEIViewModel extends BaseViewModel { HospitalsService _hospitalsService = locator(); List get imeiDetails => _authService.dashboardItemsList; - List get hospitals => _hospitalsService.hospitals; + List get hospitals => _hospitalsService.hospitals; get loginInfo => _authService.loginInfo; Future selectDeviceImei(imei) async { setState(ViewState.Busy); @@ -35,10 +37,20 @@ class IMEIViewModel extends BaseViewModel { setState(ViewState.Idle); } + Future sendActivationCodeVerificationScreen(ActivationCodeModel2 activationCodeModel) async { + setState(ViewState.BusyLocal); + // await _authService.sendActivationCodeVerificationScreen(userInfo); + if (_authService.hasError) { + error = _authService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + + Future getHospitalsList(memberID) async { GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); getHospitalsRequestModel.memberID = memberID; - // setState(ViewState.Busy); await _hospitalsService.getHospitals(getHospitalsRequestModel); if (_hospitalsService.hasError) { error = _hospitalsService.error; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 1d27e31e..d7784881 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -5,8 +5,8 @@ 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/auth_service.dart'; -import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; @@ -47,7 +47,7 @@ class _LoginsreenState extends State { //TODO change AppTextFormField to AppTextFormFieldCustom final loginFormKey = GlobalKey(); var projectIdController = TextEditingController(); - var projectsList = []; + List projectsList = []; FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); // HospitalViewModel hospitalViewModel; @@ -491,8 +491,8 @@ class _LoginsreenState extends State { onSelectProject(index) { setState(() { - userInfo.projectID = projectsList[index]["facilityId"]; - projectIdController.text = projectsList[index]['facilityName']; + userInfo.projectID = projectsList[index].facilityId; + projectIdController.text = projectsList[index].facilityName; }); primaryFocus.unfocus(); @@ -505,8 +505,8 @@ class _LoginsreenState extends State { if(model.state == ViewState.Idle) { projectsList = model.hospitals; setState(() { - userInfo.projectID = projectsList[0]["facilityId"]; - projectIdController.text = projectsList[0]['facilityName']; + userInfo.projectID = projectsList[0].facilityId; + projectIdController.text = projectsList[0].facilityName; }); } } From 9f1f06f2fc1cc4c2ba707579d46052f8973169bd Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Tue, 4 May 2021 16:02:04 +0300 Subject: [PATCH 04/28] refactor verification methods services --- lib/core/service/auth_service.dart | 78 ++++++++ lib/core/viewModel/auth_view_model.dart | 59 +----- lib/core/viewModel/imei_view_model.dart | 38 +++- ...n_code_for_verification_screen_model.dart} | 6 +- lib/screens/auth/login_screen.dart | 1 + .../auth/verification_methods_screen.dart | 49 ++--- lib/widgets/auth/verification_methods.dart | 168 +++++++++--------- 7 files changed, 227 insertions(+), 172 deletions(-) rename lib/models/auth/{send_activation_code_model2.dart => activation_code_for_verification_screen_model.dart} (91%) diff --git a/lib/core/service/auth_service.dart b/lib/core/service/auth_service.dart index ec56bed7..bdc500d0 100644 --- a/lib/core/service/auth_service.dart +++ b/lib/core/service/auth_service.dart @@ -1,13 +1,30 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; +import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; +import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; +import 'package:provider/provider.dart'; class AuthService extends BaseService { List _imeiDetails = []; List get dashboardItemsList => _imeiDetails; + //TODO Change this to models Map _loginInfo = {}; Map get loginInfo => _loginInfo; + Map _activationCodeVerificationScreenRes = {}; + + Map get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes; + + Map _activationCodeForDoctorAppRes = {}; + + Map get activationCodeForDoctorAppRes => _activationCodeForDoctorAppRes; + Map _checkActivationCodeForDoctorAppRes = {}; + + Map get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; Future selectDeviceImei(imei) async { try { // dynamic localRes; @@ -45,4 +62,65 @@ class AuthService extends BaseService { } } + + Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async { + hasError = false; + _activationCodeVerificationScreenRes = {}; + try { + await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_VERIFICATION_SCREEN, + onSuccess: (dynamic response, int statusCode) { + _activationCodeVerificationScreenRes = response; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: activationCodeModel.toJson()); + } catch (error) { + hasError = true; + super.error = error; + } + + } + + Future sendActivationCodeForDoctorApp(ActivationCodeModel activationCodeModel)async { + hasError = false; + _activationCodeForDoctorAppRes = {}; + try { + await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_DOCTOR_APP, + onSuccess: (dynamic response, int statusCode) { + _activationCodeForDoctorAppRes = response; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: activationCodeModel.toJson()); + } catch (error) { + hasError = true; + super.error = error; + } + } + + Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel)async { + hasError = false; + _checkActivationCodeForDoctorAppRes = {}; + try { + await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP, + onSuccess: (dynamic response, int statusCode) { + // TODO improve the logic here + Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear(); + _checkActivationCodeForDoctorAppRes = response; + Provider.of(AppGlobal.CONTEX, listen: false).selectedClinicName = + ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; + + response['List_DoctorsClinic'].forEach((v) { + Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.add(new ClinicModel.fromJson(v)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: checkActivationCodeRequestModel.toJson()); + } catch (error) { + hasError = true; + super.error = error; + } + + } } diff --git a/lib/core/viewModel/auth_view_model.dart b/lib/core/viewModel/auth_view_model.dart index c1410fe6..add5db86 100644 --- a/lib/core/viewModel/auth_view_model.dart +++ b/lib/core/viewModel/auth_view_model.dart @@ -6,7 +6,7 @@ import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; -import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; +import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; @@ -95,46 +95,6 @@ class AuthViewModel extends BaseViewModel { } } - Future sendActivationCodeForDoctorApp( - ActivationCodeModel activationCodeModel) async { - try { - var localRes; - await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_DOCTOR_APP, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - }, onFailure: (String error, int statusCode) { - throw error; - }, body: activationCodeModel.toJson()); - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } - - Future checkActivationCodeForDoctorApp( - CheckActivationCodeRequestModel checkActivationCodeRequestModel) async { - try { - dynamic localRes; - await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - selectedClinicName = - ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; - - response['List_DoctorsClinic'].forEach((v) { - doctorsClinicList.add(new ClinicModel.fromJson(v)); - }); - }, onFailure: (String error, int statusCode) { - throw error; - }, body: checkActivationCodeRequestModel.toJson()); - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } - Future getDocProfiles(docInfo, {bool allowChangeProfile = true}) async { try { @@ -158,21 +118,4 @@ class AuthViewModel extends BaseViewModel { throw error; } } - - Future sendActivationCodeVerificationScreen( - ActivationCodeModel2 activationCodeModel) async { - try { - var localRes; - await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_VERIFICATION_SCREEN, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - }, onFailure: (String error, int statusCode) { - throw error; - }, body: activationCodeModel.toJson()); - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } } diff --git a/lib/core/viewModel/imei_view_model.dart b/lib/core/viewModel/imei_view_model.dart index 6499cfac..09bfe8b3 100644 --- a/lib/core/viewModel/imei_view_model.dart +++ b/lib/core/viewModel/imei_view_model.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/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; @@ -6,9 +7,14 @@ import 'package:doctor_app_flutter/core/service/auth_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; -import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; +import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; +import 'package:provider/provider.dart'; + +import 'auth_view_model.dart'; class IMEIViewModel extends BaseViewModel { AuthService _authService = locator(); @@ -17,6 +23,10 @@ class IMEIViewModel extends BaseViewModel { List get imeiDetails => _authService.dashboardItemsList; List get hospitals => _hospitalsService.hospitals; get loginInfo => _authService.loginInfo; + get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; + get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; + get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; + Future selectDeviceImei(imei) async { setState(ViewState.Busy); await _authService.selectDeviceImei(imei); @@ -37,9 +47,19 @@ class IMEIViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future sendActivationCodeVerificationScreen(ActivationCodeModel2 activationCodeModel) async { + Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async { + setState(ViewState.BusyLocal); + await _authService.sendActivationCodeVerificationScreen(activationCodeModel); + if (_authService.hasError) { + error = _authService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + + Future sendActivationCodeForDoctorApp(ActivationCodeModel activationCodeModel) async { setState(ViewState.BusyLocal); - // await _authService.sendActivationCodeVerificationScreen(userInfo); + await _authService.sendActivationCodeForDoctorApp(activationCodeModel); if (_authService.hasError) { error = _authService.error; setState(ViewState.ErrorLocal); @@ -47,6 +67,18 @@ class IMEIViewModel extends BaseViewModel { setState(ViewState.Idle); } + Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel) async { + setState(ViewState.BusyLocal); + await _authService.checkActivationCodeForDoctorApp(checkActivationCodeRequestModel); + if (_authService.hasError) { + error = _authService.error; + setState(ViewState.ErrorLocal); + } else { + setState(ViewState.Idle); + + } + } + Future getHospitalsList(memberID) async { GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); diff --git a/lib/models/auth/send_activation_code_model2.dart b/lib/models/auth/activation_code_for_verification_screen_model.dart similarity index 91% rename from lib/models/auth/send_activation_code_model2.dart rename to lib/models/auth/activation_code_for_verification_screen_model.dart index 68a90c85..28cc58db 100644 --- a/lib/models/auth/send_activation_code_model2.dart +++ b/lib/models/auth/activation_code_for_verification_screen_model.dart @@ -1,4 +1,4 @@ -class ActivationCodeModel2 { +class ActivationCodeForVerificationScreenModel { int oTPSendType; String mobileNumber; String zipCode; @@ -12,7 +12,7 @@ class ActivationCodeModel2 { String vidaAuthTokenID; String vidaRefreshTokenID; String iMEI; - ActivationCodeModel2( + ActivationCodeForVerificationScreenModel( {this.oTPSendType, this.mobileNumber, this.zipCode, @@ -27,7 +27,7 @@ class ActivationCodeModel2 { this.vidaRefreshTokenID, this.iMEI}); - ActivationCodeModel2.fromJson(Map json) { + ActivationCodeForVerificationScreenModel.fromJson(Map json) { oTPSendType = json['OTP_SendType']; mobileNumber = json['MobileNumber']; zipCode = json['ZipCode']; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index d7784881..5e069a2a 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -459,6 +459,7 @@ class _LoginsreenState extends State { sharedPref.setInt(PROJECT_ID, userInfo.projectID); await model.login(userInfo); if (model.state == ViewState.ErrorLocal) { + GifLoaderDialogUtils.hideDialog(context); Helpers.showErrorToast(model.error); } else { diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 7503a70e..a83db25c 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -1,3 +1,5 @@ +import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; +import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -25,27 +27,30 @@ class _VerificationMethodsScreenState extends State { @override Widget build(BuildContext context) { - return AppScaffold( - isLoading: _isLoading, - isShowAppBar: false, - isHomeIcon: false, - backgroundColor: HexColor('#F8F8F8'), - body: ListView(children: [ - Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 50, - ), - VerificationMethods( - password: widget.password, - changeLoadingState: changeLoadingState, - ), - ], - ), - ), - ])); + return BaseView( + onModelReady: (model) async {}, + builder: (_, model, w) => AppScaffold( + isLoading: _isLoading, + isShowAppBar: false, + isHomeIcon: false, + backgroundColor: HexColor('#F8F8F8'), + body: ListView(children: [ + Container( + margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 50, + ), + VerificationMethods( + password: widget.password, + changeLoadingState: changeLoadingState, + model:model + ), + ], + ), + ), + ]))); } } diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 91d80a71..dc95f6dd 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -1,11 +1,13 @@ import 'dart:io' show Platform; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; +import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; -import 'package:doctor_app_flutter/models/auth/send_activation_code_model2.dart'; +import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; 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'; @@ -15,6 +17,7 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/otp/sms-popup.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/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -35,10 +38,11 @@ DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); class VerificationMethods extends StatefulWidget { - VerificationMethods({this.changeLoadingState, this.password}); + VerificationMethods({this.changeLoadingState, this.password, this.model}); final password; final Function changeLoadingState; + final IMEIViewModel model; @override _VerificationMethodsState createState() => _VerificationMethodsState(); @@ -330,8 +334,10 @@ class _VerificationMethodsState extends State { oTPSendType, AuthViewModel authProv) async { // TODO : build enum for verfication method if (oTPSendType == 1 || oTPSendType == 2) { - widget.changeLoadingState(true); + GifLoaderDialogUtils.showMyDialog(context); + int projectID = await sharedPref.getInt(PROJECT_ID); + // TODO create model for _loggedUser; ActivationCodeModel activationCodeModel = ActivationCodeModel( facilityId: projectID, memberID: _loggedUser['List_MemberInformation'][0]['MemberID'], @@ -339,49 +345,34 @@ class _VerificationMethodsState extends State { mobileNumber: _loggedUser['MobileNumber'], otpSendType: oTPSendType.toString(), password: widget.password); - - try { - authProv - .sendActivationCodeForDoctorApp(activationCodeModel) - .then((res) { - if (res['MessageStatus'] == 1) { - print("VerificationCode : " + res["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, res["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, res["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, res["LogInTokenID"]); - sharedPref.setString(PASSWORD, widget.password); - this.startSMSService(oTPSendType, authProv); - } else { - print(res['ErrorEndUserMessage']); - Helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - print('$err'); - widget.changeLoadingState(false); - - Helpers.showErrorToast(); - }); - } catch (e) {} + await widget.model + .sendActivationCodeForDoctorApp(activationCodeModel); + if(widget.model.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(widget.model.error); + GifLoaderDialogUtils.hideDialog(context); + }else{ + print("VerificationCode : " + widget.model.activationCodeForDoctorAppRes["VerificationCode"]); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["VidaAuthTokenID"]); + sharedPref.setString( + VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]); + sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["LogInTokenID"]); + sharedPref.setString(PASSWORD, widget.password); + GifLoaderDialogUtils.hideDialog(context); + this.startSMSService(oTPSendType, authProv); + } } else { // TODO route to this page with parameters to inicate we should present 2 option if (Platform.isAndroid && oTPSendType == 3) { Helpers.showErrorToast('Your device not support this feature'); } else { - // Navigator.of(context).push(MaterialPageRoute( - // builder: (BuildContext context) => - // VerificationMethodsScreen(password: widget.password,))); - - // Navigator.of(context).pushNamed(VERIFICATION_METHODS, - // arguments: {'verificationMethod': oTPSendType}); } } } sendActivationCodeVerificationScreen( oTPSendType, AuthViewModel authProv) async { - widget.changeLoadingState(true); - ActivationCodeModel2 activationCodeModel = ActivationCodeModel2( + GifLoaderDialogUtils.showMyDialog(context); + ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel( iMEI: user.iMEI, facilityId: user.projectID, memberID: user.doctorID, @@ -392,37 +383,25 @@ class _VerificationMethodsState extends State { vidaAuthTokenID: user.vidaAuthTokenID, vidaRefreshTokenID: user.vidaRefreshTokenID); - try { - authProv - .sendActivationCodeVerificationScreen(activationCodeModel) - .then((res) { - if (res['MessageStatus'] == 1) { - print("VerificationCode : " + res["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, res["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, res["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, res["LogInTokenID"]); - if (oTPSendType == 1 || oTPSendType == 2) { - widget.changeLoadingState(false); - this.startSMSService(oTPSendType, authProv); - } else { - checkActivationCode(authProv); - } + await widget.model + .sendActivationCodeVerificationScreen(activationCodeModel); + + if(widget.model.state == ViewState.ErrorLocal) { + GifLoaderDialogUtils.hideDialog(context); + Helpers.showErrorToast(widget.model.error); + } else { + print("VerificationCode : " + widget.model.activationCodeVerificationScreenRes["VerificationCode"]); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); + sharedPref.setString( + VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); + sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["LogInTokenID"]); + if (oTPSendType == 1 || oTPSendType == 2) { + GifLoaderDialogUtils.hideDialog(context); + this.startSMSService(oTPSendType, authProv); } else { - print(res['ErrorEndUserMessage']); - Helpers.showErrorToast(res['ErrorEndUserMessage']); + checkActivationCode(authProv); } - }).catchError((err) { - print('$err'); - widget.changeLoadingState(false); - - Helpers.showErrorToast(); - }); - } catch (e) {} - // } - // else { - // checkActivationCode(authProv); - // } + } } Widget getButton(flag, authProv) { @@ -741,7 +720,7 @@ class _VerificationMethodsState extends State { stickyAuth: true, iOSAuthStrings: iosStrings); } on PlatformException catch (e) { - DrAppToastMsg.showErrorToast(e); + DrAppToastMsg.showErrorToast(e.toString()); } if (!mounted) return; if (user != null && (user.logInTypeID == 3 || user.logInTypeID == 4)) { @@ -769,30 +748,47 @@ class _VerificationMethodsState extends State { activationCode: value ?? '0000', oTPSendType: await sharedPref.getInt(OTP_TYPE), generalid: "Cs2020@2016\$2958"); + await widget.model.checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp); - authProv - .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp) - .then((res) async { - widget.changeLoadingState(false); - if (res['MessageStatus'] == 1) { - sharedPref.setString(TOKEN, res['AuthenticationTokenID']); - if (res['List_DoctorProfile'] != null) { - loginProcessCompleted(res['List_DoctorProfile'][0], authProv); - sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']); - } else { - sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']); - ClinicModel clinic = - ClinicModel.fromJson(res['List_DoctorsClinic'][0]); - getDocProfiles(clinic, authProv); - } + if(widget.model.state == ViewState.ErrorLocal){ + Navigator.pop(context); + Helpers.showErrorToast(widget.model.error); + } else { + sharedPref.setString(TOKEN, widget.model.checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); + if (widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != null) { + loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0], authProv); + sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); } else { - Navigator.pop(context); - Helpers.showErrorToast(res['ErrorEndUserMessage']); + sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + ClinicModel clinic = + ClinicModel.fromJson(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); + getDocProfiles(clinic, authProv); } - }).catchError((err) { - Navigator.pop(context); - Helpers.showErrorToast(err); - }); + } + + // authProv + // .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp) + // .then((res) async { + // widget.changeLoadingState(false); + // if (res['MessageStatus'] == 1) { + // sharedPref.setString(TOKEN, res['AuthenticationTokenID']); + // if (res['List_DoctorProfile'] != null) { + // loginProcessCompleted(res['List_DoctorProfile'][0], authProv); + // sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']); + // } else { + // sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']); + // ClinicModel clinic = + // ClinicModel.fromJson(res['List_DoctorsClinic'][0]); + // getDocProfiles(clinic, authProv); + // } + // } else { + // Navigator.pop(context); + // Helpers.showErrorToast(res['ErrorEndUserMessage']); + // } + // }).catchError((err) { + // Navigator.pop(context); + // Helpers.showErrorToast(err); + // }); } loginProcessCompleted(Map profile, authProv) { From 15bead5164209dab1a707ea965541293cc01c547 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Tue, 4 May 2021 16:48:39 +0300 Subject: [PATCH 05/28] add insert IMEI service --- lib/core/service/auth_service.dart | 22 ++++++++++++ lib/core/viewModel/auth_view_model.dart | 39 --------------------- lib/core/viewModel/imei_view_model.dart | 45 ++++++++++++++++++++++--- lib/screens/home/home_screen.dart | 13 ++++--- 4 files changed, 71 insertions(+), 48 deletions(-) diff --git a/lib/core/service/auth_service.dart b/lib/core/service/auth_service.dart index bdc500d0..f4d0e096 100644 --- a/lib/core/service/auth_service.dart +++ b/lib/core/service/auth_service.dart @@ -1,5 +1,6 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; +import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; @@ -25,6 +26,9 @@ class AuthService extends BaseService { Map _checkActivationCodeForDoctorAppRes = {}; Map get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; + Map _insertDeviceImeiRes = {}; + + Map get insertDeviceImeiRes => _insertDeviceImeiRes; Future selectDeviceImei(imei) async { try { // dynamic localRes; @@ -123,4 +127,22 @@ class AuthService extends BaseService { } } + + + Future insertDeviceImei(InsertIMEIDetailsModel insertIMEIDetailsModel)async { + hasError = false; + _insertDeviceImeiRes = {}; + try { + await baseAppClient.post(INSERT_DEVICE_IMEI, + onSuccess: (dynamic response, int statusCode) { + _insertDeviceImeiRes = response; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: insertIMEIDetailsModel.toJson()); + } catch (error) { + hasError = true; + super.error = error; + } + } } diff --git a/lib/core/viewModel/auth_view_model.dart b/lib/core/viewModel/auth_view_model.dart index add5db86..6eb85ebb 100644 --- a/lib/core/viewModel/auth_view_model.dart +++ b/lib/core/viewModel/auth_view_model.dart @@ -56,45 +56,6 @@ class AuthViewModel extends BaseViewModel { } } - - Future insertDeviceImei(request) async { - var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); - var user = await sharedPref.getObj(LAST_LOGIN_USER); - if (user != null) { - user = GetIMEIDetailsModel.fromJson(user); - } - request['IMEI'] = DEVICE_TOKEN; - request['LogInTypeID'] = await sharedPref.getInt(OTP_TYPE); - request['BioMetricEnabled'] = true; - request['MobileNo'] = - loggedIn != null ? loggedIn['MobileNumber'] : user.mobile; - InsertIMEIDetailsModel nRequest = InsertIMEIDetailsModel.fromJson(request); - nRequest.genderDescription = request['Gender_Description']; - nRequest.genderDescriptionN = request['Gender_DescriptionN']; - nRequest.genderDescriptionN = request['Gender_DescriptionN']; - nRequest.titleDescription = request['Title_Description']; - nRequest.titleDescriptionN = request['Title_DescriptionN']; - nRequest.projectID = await sharedPref.getInt(PROJECT_ID); - nRequest.doctorID = loggedIn != null - ? loggedIn['List_MemberInformation'][0]['MemberID'] - : user.doctorID; - nRequest.outSA = loggedIn != null ? loggedIn['PatientOutSA'] : user.outSA; - nRequest.vidaAuthTokenID = await sharedPref.getString(VIDA_AUTH_TOKEN_ID); - nRequest.vidaRefreshTokenID = - await sharedPref.getString(VIDA_REFRESH_TOKEN_ID); - nRequest.password = await sharedPref.getString(PASSWORD); - try { - var localRes; - await baseAppClient.post(INSERT_DEVICE_IMEI, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - }, onFailure: (String error, int statusCode) {}, body: nRequest.toJson()); - return Future.value(localRes); - } catch (error) { - throw error; - } - } - Future getDocProfiles(docInfo, {bool allowChangeProfile = true}) async { try { diff --git a/lib/core/viewModel/imei_view_model.dart b/lib/core/viewModel/imei_view_model.dart index 09bfe8b3..90fb3578 100644 --- a/lib/core/viewModel/imei_view_model.dart +++ b/lib/core/viewModel/imei_view_model.dart @@ -1,8 +1,10 @@ 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/viewstate.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; +import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/service/auth_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; @@ -11,10 +13,6 @@ import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; -import 'package:doctor_app_flutter/util/helpers.dart'; -import 'package:provider/provider.dart'; - -import 'auth_view_model.dart'; class IMEIViewModel extends BaseViewModel { AuthService _authService = locator(); @@ -37,6 +35,45 @@ class IMEIViewModel extends BaseViewModel { setState(ViewState.Idle); } + Future insertDeviceImei() async { + + var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); + var user = await sharedPref.getObj(LAST_LOGIN_USER); + if (user != null) { + user = GetIMEIDetailsModel.fromJson(user); + } + + var profileInfo = await sharedPref.getObj(DOCTOR_PROFILE); + + profileInfo['IMEI'] = DEVICE_TOKEN; + profileInfo['LogInTypeID'] = await sharedPref.getInt(OTP_TYPE); + profileInfo['BioMetricEnabled'] = true; + profileInfo['MobileNo'] = + loggedIn != null ? loggedIn['MobileNumber'] : user.mobile; + InsertIMEIDetailsModel insertIMEIDetailsModel = InsertIMEIDetailsModel.fromJson(profileInfo); + insertIMEIDetailsModel.genderDescription = profileInfo['Gender_Description']; + insertIMEIDetailsModel.genderDescriptionN = profileInfo['Gender_DescriptionN']; + insertIMEIDetailsModel.genderDescriptionN = profileInfo['Gender_DescriptionN']; + insertIMEIDetailsModel.titleDescription = profileInfo['Title_Description']; + insertIMEIDetailsModel.titleDescriptionN = profileInfo['Title_DescriptionN']; + insertIMEIDetailsModel.projectID = await sharedPref.getInt(PROJECT_ID); + insertIMEIDetailsModel.doctorID = loggedIn != null + ? loggedIn['List_MemberInformation'][0]['MemberID'] + : user.doctorID; + insertIMEIDetailsModel.outSA = loggedIn != null ? loggedIn['PatientOutSA'] : user.outSA; + insertIMEIDetailsModel.vidaAuthTokenID = await sharedPref.getString(VIDA_AUTH_TOKEN_ID); + insertIMEIDetailsModel.vidaRefreshTokenID = + await sharedPref.getString(VIDA_REFRESH_TOKEN_ID); + insertIMEIDetailsModel.password = await sharedPref.getString(PASSWORD); + + await _authService.insertDeviceImei(insertIMEIDetailsModel); + if (_authService.hasError) { + error = _authService.error; + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } + Future login(UserModel userInfo) async { setState(ViewState.BusyLocal); await _authService.login(userInfo); diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 1fc4c795..f2d72b83 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -7,6 +7,7 @@ import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; @@ -42,6 +43,7 @@ import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:provider/provider.dart'; import 'package:sticky_headers/sticky_headers/widget.dart'; +import '../../locator.dart'; import '../../widgets/shared/app_texts_widget.dart'; import '../../widgets/shared/rounded_container_widget.dart'; import 'home_page_card.dart'; @@ -73,6 +75,9 @@ class _HomeScreenState extends State { var clinicId; var _patientSearchFormValues; + IMEIViewModel _IMEIViewModel = locator(); + + void didChangeDependencies() async { super.didChangeDependencies(); if (_isInit) { @@ -92,11 +97,9 @@ class _HomeScreenState extends State { _firebaseMessaging.getToken().then((String token) async { if (token != '') { DEVICE_TOKEN = token; - var request = await sharedPref.getObj(DOCTOR_PROFILE); - authProvider.insertDeviceImei(request).then((value) { - // print(value); - changeIsLoading(false); - }); + await _IMEIViewModel.insertDeviceImei(); + changeIsLoading(false); + } }); } From a5120b473f40f9571cf0debb48c37e472e1a1df9 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 5 May 2021 12:44:38 +0300 Subject: [PATCH 06/28] rename Auth view model to Doctor Profile View Model --- lib/core/service/auth_service.dart | 8 ++++---- ..._model.dart => doctor_profile_view_model.dart} | 15 ++++----------- lib/core/viewModel/project_view_model.dart | 4 ++-- lib/main.dart | 6 +++--- lib/root_page.dart | 4 ++-- lib/screens/home/home_screen.dart | 4 ++-- .../patients/out_patient/out_patient_screen.dart | 4 ++-- .../patient_search_result_screen.dart | 4 ++-- .../patient_search/patient_search_screen.dart | 4 ++-- .../profile/note/progress_note_screen.dart | 4 ++-- .../referral/my-referral-detail-screen.dart | 4 ++-- .../referral/my-referral-patient-screen.dart | 4 ++-- .../assessment/add_assessment_details.dart | 2 +- lib/widgets/auth/verification_methods.dart | 10 +++++----- .../patients/profile/profile-welcome-widget.dart | 4 ++-- lib/widgets/shared/app_drawer_widget.dart | 4 ++-- 16 files changed, 39 insertions(+), 46 deletions(-) rename lib/core/viewModel/{auth_view_model.dart => doctor_profile_view_model.dart} (78%) diff --git a/lib/core/service/auth_service.dart b/lib/core/service/auth_service.dart index f4d0e096..ec7c2615 100644 --- a/lib/core/service/auth_service.dart +++ b/lib/core/service/auth_service.dart @@ -2,7 +2,7 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; @@ -109,13 +109,13 @@ class AuthService extends BaseService { await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP, onSuccess: (dynamic response, int statusCode) { // TODO improve the logic here - Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear(); + Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear(); _checkActivationCodeForDoctorAppRes = response; - Provider.of(AppGlobal.CONTEX, listen: false).selectedClinicName = + Provider.of(AppGlobal.CONTEX, listen: false).selectedClinicName = ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; response['List_DoctorsClinic'].forEach((v) { - Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.add(new ClinicModel.fromJson(v)); + Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.add(new ClinicModel.fromJson(v)); }); }, onFailure: (String error, int statusCode) { hasError = true; diff --git a/lib/core/viewModel/auth_view_model.dart b/lib/core/viewModel/doctor_profile_view_model.dart similarity index 78% rename from lib/core/viewModel/auth_view_model.dart rename to lib/core/viewModel/doctor_profile_view_model.dart index 6eb85ebb..24f53e5b 100644 --- a/lib/core/viewModel/auth_view_model.dart +++ b/lib/core/viewModel/doctor_profile_view_model.dart @@ -1,20 +1,13 @@ import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/core/model/imei_details.dart'; -import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; -import '../../models/doctor/user_model.dart'; - enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } -class AuthViewModel extends BaseViewModel { +class DoctorProfileViewModel extends BaseViewModel { List doctorsClinicList = []; String selectedClinicName; @@ -27,11 +20,11 @@ class AuthViewModel extends BaseViewModel { notifyListeners(); } - AuthViewModel() { - getUserAuthentication(); + DoctorProfileViewModel() { + getUserProfile(); } - getUserAuthentication() async { + getUserProfile() async { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); if (profile != null) { doctorProfile = new DoctorProfileModel.fromJson(profile); diff --git a/lib/core/viewModel/project_view_model.dart b/lib/core/viewModel/project_view_model.dart index 97974a04..0bf0c844 100644 --- a/lib/core/viewModel/project_view_model.dart +++ b/lib/core/viewModel/project_view_model.dart @@ -4,7 +4,7 @@ import 'package:connectivity/connectivity.dart'; import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; 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'; @@ -123,7 +123,7 @@ class ProjectViewModel with ChangeNotifier { projectID: doctorProfile.projectID, ); - Provider.of(AppGlobal.CONTEX, listen: false) + Provider.of(AppGlobal.CONTEX, listen: false) .getDocProfiles(docInfo.toJson()) .then((res) async { sharedPref.setObj(DOCTOR_PROFILE, res['DoctorProfileList'][0]); diff --git a/lib/main.dart b/lib/main.dart index 83c2a450..7c70061c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,7 +11,7 @@ import 'package:provider/provider.dart'; import './config/size_config.dart'; import './routes.dart'; import 'config/config.dart'; -import 'core/viewModel/auth_view_model.dart'; +import 'core/viewModel/doctor_profile_view_model.dart'; import 'core/viewModel/hospitals_view_model.dart'; import 'locator.dart'; @@ -33,8 +33,8 @@ class MyApp extends StatelessWidget { SizeConfig().init(constraints, orientation); return MultiProvider( providers: [ - ChangeNotifierProvider( - create: (context) => AuthViewModel()), + ChangeNotifierProvider( + create: (context) => DoctorProfileViewModel()), // ChangeNotifierProvider( // create: (context) => HospitalViewModel()), ChangeNotifierProvider( diff --git a/lib/root_page.dart b/lib/root_page.dart index 3bd24a81..7df1b7cb 100644 --- a/lib/root_page.dart +++ b/lib/root_page.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; import 'package:flutter/cupertino.dart'; @@ -10,7 +10,7 @@ import 'landing_page.dart'; class RootPage extends StatelessWidget { @override Widget build(BuildContext context) { - AuthViewModel authProvider = Provider.of(context); + DoctorProfileViewModel authProvider = Provider.of(context); Widget buildRoot() { switch (authProvider.stutas) { case APP_STATUS.LOADING: diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index f2d72b83..b3f79761 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -4,7 +4,7 @@ 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/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; @@ -63,7 +63,7 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); - AuthViewModel authProvider; + DoctorProfileViewModel authProvider; bool isLoading = false; ProjectViewModel projectsProvider; var _isInit = true; diff --git a/lib/screens/patients/out_patient/out_patient_screen.dart b/lib/screens/patients/out_patient/out_patient_screen.dart index c8d197de..c6549568 100644 --- a/lib/screens/patients/out_patient/out_patient_screen.dart +++ b/lib/screens/patients/out_patient/out_patient_screen.dart @@ -4,7 +4,7 @@ import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/patient_model.dart'; @@ -60,7 +60,7 @@ class OutPatientsScreen extends StatefulWidget { class _OutPatientsScreenState extends State { int clinicId; - AuthViewModel authProvider; + DoctorProfileViewModel authProvider; List _times = []; //['All', 'Today', 'Tomorrow', 'Next Week']; diff --git a/lib/screens/patients/patient_search/patient_search_result_screen.dart b/lib/screens/patients/patient_search/patient_search_result_screen.dart index 0f536fcd..05de14db 100644 --- a/lib/screens/patients/patient_search/patient_search_result_screen.dart +++ b/lib/screens/patients/patient_search/patient_search_result_screen.dart @@ -2,7 +2,7 @@ import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/patient_model.dart'; @@ -48,7 +48,7 @@ class PatientsSearchResultScreen extends StatefulWidget { class _PatientsSearchResultScreenState extends State { int clinicId; - AuthViewModel authProvider; + DoctorProfileViewModel authProvider; String patientType; diff --git a/lib/screens/patients/patient_search/patient_search_screen.dart b/lib/screens/patients/patient_search/patient_search_screen.dart index dc6d3587..192a37c9 100644 --- a/lib/screens/patients/patient_search/patient_search_screen.dart +++ b/lib/screens/patients/patient_search/patient_search_screen.dart @@ -2,7 +2,7 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_result_screen.dart'; import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; @@ -29,7 +29,7 @@ class _PatientSearchScreenState extends State { TextEditingController middleNameInfoController = TextEditingController(); TextEditingController lastNameFileInfoController = TextEditingController(); PatientType selectedPatientType = PatientType.inPatient; - AuthViewModel authProvider; + DoctorProfileViewModel authProvider; @override Widget build(BuildContext context) { diff --git a/lib/screens/patients/profile/note/progress_note_screen.dart b/lib/screens/patients/profile/note/progress_note_screen.dart index 173115f9..38b4edad 100644 --- a/lib/screens/patients/profile/note/progress_note_screen.dart +++ b/lib/screens/patients/profile/note/progress_note_screen.dart @@ -1,6 +1,6 @@ import 'package:doctor_app_flutter/core/model/note/note_model.dart'; import 'package:doctor_app_flutter/core/model/note/update_note_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; @@ -42,7 +42,7 @@ class _ProgressNoteState extends State { final _controller = TextEditingController(); var _isInit = true; bool isDischargedPatient = false; - AuthViewModel authProvider; + DoctorProfileViewModel authProvider; ProjectViewModel projectViewModel; getProgressNoteList(BuildContext context, PatientViewModel model, diff --git a/lib/screens/patients/profile/referral/my-referral-detail-screen.dart b/lib/screens/patients/profile/referral/my-referral-detail-screen.dart index 71edabb6..8eea6c34 100644 --- a/lib/screens/patients/profile/referral/my-referral-detail-screen.dart +++ b/lib/screens/patients/profile/referral/my-referral-detail-screen.dart @@ -1,6 +1,6 @@ import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/my_referral/PendingReferral.dart'; @@ -24,7 +24,7 @@ class MyReferralDetailScreen extends StatelessWidget { Widget build(BuildContext context) { final gridHeight = (MediaQuery.of(context).size.width * 0.3) * 1.8; - AuthViewModel authProvider = Provider.of(context); + DoctorProfileViewModel authProvider = Provider.of(context); final routeArgs = ModalRoute.of(context).settings.arguments as Map; pendingReferral = routeArgs['referral']; diff --git a/lib/screens/patients/profile/referral/my-referral-patient-screen.dart b/lib/screens/patients/profile/referral/my-referral-patient-screen.dart index b2953cca..1482db74 100644 --- a/lib/screens/patients/profile/referral/my-referral-patient-screen.dart +++ b/lib/screens/patients/profile/referral/my-referral-patient-screen.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; @@ -15,7 +15,7 @@ class MyReferralPatientScreen extends StatelessWidget { // previous design page is: MyReferralPatient @override Widget build(BuildContext context) { - AuthViewModel authProvider = Provider.of(context); + DoctorProfileViewModel authProvider = Provider.of(context); return BaseView( onModelReady: (model) => model.getPendingReferralPatients(), diff --git a/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart b/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart index 47d639ad..57e2e53f 100644 --- a/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart +++ b/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart @@ -3,7 +3,7 @@ import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart'; -// import 'package:doctor_app_flutter/core/viewModel/auth_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/models/SOAP/PatchAssessmentReqModel.dart'; import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index dc95f6dd..67252c6b 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -27,7 +27,7 @@ import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; import '../../config/size_config.dart'; -import '../../core/viewModel/auth_view_model.dart'; +import '../../core/viewModel/doctor_profile_view_model.dart'; import '../../landing_page.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; @@ -97,7 +97,7 @@ class _VerificationMethodsState extends State { @override Widget build(BuildContext context) { - AuthViewModel authProv = Provider.of(context); + DoctorProfileViewModel authProv = Provider.of(context); projectsProvider = Provider.of(context); return FutureBuilder( future: Future.wait([_loggedUserFuture]), @@ -331,7 +331,7 @@ class _VerificationMethodsState extends State { } sendActivationCodeByOtpNotificationType( - oTPSendType, AuthViewModel authProv) async { + oTPSendType, DoctorProfileViewModel authProv) async { // TODO : build enum for verfication method if (oTPSendType == 1 || oTPSendType == 2) { GifLoaderDialogUtils.showMyDialog(context); @@ -370,7 +370,7 @@ class _VerificationMethodsState extends State { } sendActivationCodeVerificationScreen( - oTPSendType, AuthViewModel authProv) async { + oTPSendType, DoctorProfileViewModel authProv) async { GifLoaderDialogUtils.showMyDialog(context); ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel( iMEI: user.iMEI, @@ -734,7 +734,7 @@ class _VerificationMethodsState extends State { } } - checkActivationCode(AuthViewModel authProv, {value}) async { + checkActivationCode(DoctorProfileViewModel authProv, {value}) async { CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = new CheckActivationCodeRequestModel( zipCode: diff --git a/lib/widgets/patients/profile/profile-welcome-widget.dart b/lib/widgets/patients/profile/profile-welcome-widget.dart index 10586552..577d94bd 100644 --- a/lib/widgets/patients/profile/profile-welcome-widget.dart +++ b/lib/widgets/patients/profile/profile-welcome-widget.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -11,7 +11,7 @@ class ProfileWelcomeWidget extends StatelessWidget { @override Widget build(BuildContext context) { - AuthViewModel authProvider = Provider.of(context); + DoctorProfileViewModel authProvider = Provider.of(context); return Container( height: height, diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index ebb49e6f..5ca6bf84 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/auth_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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/screens/reschedule-leaves/add-rescheduleleave.dart'; @@ -28,7 +28,7 @@ class _AppDrawerState extends State { @override Widget build(BuildContext context) { - AuthViewModel authProvider = Provider.of(context); + DoctorProfileViewModel authProvider = Provider.of(context); projectsProvider = Provider.of(context); return RoundedContainer( child: Container( From 53791f1028fb43dd179ce80f39620c6998feb62a Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 5 May 2021 12:48:36 +0300 Subject: [PATCH 07/28] change imei to authentication --- ...auth_service.dart => authentication_service.dart} | 2 +- ...iew_model.dart => authentication_view_model.dart} | 6 +++--- lib/locator.dart | 8 ++++---- lib/screens/auth/login_screen.dart | 12 ++++++------ lib/screens/auth/verification_methods_screen.dart | 4 ++-- lib/screens/home/home_screen.dart | 4 ++-- lib/widgets/auth/verification_methods.dart | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) rename lib/core/service/{auth_service.dart => authentication_service.dart} (99%) rename lib/core/viewModel/{imei_view_model.dart => authentication_view_model.dart} (96%) diff --git a/lib/core/service/auth_service.dart b/lib/core/service/authentication_service.dart similarity index 99% rename from lib/core/service/auth_service.dart rename to lib/core/service/authentication_service.dart index ec7c2615..59d8e34a 100644 --- a/lib/core/service/auth_service.dart +++ b/lib/core/service/authentication_service.dart @@ -10,7 +10,7 @@ import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:provider/provider.dart'; -class AuthService extends BaseService { +class AuthenticationService extends BaseService { List _imeiDetails = []; List get dashboardItemsList => _imeiDetails; //TODO Change this to models diff --git a/lib/core/viewModel/imei_view_model.dart b/lib/core/viewModel/authentication_view_model.dart similarity index 96% rename from lib/core/viewModel/imei_view_model.dart rename to lib/core/viewModel/authentication_view_model.dart index 90fb3578..54a06c04 100644 --- a/lib/core/viewModel/imei_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -5,7 +5,7 @@ import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_mo import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; -import 'package:doctor_app_flutter/core/service/auth_service.dart'; +import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; @@ -14,8 +14,8 @@ import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_ import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; -class IMEIViewModel extends BaseViewModel { - AuthService _authService = locator(); +class AuthenticationViewModel extends BaseViewModel { + AuthenticationService _authService = locator(); HospitalsService _hospitalsService = locator(); List get imeiDetails => _authService.dashboardItemsList; diff --git a/lib/locator.dart b/lib/locator.dart index d0d76ea3..3032c49d 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/service/auth_service.dart'; +import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/dasboard_service.dart'; import 'package:doctor_app_flutter/core/service/medical_file_service.dart'; import 'package:doctor_app_flutter/core/service/patient_service.dart'; @@ -7,7 +7,7 @@ import 'package:doctor_app_flutter/core/service/procedure_service.dart'; import 'package:doctor_app_flutter/core/service/sickleave_service.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/medical_file_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; @@ -75,7 +75,7 @@ void setupLocator() { locator.registerLazySingleton(() => MedicalFileService()); locator.registerLazySingleton(() => AdmissionRequestService()); locator.registerLazySingleton(() => UcafService()); - locator.registerLazySingleton(() => AuthService()); + locator.registerLazySingleton(() => AuthenticationService()); locator.registerLazySingleton(() => PatientMuseService()); locator.registerLazySingleton(() => LabsService()); locator.registerLazySingleton(() => InsuranceCardService()); @@ -90,7 +90,7 @@ void setupLocator() { /// View Model locator.registerFactory(() => DoctorReplayViewModel()); - locator.registerFactory(() => IMEIViewModel()); + locator.registerFactory(() => AuthenticationViewModel()); locator.registerFactory(() => ScheduleViewModel()); locator.registerFactory(() => ReferralPatientViewModel()); locator.registerFactory(() => ReferredPatientViewModel()); diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 5e069a2a..707e178c 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -6,8 +6,8 @@ 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/auth_service.dart'; -import 'package:doctor_app_flutter/core/viewModel/imei_view_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/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; @@ -42,7 +42,7 @@ class _LoginsreenState extends State { final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); bool _isLoading = true; ProjectViewModel projectViewModel; - AuthService authService = AuthService(); + AuthenticationService authService = AuthenticationService(); //TODO change AppTextFormField to AppTextFormFieldCustom final loginFormKey = GlobalKey(); @@ -99,7 +99,7 @@ class _LoginsreenState extends State { projectViewModel = Provider.of(context); - return BaseView( + return BaseView( onModelReady: (model) => {}, builder: (_, model, w) => AppScaffold( @@ -452,7 +452,7 @@ class _LoginsreenState extends State { } login(context, - IMEIViewModel model,) async { + AuthenticationViewModel model,) async { if (loginFormKey.currentState.validate()) { loginFormKey.currentState.save(); GifLoaderDialogUtils.showMyDialog(context); @@ -499,7 +499,7 @@ class _LoginsreenState extends State { primaryFocus.unfocus(); } - getProjects(memberID, IMEIViewModel model)async { + getProjects(memberID, AuthenticationViewModel model)async { if (memberID != null && memberID != '') { if (projectsList.length == 0) { await model.getHospitalsList(memberID); diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index a83db25c..3d44d726 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/imei_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; @@ -27,7 +27,7 @@ class _VerificationMethodsScreenState extends State { @override Widget build(BuildContext context) { - return BaseView( + return BaseView( onModelReady: (model) async {}, builder: (_, model, w) => AppScaffold( isLoading: _isLoading, diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index b3f79761..dad2460d 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -7,7 +7,7 @@ import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/imei_view_model.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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; @@ -75,7 +75,7 @@ class _HomeScreenState extends State { var clinicId; var _patientSearchFormValues; - IMEIViewModel _IMEIViewModel = locator(); + AuthenticationViewModel _IMEIViewModel = locator(); void didChangeDependencies() async { diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 67252c6b..7e268b06 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -3,7 +3,7 @@ import 'dart:io' show Platform; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/imei_details.dart'; -import 'package:doctor_app_flutter/core/viewModel/imei_view_model.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/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; @@ -42,7 +42,7 @@ class VerificationMethods extends StatefulWidget { final password; final Function changeLoadingState; - final IMEIViewModel model; + final AuthenticationViewModel model; @override _VerificationMethodsState createState() => _VerificationMethodsState(); From a3caf023e2f7a533f4c99a8dd306d061be0b9b48 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 5 May 2021 14:54:36 +0300 Subject: [PATCH 08/28] Add enum to verification_methods --- lib/core/enum/auth_method_types.dart | 24 +++ lib/widgets/{otp => auth}/sms-popup.dart | 5 +- lib/widgets/auth/verification_methods.dart | 190 ++++++++------------- 3 files changed, 101 insertions(+), 118 deletions(-) create mode 100644 lib/core/enum/auth_method_types.dart rename lib/widgets/{otp => auth}/sms-popup.dart (99%) diff --git a/lib/core/enum/auth_method_types.dart b/lib/core/enum/auth_method_types.dart new file mode 100644 index 00000000..3faff89c --- /dev/null +++ b/lib/core/enum/auth_method_types.dart @@ -0,0 +1,24 @@ +enum AuthMethodTypes { SMS, WhatsApp, Fingerprint,FaceID,MoreOptions } +extension SelectedAuthMethodTypesService on AuthMethodTypes { + // ignore: missing_return + int getTypeIdService() { + switch (this) { + case AuthMethodTypes.SMS: + return 1; + break; + case AuthMethodTypes.WhatsApp: + return 2; + break; + case AuthMethodTypes.Fingerprint: + return 3; + break; + case AuthMethodTypes.FaceID: + return 4; + break; + case AuthMethodTypes.MoreOptions: + return 5; + break; + + } + } +} \ No newline at end of file diff --git a/lib/widgets/otp/sms-popup.dart b/lib/widgets/auth/sms-popup.dart similarity index 99% rename from lib/widgets/otp/sms-popup.dart rename to lib/widgets/auth/sms-popup.dart index fca0d689..50674138 100644 --- a/lib/widgets/otp/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; @@ -9,7 +10,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class SMSOTP { - final type; + final AuthMethodTypes type; final mobileNo; final Function onSuccess; final Function onFailure; @@ -81,7 +82,7 @@ class SMSOTP { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - type == 1 + type == AuthMethodTypes.SMS ? Padding( child: Icon( DoctorApp.verify_sms_1, diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 7e268b06..6c7142c4 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -1,6 +1,7 @@ import 'dart:io' show Platform; 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/model/imei_details.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; @@ -14,7 +15,7 @@ import 'package:doctor_app_flutter/models/doctor/profile_req_Model.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/translations_delegate_base.dart'; -import 'package:doctor_app_flutter/widgets/otp/sms-popup.dart'; +import 'package:doctor_app_flutter/widgets/auth/sms-popup.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'; @@ -57,15 +58,16 @@ class _VerificationMethodsState extends State { final LocalAuthentication auth = LocalAuthentication(); var _availableBiometrics; ProjectViewModel projectsProvider; - var isMoreOption = false; - var onlySMSBox = false; + bool isMoreOption = false; + bool onlySMSBox = false; var loginTokenID; + DoctorProfileViewModel doctorProfileViewModel; bool authenticated; - var fingrePrintBefore; + AuthMethodTypes fingrePrintBefore; - var selectedOption; + AuthMethodTypes selectedOption; @override void initState() { @@ -97,7 +99,7 @@ class _VerificationMethodsState extends State { @override Widget build(BuildContext context) { - DoctorProfileViewModel authProv = Provider.of(context); + doctorProfileViewModel = Provider.of(context); projectsProvider = Provider.of(context); return FutureBuilder( future: Future.wait([_loggedUserFuture]), @@ -112,7 +114,7 @@ class _VerificationMethodsState extends State { } else { return SingleChildScrollView( child: Container( - height: SizeConfig.realScreenHeight * .9, + height: SizeConfig.realScreenHeight * .87, width: SizeConfig.realScreenWidth, child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -253,14 +255,16 @@ class _VerificationMethodsState extends State { Expanded( child: InkWell( onTap: () => { - authenticateUser(3, - true, authProv) + // TODO check this logic it seem it will create bug to us + + authenticateUser(AuthMethodTypes.Fingerprint, + true) }, - child: getButton( - user.logInTypeID, - authProv))), + child: methodCard( + user.logInTypeID == 4 ?AuthMethodTypes.FaceID:user.logInTypeID == 2?AuthMethodTypes.WhatsApp:user.logInTypeID ==3? AuthMethodTypes.Fingerprint:AuthMethodTypes.SMS + ))), Expanded( - child: getButton(5, authProv)) + child: methodCard(AuthMethodTypes.MoreOptions)) ]), ]) : Column( @@ -274,11 +278,11 @@ class _VerificationMethodsState extends State { MainAxisAlignment.center, children: [ Expanded( - child: getButton( - 3, authProv)), + child: methodCard( + AuthMethodTypes.Fingerprint)), Expanded( - child: getButton( - 4, authProv)) + child: methodCard( + AuthMethodTypes.FaceID)) ], ) : SizedBox(), @@ -287,9 +291,9 @@ class _VerificationMethodsState extends State { MainAxisAlignment.center, children: [ Expanded( - child: getButton(1, authProv)), + child: methodCard(AuthMethodTypes.SMS)), Expanded( - child: getButton(2, authProv)) + child: methodCard(AuthMethodTypes.WhatsApp)) ], ), ]), @@ -325,15 +329,10 @@ class _VerificationMethodsState extends State { } }); } - - bool hideSilentMethods() { - return verificationMethod == 4 || verificationMethod == 3 ? true : false; - } - + sendActivationCodeByOtpNotificationType( - oTPSendType, DoctorProfileViewModel authProv) async { - // TODO : build enum for verfication method - if (oTPSendType == 1 || oTPSendType == 2) { + AuthMethodTypes authMethodType) async { + if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.showMyDialog(context); int projectID = await sharedPref.getInt(PROJECT_ID); @@ -343,7 +342,7 @@ class _VerificationMethodsState extends State { memberID: _loggedUser['List_MemberInformation'][0]['MemberID'], zipCode: _loggedUser['ZipCode'], mobileNumber: _loggedUser['MobileNumber'], - otpSendType: oTPSendType.toString(), + otpSendType: authMethodType.getTypeIdService().toString(), password: widget.password); await widget.model .sendActivationCodeForDoctorApp(activationCodeModel); @@ -358,11 +357,11 @@ class _VerificationMethodsState extends State { sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["LogInTokenID"]); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); - this.startSMSService(oTPSendType, authProv); + this.startSMSService(authMethodType); } } else { // TODO route to this page with parameters to inicate we should present 2 option - if (Platform.isAndroid && oTPSendType == 3) { + if (Platform.isAndroid && authMethodType == AuthMethodTypes.Fingerprint) { Helpers.showErrorToast('Your device not support this feature'); } else { } @@ -370,7 +369,7 @@ class _VerificationMethodsState extends State { } sendActivationCodeVerificationScreen( - oTPSendType, DoctorProfileViewModel authProv) async { + AuthMethodTypes authMethodType) async { GifLoaderDialogUtils.showMyDialog(context); ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel( iMEI: user.iMEI, @@ -378,7 +377,7 @@ class _VerificationMethodsState extends State { memberID: user.doctorID, zipCode: user.outSA == true ? '971' : '966', mobileNumber: user.mobile, - oTPSendType: oTPSendType, + oTPSendType: authMethodType ==AuthMethodTypes.FaceID?4:authMethodType ==AuthMethodTypes.Fingerprint?3:authMethodType ==AuthMethodTypes.WhatsApp?2:1, isMobileFingerPrint: 1, vidaAuthTokenID: user.vidaAuthTokenID, vidaRefreshTokenID: user.vidaRefreshTokenID); @@ -395,20 +394,20 @@ class _VerificationMethodsState extends State { sharedPref.setString( VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["LogInTokenID"]); - if (oTPSendType == 1 || oTPSendType == 2) { + if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.hideDialog(context); - this.startSMSService(oTPSendType, authProv); + this.startSMSService(authMethodType); } else { - checkActivationCode(authProv); + checkActivationCode(); } } } - Widget getButton(flag, authProv) { - switch (flag) { - case 2: + Widget methodCard(AuthMethodTypes authMethodType) { + switch (authMethodType) { + case AuthMethodTypes.WhatsApp: return InkWell( - onTap: () => {authenticateUser(2, true, authProv)}, + onTap: () => {authenticateUser(AuthMethodTypes.WhatsApp, true)}, child: Container( margin: EdgeInsets.all(10), decoration: BoxDecoration( @@ -442,9 +441,9 @@ class _VerificationMethodsState extends State { ), ))); break; - case 1: + case AuthMethodTypes.SMS: return InkWell( - onTap: () => {authenticateUser(1, true, authProv)}, + onTap: () => {authenticateUser(AuthMethodTypes.SMS, true)}, child: Container( margin: EdgeInsets.all(10), decoration: BoxDecoration( @@ -462,11 +461,7 @@ class _VerificationMethodsState extends State { height: 60, width: 60, ), - projectsProvider.isArabic - ? SizedBox( - height: 20, - ) - : SizedBox( + SizedBox( height: 20, ), AppText( @@ -478,11 +473,11 @@ class _VerificationMethodsState extends State { ), ))); break; - case 3: + case AuthMethodTypes.Fingerprint: return InkWell( onTap: () => { if (checkIfBiometricAvailable(BiometricType.fingerprint)) - {authenticateUser(3, true, authProv)} + {authenticateUser(AuthMethodTypes.Fingerprint, true)} }, child: Container( margin: EdgeInsets.all(10), @@ -513,11 +508,11 @@ class _VerificationMethodsState extends State { ), ))); break; - case 4: + case AuthMethodTypes.FaceID: return InkWell( onTap: () { if (checkIfBiometricAvailable(BiometricType.face)) { - authenticateUser(4, true, authProv); + authenticateUser(AuthMethodTypes.FaceID, true); } }, child: @@ -622,41 +617,32 @@ class _VerificationMethodsState extends State { return isAvailable; } - formatDate(date) { - return DateFormat('MMM dd, yyy, kk:mm').format(date); - } - authenticateUser(type, isActive, authProv) { - //GifLoaderDialogUtils.showMyDialog(context); - if (type == 3 || type == 4) { - fingrePrintBefore = type; + authenticateUser( AuthMethodTypes authMethodType, isActive) { + if (authMethodType == AuthMethodTypes.Fingerprint || authMethodType == AuthMethodTypes.FaceID) { + fingrePrintBefore = authMethodType; } - this.selectedOption = fingrePrintBefore != null ? fingrePrintBefore : type; + this.selectedOption = fingrePrintBefore != null ? fingrePrintBefore : authMethodType; - switch (type) { - case 1: - this.loginWithSMS(1, isActive, authProv); + switch (authMethodType) { + case AuthMethodTypes.SMS: + sendActivationCode(authMethodType); break; - case 2: - this.loginWithSMS(2, isActive, authProv); - + case AuthMethodTypes.WhatsApp: + sendActivationCode(authMethodType); break; - case 3: - this.loginWithFingurePrintFace(3, isActive, authProv); + case AuthMethodTypes.Fingerprint: + this.loginWithFingerPrintOrFaceID(AuthMethodTypes.Fingerprint, isActive); break; - case 4: - this.loginWithFingurePrintFace(4, isActive, authProv); + case AuthMethodTypes.FaceID: + this.loginWithFingerPrintOrFaceID(AuthMethodTypes.FaceID, isActive); break; default: break; } - sharedPref.setInt(OTP_TYPE, selectedOption); - // sharedPref.setInt(LAST_LOGIN), + sharedPref.setInt(OTP_TYPE, selectedOption.getTypeIdService()); } - loginWithSMS(type, isActive, authProv) { - this.sendActivationCode(type, authProv); - } Future _getAvailableBiometrics() async { var availableBiometrics; @@ -672,15 +658,15 @@ class _VerificationMethodsState extends State { }); } - sendActivationCode(type, authProv) async { + sendActivationCode(AuthMethodTypes authMethodType) async { if (user != null) { - sendActivationCodeVerificationScreen(type, authProv); + sendActivationCodeVerificationScreen(authMethodType); } else { - sendActivationCodeByOtpNotificationType(type, authProv); + sendActivationCodeByOtpNotificationType(authMethodType); } } - startSMSService(type, authProv) { + startSMSService(AuthMethodTypes type) { new SMSOTP( context, type, @@ -694,7 +680,7 @@ class _VerificationMethodsState extends State { ); }); - this.checkActivationCode(authProv, value: value); + this.checkActivationCode(value: value); }, () => { widget.changeLoadingState(false), @@ -703,10 +689,8 @@ class _VerificationMethodsState extends State { ).displayDialog(context); } - loginWithFingurePrintFace(type, isActive, authProv) async { + loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async { if (isActive) { - // this.startBiometricLoginIfAvailable(); - const iosStrings = const IOSAuthMessages( cancelButton: 'cancel', goToSettingsButton: 'settings', @@ -724,8 +708,7 @@ class _VerificationMethodsState extends State { } if (!mounted) return; if (user != null && (user.logInTypeID == 3 || user.logInTypeID == 4)) { - this.sendActivationCode(type, authProv); - // this.checkActivationCode(authProv); + this.sendActivationCode(authMethodTypes); } else { setState(() { this.onlySMSBox = true; @@ -734,7 +717,7 @@ class _VerificationMethodsState extends State { } } - checkActivationCode(DoctorProfileViewModel authProv, {value}) async { + checkActivationCode( {value}) async { CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = new CheckActivationCodeRequestModel( zipCode: @@ -756,44 +739,20 @@ class _VerificationMethodsState extends State { } else { sharedPref.setString(TOKEN, widget.model.checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); if (widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != null) { - loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0], authProv); + loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); } else { sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); ClinicModel clinic = ClinicModel.fromJson(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); - getDocProfiles(clinic, authProv); + getDocProfiles(clinic); } } - - // authProv - // .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp) - // .then((res) async { - // widget.changeLoadingState(false); - // if (res['MessageStatus'] == 1) { - // sharedPref.setString(TOKEN, res['AuthenticationTokenID']); - // if (res['List_DoctorProfile'] != null) { - // loginProcessCompleted(res['List_DoctorProfile'][0], authProv); - // sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']); - // } else { - // sharedPref.setObj(CLINIC_NAME, res['List_DoctorsClinic']); - // ClinicModel clinic = - // ClinicModel.fromJson(res['List_DoctorsClinic'][0]); - // getDocProfiles(clinic, authProv); - // } - // } else { - // Navigator.pop(context); - // Helpers.showErrorToast(res['ErrorEndUserMessage']); - // } - // }).catchError((err) { - // Navigator.pop(context); - // Helpers.showErrorToast(err); - // }); } - loginProcessCompleted(Map profile, authProv) { + loginProcessCompleted(Map profile) { var doctor = DoctorProfileModel.fromJson(profile); - authProv.setDoctorProfile(doctor); + doctorProfileViewModel.setDoctorProfile(doctor); sharedPref.setObj(DOCTOR_PROFILE, profile); projectsProvider.isLogin = true; @@ -805,7 +764,7 @@ class _VerificationMethodsState extends State { (r) => false); } - getDocProfiles(ClinicModel clinicInfo, authProv) { + getDocProfiles(ClinicModel clinicInfo) { ProfileReqModel docInfo = new ProfileReqModel( doctorID: clinicInfo.doctorID, clinicID: clinicInfo.clinicID, @@ -813,15 +772,14 @@ class _VerificationMethodsState extends State { projectID: clinicInfo.projectID, tokenID: '', languageID: 2); - authProv.getDocProfiles(docInfo.toJson()).then((res) { + doctorProfileViewModel.getDocProfiles(docInfo.toJson()).then((res) { if (res['MessageStatus'] == 1) { - loginProcessCompleted(res['DoctorProfileList'][0], authProv); + loginProcessCompleted(res['DoctorProfileList'][0]); } else { // changeLoadingState(false); Helpers.showErrorToast(res['ErrorEndUserMessage']); } }).catchError((err) { - // changeLoadingState(false); Helpers.showErrorToast(err); }); } From 3ca4ac3632c93725e36695cf066189b97f3e44e6 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 5 May 2021 16:59:11 +0300 Subject: [PATCH 09/28] create method card and remove future builder from verification method widget --- lib/config/config.dart | 2 +- .../viewModel/authentication_view_model.dart | 56 + .../auth/verification_methods_screen.dart | 24 +- lib/widgets/auth/method_card.dart | 242 +++++ lib/widgets/auth/sms-popup.dart | 3 - lib/widgets/auth/verification_methods.dart | 959 +++++++----------- 6 files changed, 694 insertions(+), 592 deletions(-) create mode 100644 lib/widgets/auth/method_card.dart diff --git a/lib/config/config.dart b/lib/config/config.dart index b21ee8ed..ec8efe26 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -337,7 +337,7 @@ const TRANSACTION_NO = 0; const LANGUAGE_ID = 2; const STAMP = '2020-04-27T12:17:17.721Z'; const IP_ADDRESS = '9.9.9.9'; -const VERSION_ID = 5.9; +const VERSION_ID = 6.0; const CHANNEL = 9; const SESSION_ID = 'BlUSkYymTt'; const IS_LOGIN_FOR_DOCTOR_APP = true; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 54a06c04..474b91fe 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -13,6 +13,8 @@ import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:intl/intl.dart'; class AuthenticationViewModel extends BaseViewModel { AuthenticationService _authService = locator(); @@ -25,6 +27,8 @@ class AuthenticationViewModel extends BaseViewModel { get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; + var loggedUser; + GetIMEIDetailsModel user; Future selectDeviceImei(imei) async { setState(ViewState.Busy); await _authService.selectDeviceImei(imei); @@ -127,4 +131,56 @@ class AuthenticationViewModel extends BaseViewModel { } else setState(ViewState.Idle); } + + + + getDate(DateTime date) { + final DateFormat formatter = DateFormat('dd MMM yyyy'); + + return formatter.format(date); + } + + getTime(DateTime date) { + final DateFormat formatter = DateFormat('HH:mm a'); + + return formatter.format(date); + } + + + getType(type, context) { + switch (type) { + case 1: + return TranslationBase + .of(context) + .verifySMS; + break; + case 3: + return TranslationBase + .of(context) + .verifyFingerprint; + break; + case 4: + return TranslationBase + .of(context) + .verifyFaceID; + break; + case 2: + return TranslationBase.of(context).verifyWhatsApp; + break; + default: + return TranslationBase.of(context).verifySMS; + break; + } + } + + getInitUserInfo()async{ + setState(ViewState.Busy); + loggedUser = await sharedPref.getObj(LOGGED_IN_USER); + var lastLogin = await sharedPref.getObj(LAST_LOGIN_USER); + if (lastLogin != null) { + user = GetIMEIDetailsModel.fromJson(lastLogin); + } + setState(ViewState.Idle); + + } } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 3d44d726..e4d2603d 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -28,29 +28,15 @@ class _VerificationMethodsScreenState extends State { @override Widget build(BuildContext context) { return BaseView( - onModelReady: (model) async {}, builder: (_, model, w) => AppScaffold( isLoading: _isLoading, isShowAppBar: false, isHomeIcon: false, backgroundColor: HexColor('#F8F8F8'), - body: ListView(children: [ - Container( - margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 50, - ), - VerificationMethods( - password: widget.password, - changeLoadingState: changeLoadingState, - model:model - ), - ], - ), - ), - ]))); + body:VerificationMethods( + password: widget.password, + changeLoadingState: changeLoadingState, + // model:model + ))); } } diff --git a/lib/widgets/auth/method_card.dart b/lib/widgets/auth/method_card.dart new file mode 100644 index 00000000..94bd261b --- /dev/null +++ b/lib/widgets/auth/method_card.dart @@ -0,0 +1,242 @@ +import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; +import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:local_auth/local_auth.dart'; +import 'package:provider/provider.dart'; + +class MethodCard extends StatefulWidget { + final AuthMethodTypes authMethodType; + final Function ( AuthMethodTypes type, bool isActive) authenticateUser; + final Function onShowMore; + + const MethodCard({Key key, this.authMethodType, this.authenticateUser, this.onShowMore}) : super(key: key); + + @override + _MethodCardState createState() => _MethodCardState(); +} + +class _MethodCardState extends State { + + var _availableBiometrics; + + final LocalAuthentication auth = LocalAuthentication(); + ProjectViewModel projectsProvider; + + + + @override + void initState() { + super.initState(); + _getAvailableBiometrics(); + } + + + bool checkIfBiometricAvailable(BiometricType biometricType) { + bool isAvailable = false; + if (_availableBiometrics != null) { + for (var i = 0; i < _availableBiometrics.length; i++) { + if (biometricType == _availableBiometrics[i]) isAvailable = true; + } + } + return isAvailable; + } + + Future _getAvailableBiometrics() async { + var availableBiometrics; + try { + availableBiometrics = await auth.getAvailableBiometrics(); + } on PlatformException catch (e) { + print(e); + } + if (!mounted) return; + + setState(() { + _availableBiometrics = availableBiometrics; + }); + } + @override + Widget build(BuildContext context) { + projectsProvider = Provider.of(context); + + switch (widget.authMethodType) { + case AuthMethodTypes.WhatsApp: + return InkWell( + onTap: () => {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)}, + child: Container( + margin: EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + child: Padding( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Image.asset( + 'assets/images/verify-whtsapp.png', + height: 60, + width: 60, + ), + ], + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifyWhatsApp, + fontSize: 14, + fontWeight: FontWeight.w600, + ) + ], + ), + ))); + break; + case AuthMethodTypes.SMS: + return InkWell( + onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)}, + child: Container( + margin: EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + child: Padding( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/verify-sms.png', + height: 60, + width: 60, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifySMS, + fontSize: 14, + fontWeight: FontWeight.w600, + ) + ], + ), + ))); + break; + case AuthMethodTypes.Fingerprint: + return InkWell( + onTap: () => { + if (checkIfBiometricAvailable(BiometricType.fingerprint)) + {widget.authenticateUser(AuthMethodTypes.Fingerprint, true)} + }, + child: Container( + margin: EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + child: Padding( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/verification_fingerprint_icon.png', + height: 60, + width: 60, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifyFingerprint, + fontSize: 14, + fontWeight: FontWeight.w600, + ) + ], + ), + ))); + break; + case AuthMethodTypes.FaceID: + return InkWell( + onTap: () { + if (checkIfBiometricAvailable(BiometricType.face)) { + widget.authenticateUser(AuthMethodTypes.FaceID, true); + } + }, + child: + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + margin: EdgeInsets.all(10), + child: Padding( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/verification_faceid_icon.png', + height: 60, + width: 60, + ), + SizedBox( + height: 20, + ), + AppText( + TranslationBase.of(context).verifyFaceID, + fontSize: 14, + fontWeight: FontWeight.w600, + ) + ], + ), + ))); + break; + + default: + return InkWell( + onTap: widget.onShowMore, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + child: Padding( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/login/more_icon.png', + height: 60, + width: 60, + ), + projectsProvider.isArabic + ? SizedBox( + height: 20, + ) + : SizedBox( + height: 10, + ), + AppText( + TranslationBase.of(context).moreVerification, + fontSize: 14, + fontWeight: FontWeight.w600, + ) + ], + ), + ))); + }; + } +} diff --git a/lib/widgets/auth/sms-popup.dart b/lib/widgets/auth/sms-popup.dart index 50674138..61329758 100644 --- a/lib/widgets/auth/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -61,9 +61,6 @@ class SMSOTP { projectProvider = Provider.of(context); return AlertDialog( contentPadding: EdgeInsets.fromLTRB(24.0, 0.0, 0.0, 24.0), - - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.all(Radius.circular(10.0))), content: StatefulBuilder(builder: (context, setState) { if (displayTime == '') { startTimer(setState); diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index 6c7142c4..faadbf9e 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -7,22 +7,23 @@ import 'package:doctor_app_flutter/core/model/imei_details.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/models/auth/activation_Code_req_model.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; 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/screens/base/base_view.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/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/auth/sms-popup.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/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:intl/intl.dart'; import 'package:local_auth/auth_strings.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; @@ -33,30 +34,23 @@ import '../../landing_page.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../util/helpers.dart'; -import '../../widgets/shared/dr_app_circular_progress_Indeicator.dart'; +import 'method_card.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); class VerificationMethods extends StatefulWidget { - VerificationMethods({this.changeLoadingState, this.password, this.model}); + VerificationMethods({this.changeLoadingState, this.password}); final password; final Function changeLoadingState; - final AuthenticationViewModel model; @override _VerificationMethodsState createState() => _VerificationMethodsState(); } class _VerificationMethodsState extends State { - MainAxisAlignment spaceBetweenMethods = MainAxisAlignment.spaceBetween; - Future _loggedUserFuture; - var _loggedUser; - var verificationMethod; - GetIMEIDetailsModel user; - final LocalAuthentication auth = LocalAuthentication(); - var _availableBiometrics; + ProjectViewModel projectsProvider; bool isMoreOption = false; bool onlySMSBox = false; @@ -65,564 +59,404 @@ class _VerificationMethodsState extends State { bool authenticated; - AuthMethodTypes fingrePrintBefore; + AuthMethodTypes fingerPrintBefore; AuthMethodTypes selectedOption; + AuthenticationViewModel model; + + final LocalAuthentication auth = LocalAuthentication(); @override void initState() { super.initState(); - _loggedUserFuture = getSharedPref(); - _getAvailableBiometrics(); - } - - Future getSharedPref() async { - sharedPref.getObj(LOGGED_IN_USER).then((userInfo) { - _loggedUser = userInfo; - }); - sharedPref.getObj(LAST_LOGIN_USER).then((lastLogin) { - if (lastLogin != null) { - user = GetIMEIDetailsModel.fromJson(lastLogin); - } - }); - - print(user); } + @override - void didChangeDependencies() { + void didChangeDependencies() async{ super.didChangeDependencies(); - final routeArgs = ModalRoute.of(context).settings.arguments as Map; - verificationMethod = - routeArgs != null ? routeArgs['verificationMethod'] : null; + } @override Widget build(BuildContext context) { doctorProfileViewModel = Provider.of(context); projectsProvider = Provider.of(context); - return FutureBuilder( - future: Future.wait([_loggedUserFuture]), - builder: (BuildContext context, AsyncSnapshot snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.waiting: - return DrAppCircularProgressIndeicator(); - default: - if (snapshot.hasError) { - Helpers.showErrorToast('Error: ${snapshot.error}'); - return Text('Error: ${snapshot.error}'); - } else { - return SingleChildScrollView( - child: Container( - height: SizeConfig.realScreenHeight * .87, - width: SizeConfig.realScreenWidth, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - child: Column( - children: [ - user != null && isMoreOption == false - ? Column( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - AppText(TranslationBase.of(context) - .welcomeBack), - AppText( - Helpers.capitalize(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( - getType( - user.logInTypeID, - context), - fontSize: 14, - ))), - Flexible( - flex: 2, - child: ListTile( - title: AppText( - user.editedOn != null - ? getDate(DateUtils + 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( + // widthFactor: 0.9, + 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: [ + Container( + child: Column( + + children: [ + SizedBox( + height: 100, + ), + model.user != null && isMoreOption == false + ? Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + 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 + ? model.getDate( + DateUtils .convertStringToDate( - user + model.user .editedOn)) - : user.createdOn != - null - ? getDate(DateUtils + : model.user.createdOn != null + ? model + .getDate(DateUtils .convertStringToDate( - user.createdOn)) - : '--', - textAlign: - TextAlign.right, - fontSize: 14, - fontWeight: - FontWeight.w800, - ), - subtitle: AppText( - user.editedOn != null - ? getTime(DateUtils + model.user.createdOn)) + : '--', + textAlign: TextAlign.right, + fontSize: 14, + fontWeight: FontWeight.w800, + ), + subtitle: AppText( + model.user.editedOn != null + ? model.getTime( + DateUtils .convertStringToDate( - user + model.user .editedOn)) - : user.createdOn != - null - ? getTime(DateUtils + : model.user.createdOn != null + ? model + .getTime(DateUtils .convertStringToDate( - 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, - ), - ]), - user != null && isMoreOption == false - ? Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Row( + model.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, + ), + ]), + model.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: MethodCard( + authMethodType: model.user + .logInTypeID == + 4 + ? AuthMethodTypes.FaceID + : model.user.logInTypeID == 2 + ? AuthMethodTypes + .WhatsApp + : model.user.logInTypeID == + 3 + ? AuthMethodTypes + .Fingerprint + : AuthMethodTypes + .SMS, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )), + ), + Expanded( + child: MethodCard( + authMethodType: + AuthMethodTypes.MoreOptions, + onShowMore: () { + setState(() { + isMoreOption = true; + }); + }, + )) + ]), + ]) + : Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + onlySMSBox == false + ? 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: methodCard( - user.logInTypeID == 4 ?AuthMethodTypes.FaceID:user.logInTypeID == 2?AuthMethodTypes.WhatsApp:user.logInTypeID ==3? AuthMethodTypes.Fingerprint:AuthMethodTypes.SMS - ))), + child: MethodCard( + authMethodType: + AuthMethodTypes.Fingerprint, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )), Expanded( - child: methodCard(AuthMethodTypes.MoreOptions)) - ]), - ]) - : Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - onlySMSBox == false - ? Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: methodCard( - AuthMethodTypes.Fingerprint)), - Expanded( - child: methodCard( - AuthMethodTypes.FaceID)) - ], - ) - : SizedBox(), - Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: methodCard(AuthMethodTypes.SMS)), - Expanded( - child: methodCard(AuthMethodTypes.WhatsApp)) - ], - ), - ]), - - // ) - ], - ), - ), - Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - user != null - ? Row( - children: [ - Expanded( - child: AppButton( - title: TranslationBase.of(context) - .useAnotherAccount, - color: Colors.red[700], - onPressed: () { - Navigator.of(context).pushNamed(LOGIN); - }, - )), - ], - ) - : SizedBox(), - ], - ), + child: MethodCard( + authMethodType: + AuthMethodTypes.FaceID, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )) + ], + ) + : SizedBox(), + Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + child: MethodCard( + authMethodType: AuthMethodTypes.SMS, + authenticateUser: + (AuthMethodTypes authMethodType, + isActive) => + authenticateUser( + authMethodType, isActive), + )), + Expanded( + child: MethodCard( + authMethodType: + AuthMethodTypes.WhatsApp, + authenticateUser: + (AuthMethodTypes authMethodType, + isActive) => + authenticateUser( + authMethodType, isActive), + )) + ], + ), + ]), + + // ) + ], + ), + ), + Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + model.user != null + ? Row( + children: [ + Expanded( + child: AppButton( + title: TranslationBase.of(context) + .useAnotherAccount, + color: Colors.red[700], + onPressed: () { + Navigator.of(context).pushNamed(LOGIN); + }, + )), + ], + ) + : SizedBox(), ], ), - )); - } - } - }); + ], + ), + ), + ), + ), + ), + )); } - + sendActivationCodeByOtpNotificationType( AuthMethodTypes authMethodType) async { - if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { + if (authMethodType == AuthMethodTypes.SMS || + authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.showMyDialog(context); int projectID = await sharedPref.getInt(PROJECT_ID); - // TODO create model for _loggedUser; + // TODO create model for model.loggedUser; ActivationCodeModel activationCodeModel = ActivationCodeModel( facilityId: projectID, - memberID: _loggedUser['List_MemberInformation'][0]['MemberID'], - zipCode: _loggedUser['ZipCode'], - mobileNumber: _loggedUser['MobileNumber'], + memberID: model.loggedUser['List_MemberInformation'][0]['MemberID'], + zipCode: model.loggedUser['ZipCode'], + mobileNumber: model.loggedUser['MobileNumber'], otpSendType: authMethodType.getTypeIdService().toString(), password: widget.password); - await widget.model - .sendActivationCodeForDoctorApp(activationCodeModel); - if(widget.model.state == ViewState.ErrorLocal) { - Helpers.showErrorToast(widget.model.error); - GifLoaderDialogUtils.hideDialog(context); - }else{ - print("VerificationCode : " + widget.model.activationCodeForDoctorAppRes["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeForDoctorAppRes["LogInTokenID"]); - sharedPref.setString(PASSWORD, widget.password); - GifLoaderDialogUtils.hideDialog(context); - this.startSMSService(authMethodType); - } + await model.sendActivationCodeForDoctorApp(activationCodeModel); + if (model.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(model.error); + GifLoaderDialogUtils.hideDialog(context); + } else { + print("VerificationCode : " + + model.activationCodeForDoctorAppRes["VerificationCode"]); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, + model.activationCodeForDoctorAppRes["VidaAuthTokenID"]); + sharedPref.setString(VIDA_REFRESH_TOKEN_ID, + model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]); + sharedPref.setString(LOGIN_TOKEN_ID, + model.activationCodeForDoctorAppRes["LogInTokenID"]); + sharedPref.setString(PASSWORD, widget.password); + GifLoaderDialogUtils.hideDialog(context); + this.startSMSService(authMethodType); + } } else { // TODO route to this page with parameters to inicate we should present 2 option if (Platform.isAndroid && authMethodType == AuthMethodTypes.Fingerprint) { Helpers.showErrorToast('Your device not support this feature'); - } else { - } + } else {} } } - sendActivationCodeVerificationScreen( - AuthMethodTypes authMethodType) async { + sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { GifLoaderDialogUtils.showMyDialog(context); - ActivationCodeForVerificationScreenModel activationCodeModel = ActivationCodeForVerificationScreenModel( - iMEI: user.iMEI, - facilityId: user.projectID, - memberID: user.doctorID, - zipCode: user.outSA == true ? '971' : '966', - mobileNumber: user.mobile, - oTPSendType: authMethodType ==AuthMethodTypes.FaceID?4:authMethodType ==AuthMethodTypes.Fingerprint?3:authMethodType ==AuthMethodTypes.WhatsApp?2:1, + ActivationCodeForVerificationScreenModel activationCodeModel = + ActivationCodeForVerificationScreenModel( + iMEI: model.user.iMEI, + facilityId: model.user.projectID, + memberID: model.user.doctorID, + zipCode: model.user.outSA == true ? '971' : '966', + mobileNumber: model.user.mobile, + oTPSendType: authMethodType.getTypeIdService(), isMobileFingerPrint: 1, - vidaAuthTokenID: user.vidaAuthTokenID, - vidaRefreshTokenID: user.vidaRefreshTokenID); + vidaAuthTokenID: model.user.vidaAuthTokenID, + vidaRefreshTokenID: model.user.vidaRefreshTokenID); - await widget.model + await model .sendActivationCodeVerificationScreen(activationCodeModel); - if(widget.model.state == ViewState.ErrorLocal) { + if (model.state == ViewState.ErrorLocal) { GifLoaderDialogUtils.hideDialog(context); - Helpers.showErrorToast(widget.model.error); + Helpers.showErrorToast(model.error); } else { - print("VerificationCode : " + widget.model.activationCodeVerificationScreenRes["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, widget.model.activationCodeVerificationScreenRes["LogInTokenID"]); - if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { - GifLoaderDialogUtils.hideDialog(context); - this.startSMSService(authMethodType); - } else { - checkActivationCode(); - } - } - } - - Widget methodCard(AuthMethodTypes authMethodType) { - switch (authMethodType) { - case AuthMethodTypes.WhatsApp: - return InkWell( - onTap: () => {authenticateUser(AuthMethodTypes.WhatsApp, true)}, - child: Container( - margin: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Image.asset( - 'assets/images/verify-whtsapp.png', - height: 60, - width: 60, - ), - ], - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifyWhatsApp, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - case AuthMethodTypes.SMS: - return InkWell( - onTap: () => {authenticateUser(AuthMethodTypes.SMS, true)}, - child: Container( - margin: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/verify-sms.png', - height: 60, - width: 60, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifySMS, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - case AuthMethodTypes.Fingerprint: - return InkWell( - onTap: () => { - if (checkIfBiometricAvailable(BiometricType.fingerprint)) - {authenticateUser(AuthMethodTypes.Fingerprint, true)} - }, - child: Container( - margin: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/verification_fingerprint_icon.png', - height: 60, - width: 60, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifyFingerprint, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - case AuthMethodTypes.FaceID: - return InkWell( - onTap: () { - if (checkIfBiometricAvailable(BiometricType.face)) { - authenticateUser(AuthMethodTypes.FaceID, true); - } - }, - child: - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - margin: EdgeInsets.all(10), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/verification_faceid_icon.png', - height: 60, - width: 60, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifyFaceID, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - - default: - return InkWell( - onTap: () => { - setState(() { - isMoreOption = true; - }) - }, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/login/more_icon.png', - height: 60, - width: 60, - ), - projectsProvider.isArabic - ? SizedBox( - height: 20, - ) - : SizedBox( - height: 10, - ), - AppText( - TranslationBase.of(context).moreVerification, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - } - } - - getType(type, context) { - switch (type) { - case 1: - return TranslationBase.of(context).verifySMS; - break; - case 3: - return TranslationBase.of(context).verifyFingerprint; - break; - case 4: - return TranslationBase.of(context).verifyFaceID; - break; - case 2: - return TranslationBase.of(context).verifyWhatsApp; - break; - default: - return TranslationBase.of(context).verifySMS; - break; - } - } - - bool checkIfBiometricAvailable(BiometricType biometricType) { - bool isAvailable = false; - if (_availableBiometrics != null) { - for (var i = 0; i < _availableBiometrics.length; i++) { - if (biometricType == _availableBiometrics[i]) isAvailable = true; + print("VerificationCode : " + + model.activationCodeVerificationScreenRes["VerificationCode"]); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, + model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); + sharedPref.setString( + VIDA_REFRESH_TOKEN_ID, + model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); + sharedPref.setString(LOGIN_TOKEN_ID, + model.activationCodeVerificationScreenRes["LogInTokenID"]); + if (authMethodType == AuthMethodTypes.SMS || + authMethodType == AuthMethodTypes.WhatsApp) { + GifLoaderDialogUtils.hideDialog(context); + this.startSMSService(authMethodType); + } else { + checkActivationCode(); } } - return isAvailable; } - - authenticateUser( AuthMethodTypes authMethodType, isActive) { - if (authMethodType == AuthMethodTypes.Fingerprint || authMethodType == AuthMethodTypes.FaceID) { - fingrePrintBefore = authMethodType; + authenticateUser(AuthMethodTypes authMethodType, isActive) { + if (authMethodType == AuthMethodTypes.Fingerprint || + authMethodType == AuthMethodTypes.FaceID) { + fingerPrintBefore = authMethodType; } - this.selectedOption = fingrePrintBefore != null ? fingrePrintBefore : authMethodType; + this.selectedOption = + fingerPrintBefore != null ? fingerPrintBefore : authMethodType; switch (authMethodType) { case AuthMethodTypes.SMS: @@ -632,7 +466,8 @@ class _VerificationMethodsState extends State { sendActivationCode(authMethodType); break; case AuthMethodTypes.Fingerprint: - this.loginWithFingerPrintOrFaceID(AuthMethodTypes.Fingerprint, isActive); + this.loginWithFingerPrintOrFaceID( + AuthMethodTypes.Fingerprint, isActive); break; case AuthMethodTypes.FaceID: this.loginWithFingerPrintOrFaceID(AuthMethodTypes.FaceID, isActive); @@ -643,23 +478,8 @@ class _VerificationMethodsState extends State { sharedPref.setInt(OTP_TYPE, selectedOption.getTypeIdService()); } - - Future _getAvailableBiometrics() async { - var availableBiometrics; - try { - availableBiometrics = await auth.getAvailableBiometrics(); - } on PlatformException catch (e) { - print(e); - } - if (!mounted) return; - - setState(() { - _availableBiometrics = availableBiometrics; - }); - } - sendActivationCode(AuthMethodTypes authMethodType) async { - if (user != null) { + if (model.user != null) { sendActivationCodeVerificationScreen(authMethodType); } else { sendActivationCodeByOtpNotificationType(authMethodType); @@ -667,10 +487,11 @@ class _VerificationMethodsState extends State { } startSMSService(AuthMethodTypes type) { + // TODO improve this logic new SMSOTP( context, type, - _loggedUser != null ? _loggedUser['MobileNumber'] : user.mobile, + model.loggedUser != null ? model.loggedUser['MobileNumber'] : model.user.mobile, (value) { showDialog( context: context, @@ -682,14 +503,16 @@ class _VerificationMethodsState extends State { this.checkActivationCode(value: value); }, - () => { + () => + { widget.changeLoadingState(false), print('Faild..'), }, ).displayDialog(context); } - loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async { + loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, + isActive) async { if (isActive) { const iosStrings = const IOSAuthMessages( cancelButton: 'cancel', @@ -707,7 +530,7 @@ class _VerificationMethodsState extends State { DrAppToastMsg.showErrorToast(e.toString()); } if (!mounted) return; - if (user != null && (user.logInTypeID == 3 || user.logInTypeID == 4)) { + if (model.user != null && (model.user.logInTypeID == 3 || model.user.logInTypeID == 4)) { this.sendActivationCode(authMethodTypes); } else { setState(() { @@ -717,34 +540,44 @@ class _VerificationMethodsState extends State { } } - checkActivationCode( {value}) async { + checkActivationCode({value}) async { CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = - new CheckActivationCodeRequestModel( - zipCode: - _loggedUser != null ? _loggedUser['ZipCode'] : user.zipCode, - mobileNumber: - _loggedUser != null ? _loggedUser['MobileNumber'] : user.mobile, - projectID: await sharedPref.getInt(PROJECT_ID) != null - ? await sharedPref.getInt(PROJECT_ID) - : user.projectID, - logInTokenID: await sharedPref.getString(LOGIN_TOKEN_ID), - activationCode: value ?? '0000', - oTPSendType: await sharedPref.getInt(OTP_TYPE), - generalid: "Cs2020@2016\$2958"); - await widget.model.checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp); - - if(widget.model.state == ViewState.ErrorLocal){ + new CheckActivationCodeRequestModel( + zipCode: + model.loggedUser != null ? model.loggedUser['ZipCode'] : model.user.zipCode, + mobileNumber: + model.loggedUser != null ? model.loggedUser['MobileNumber'] : model.user.mobile, + projectID: await sharedPref.getInt(PROJECT_ID) != null + ? await sharedPref.getInt(PROJECT_ID) + : model.user.projectID, + logInTokenID: await sharedPref.getString(LOGIN_TOKEN_ID), + activationCode: value ?? '0000', + oTPSendType: await sharedPref.getInt(OTP_TYPE), + generalid: "Cs2020@2016\$2958"); + await model + .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp); + + if (model.state == ViewState.ErrorLocal) { Navigator.pop(context); - Helpers.showErrorToast(widget.model.error); + Helpers.showErrorToast(model.error); } else { - sharedPref.setString(TOKEN, widget.model.checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); - if (widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != null) { - loginProcessCompleted(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); - sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + sharedPref.setString( + TOKEN, + model + .checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); + if (model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != + null) { + loginProcessCompleted(model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); + sharedPref.setObj( + CLINIC_NAME, + model + .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); } else { - sharedPref.setObj(CLINIC_NAME, widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); - ClinicModel clinic = - ClinicModel.fromJson(widget.model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); + sharedPref.setObj( + CLINIC_NAME, + model + .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); getDocProfiles(clinic); } } @@ -783,16 +616,4 @@ class _VerificationMethodsState extends State { Helpers.showErrorToast(err); }); } - - getDate(DateTime date) { - final DateFormat formatter = DateFormat('dd MMM yyyy'); - - return formatter.format(date); - } - - getTime(DateTime date) { - final DateFormat formatter = DateFormat('HH:mm a'); - - return formatter.format(date); - } } From 32d26c3c4b4445c2eff8618ef25bb4c2e9a039e3 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 5 May 2021 17:53:53 +0300 Subject: [PATCH 10/28] remove Verification Methods page and move some code to model --- .../viewModel/authentication_view_model.dart | 41 +- lib/routes.dart | 2 +- lib/screens/auth/login_screen.dart | 2 +- .../auth/verification_methods_screen.dart | 591 ++++++++++++++++- lib/widgets/auth/verification_methods.dart | 619 ------------------ 5 files changed, 609 insertions(+), 646 deletions(-) delete mode 100644 lib/widgets/auth/verification_methods.dart diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 474b91fe..a8dda45f 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -1,5 +1,6 @@ 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'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; @@ -88,8 +89,19 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async { + Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async { setState(ViewState.BusyLocal); + ActivationCodeForVerificationScreenModel activationCodeModel = + ActivationCodeForVerificationScreenModel( + iMEI: user.iMEI, + facilityId: user.projectID, + memberID: user.doctorID, + zipCode: user.outSA == true ? '971' : '966', + mobileNumber: user.mobile, + oTPSendType: authMethodType.getTypeIdService(), + isMobileFingerPrint: 1, + vidaAuthTokenID: user.vidaAuthTokenID, + vidaRefreshTokenID: user.vidaRefreshTokenID); await _authService.sendActivationCodeVerificationScreen(activationCodeModel); if (_authService.hasError) { error = _authService.error; @@ -98,8 +110,16 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future sendActivationCodeForDoctorApp(ActivationCodeModel activationCodeModel) async { + Future sendActivationCodeForDoctorApp({AuthMethodTypes authMethodType, String password }) async { setState(ViewState.BusyLocal); + int projectID = await sharedPref.getInt(PROJECT_ID); + ActivationCodeModel activationCodeModel = ActivationCodeModel( + facilityId: projectID, + memberID: loggedUser['List_MemberInformation'][0]['MemberID'], + zipCode: loggedUser['ZipCode'], + mobileNumber: loggedUser['MobileNumber'], + otpSendType: authMethodType.getTypeIdService().toString(), + password: password); await _authService.sendActivationCodeForDoctorApp(activationCodeModel); if (_authService.hasError) { error = _authService.error; @@ -108,9 +128,22 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel) async { + Future checkActivationCodeForDoctorApp({String activationCode}) async { setState(ViewState.BusyLocal); - await _authService.checkActivationCodeForDoctorApp(checkActivationCodeRequestModel); + CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = + new CheckActivationCodeRequestModel( + zipCode: + loggedUser != null ? loggedUser['ZipCode'] :user.zipCode, + mobileNumber: + loggedUser != null ? loggedUser['MobileNumber'] : user.mobile, + projectID: await sharedPref.getInt(PROJECT_ID) != null + ? await sharedPref.getInt(PROJECT_ID) + : user.projectID, + logInTokenID: await sharedPref.getString(LOGIN_TOKEN_ID), + activationCode: activationCode ?? '0000', + oTPSendType: await sharedPref.getInt(OTP_TYPE), + generalid: "Cs2020@2016\$2958"); + await _authService.checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp); if (_authService.hasError) { error = _authService.error; setState(ViewState.ErrorLocal); diff --git a/lib/routes.dart b/lib/routes.dart index 2684cd82..90e061b8 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -14,9 +14,9 @@ import 'package:doctor_app_flutter/screens/prescription/prescriptions_page.dart' import 'package:doctor_app_flutter/screens/procedures/procedure_screen.dart'; import 'package:doctor_app_flutter/screens/sick-leave/add-sickleave.dart'; import 'package:doctor_app_flutter/screens/sick-leave/show-sickleave.dart'; +import 'package:doctor_app_flutter/screens/auth/verification_methods_screen.dart'; import './screens/auth/login_screen.dart'; -import './screens/auth/verification_methods_screen.dart'; import 'screens/patients/profile/profile_screen/patient_profile_screen.dart'; import './screens/patients/profile/vital_sign/vital_sign_details_screen.dart'; import 'landing_page.dart'; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 707e178c..0048b10c 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -10,10 +10,10 @@ 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/models/doctor/user_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/screens/auth/verification_methods_screen.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'; diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index e4d2603d..2b906588 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -1,42 +1,591 @@ +import 'dart:io' show Platform; + +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/model/imei_details.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/models/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; +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/screens/base/base_view.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/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/auth/sms-popup.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/loader/gif_loader_dialog_utils.dart'; +import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; +import 'package:flutter/services.dart'; +import 'package:local_auth/auth_strings.dart'; +import 'package:local_auth/local_auth.dart'; +import 'package:provider/provider.dart'; -import '../../widgets/auth/verification_methods.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'; +import '../../util/helpers.dart'; +import '../../widgets/auth/method_card.dart'; -class VerificationMethodsScreen extends StatefulWidget { - const VerificationMethodsScreen({Key key, this.password}) : super(key: key); +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); +Helpers helpers = Helpers(); - @override - _VerificationMethodsScreenState createState() => - _VerificationMethodsScreenState(); +class VerificationMethodsScreen extends StatefulWidget { + VerificationMethodsScreen({this.changeLoadingState, this.password}); final password; + final Function changeLoadingState; + + @override + _VerificationMethodsScreenState createState() => _VerificationMethodsScreenState(); } class _VerificationMethodsScreenState extends State { - bool _isLoading = false; + + ProjectViewModel projectsProvider; + bool isMoreOption = false; + bool onlySMSBox = false; + var loginTokenID; + DoctorProfileViewModel doctorProfileViewModel; - void changeLoadingState(isLoading) { - setState(() { - _isLoading = isLoading; - }); + bool authenticated; + + AuthMethodTypes fingerPrintBefore; + + AuthMethodTypes selectedOption; + AuthenticationViewModel model; + + final LocalAuthentication auth = LocalAuthentication(); + + @override + void initState() { + super.initState(); + } + + + @override + void didChangeDependencies() async{ + super.didChangeDependencies(); + } @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( - isLoading: _isLoading, - isShowAppBar: false, - isHomeIcon: false, - backgroundColor: HexColor('#F8F8F8'), - body:VerificationMethods( - password: widget.password, - changeLoadingState: changeLoadingState, - // model:model - ))); + isShowAppBar: false, + baseViewModel: model, + body: SingleChildScrollView( + child: Center( + child: FractionallySizedBox( + // widthFactor: 0.9, + 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: [ + Container( + child: Column( + + children: [ + SizedBox( + height: 100, + ), + model.user != null && isMoreOption == false + ? Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + 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 + ? model.getDate( + DateUtils + .convertStringToDate( + model.user + .editedOn)) + : model.user.createdOn != null + ? model + .getDate(DateUtils + .convertStringToDate( + model.user.createdOn)) + : '--', + textAlign: TextAlign.right, + fontSize: 14, + fontWeight: FontWeight.w800, + ), + subtitle: AppText( + model.user.editedOn != null + ? model.getTime( + DateUtils + .convertStringToDate( + model.user + .editedOn)) + : model.user.createdOn != null + ? model + .getTime(DateUtils + .convertStringToDate( + model.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, + ), + ]), + model.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: MethodCard( + authMethodType: model.user + .logInTypeID == + 4 + ? AuthMethodTypes.FaceID + : model.user.logInTypeID == 2 + ? AuthMethodTypes + .WhatsApp + : model.user.logInTypeID == + 3 + ? AuthMethodTypes + .Fingerprint + : AuthMethodTypes + .SMS, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )), + ), + Expanded( + child: MethodCard( + authMethodType: + AuthMethodTypes.MoreOptions, + onShowMore: () { + setState(() { + isMoreOption = true; + }); + }, + )) + ]), + ]) + : Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + onlySMSBox == false + ? Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + child: MethodCard( + authMethodType: + AuthMethodTypes.Fingerprint, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )), + Expanded( + child: MethodCard( + authMethodType: + AuthMethodTypes.FaceID, + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), + )) + ], + ) + : SizedBox(), + Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + child: MethodCard( + authMethodType: AuthMethodTypes.SMS, + authenticateUser: + (AuthMethodTypes authMethodType, + isActive) => + authenticateUser( + authMethodType, isActive), + )), + Expanded( + child: MethodCard( + authMethodType: + AuthMethodTypes.WhatsApp, + authenticateUser: + (AuthMethodTypes authMethodType, + isActive) => + authenticateUser( + authMethodType, isActive), + )) + ], + ), + ]), + + // ) + ], + ), + ), + Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + model.user != null + ? Row( + children: [ + Expanded( + child: AppButton( + title: TranslationBase.of(context) + .useAnotherAccount, + color: Colors.red[700], + onPressed: () { + Navigator.of(context).pushNamed(LOGIN); + }, + )), + ], + ) + : SizedBox(), + ], + ), + ], + ), + ), + ), + ), + ), + )); + } + + sendActivationCodeByOtpNotificationType( + AuthMethodTypes authMethodType) async { + if (authMethodType == AuthMethodTypes.SMS || + authMethodType == AuthMethodTypes.WhatsApp) { + GifLoaderDialogUtils.showMyDialog(context); + + + await model.sendActivationCodeForDoctorApp(authMethodType:authMethodType, password: widget.password ); + if (model.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(model.error); + GifLoaderDialogUtils.hideDialog(context); + } else { + // TODO move it model + print("VerificationCode : " + + model.activationCodeForDoctorAppRes["VerificationCode"]); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, + model.activationCodeForDoctorAppRes["VidaAuthTokenID"]); + sharedPref.setString(VIDA_REFRESH_TOKEN_ID, + model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]); + sharedPref.setString(LOGIN_TOKEN_ID, + model.activationCodeForDoctorAppRes["LogInTokenID"]); + sharedPref.setString(PASSWORD, widget.password); + GifLoaderDialogUtils.hideDialog(context); + this.startSMSService(authMethodType); + } + } else { + // TODO route to this page with parameters to inicate we should present 2 option + if (Platform.isAndroid && authMethodType == AuthMethodTypes.Fingerprint) { + Helpers.showErrorToast('Your device not support this feature'); + } else {} + } + } + + sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { + GifLoaderDialogUtils.showMyDialog(context); + + + await model + .sendActivationCodeVerificationScreen(authMethodType); + + if (model.state == ViewState.ErrorLocal) { + GifLoaderDialogUtils.hideDialog(context); + Helpers.showErrorToast(model.error); + } else { + //TODO Move it to view model + print("VerificationCode : " + + model.activationCodeVerificationScreenRes["VerificationCode"]); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, + model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); + sharedPref.setString( + VIDA_REFRESH_TOKEN_ID, + model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); + sharedPref.setString(LOGIN_TOKEN_ID, + model.activationCodeVerificationScreenRes["LogInTokenID"]); + if (authMethodType == AuthMethodTypes.SMS || + authMethodType == AuthMethodTypes.WhatsApp) { + GifLoaderDialogUtils.hideDialog(context); + this.startSMSService(authMethodType); + } else { + checkActivationCode(); + } + } + } + + authenticateUser(AuthMethodTypes authMethodType, isActive) { + if (authMethodType == AuthMethodTypes.Fingerprint || + authMethodType == AuthMethodTypes.FaceID) { + fingerPrintBefore = authMethodType; + } + this.selectedOption = + fingerPrintBefore != null ? fingerPrintBefore : authMethodType; + + switch (authMethodType) { + case AuthMethodTypes.SMS: + sendActivationCode(authMethodType); + break; + case AuthMethodTypes.WhatsApp: + sendActivationCode(authMethodType); + break; + case AuthMethodTypes.Fingerprint: + this.loginWithFingerPrintOrFaceID( + AuthMethodTypes.Fingerprint, isActive); + break; + case AuthMethodTypes.FaceID: + this.loginWithFingerPrintOrFaceID(AuthMethodTypes.FaceID, isActive); + break; + default: + break; + } + sharedPref.setInt(OTP_TYPE, selectedOption.getTypeIdService()); + } + + sendActivationCode(AuthMethodTypes authMethodType) async { + if (model.user != null) { + sendActivationCodeVerificationScreen(authMethodType); + } else { + sendActivationCodeByOtpNotificationType(authMethodType); + } + } + + startSMSService(AuthMethodTypes type) { + // TODO improve this logic + new SMSOTP( + context, + type, + model.loggedUser != null ? model.loggedUser['MobileNumber'] : model.user.mobile, + (value) { + showDialog( + context: context, + builder: (BuildContext context) { + return Center( + child: CircularProgressIndicator(), + ); + }); + + this.checkActivationCode(value: value); + }, + () => + { + widget.changeLoadingState(false), + print('Faild..'), + }, + ).displayDialog(context); + } + + loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, + isActive) async { + if (isActive) { + const iosStrings = const IOSAuthMessages( + cancelButton: 'cancel', + goToSettingsButton: 'settings', + goToSettingsDescription: 'Please set up your Touch ID.', + lockOut: 'Please reenable your Touch ID'); + + try { + authenticated = await auth.authenticateWithBiometrics( + localizedReason: 'Scan your fingerprint to authenticate', + useErrorDialogs: true, + stickyAuth: true, + iOSAuthStrings: iosStrings); + } on PlatformException catch (e) { + DrAppToastMsg.showErrorToast(e.toString()); + } + if (!mounted) return; + if (model.user != null && (model.user.logInTypeID == 3 || model.user.logInTypeID == 4)) { + this.sendActivationCode(authMethodTypes); + } else { + setState(() { + this.onlySMSBox = true; + }); + } + } + } + + checkActivationCode({value}) async { + + await model + .checkActivationCodeForDoctorApp(activationCode:value ); + + if (model.state == ViewState.ErrorLocal) { + Navigator.pop(context); + Helpers.showErrorToast(model.error); + } else { + sharedPref.setString( + TOKEN, + model + .checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); + if (model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != + null) { + loginProcessCompleted(model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); + sharedPref.setObj( + CLINIC_NAME, + model + .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + } else { + sharedPref.setObj( + CLINIC_NAME, + model + .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); + getDocProfiles(clinic); + } + } + } + + loginProcessCompleted(Map profile) { + var doctor = DoctorProfileModel.fromJson(profile); + doctorProfileViewModel.setDoctorProfile(doctor); + sharedPref.setObj(DOCTOR_PROFILE, profile); + projectsProvider.isLogin = true; + + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: LandingPage(), + ), + (r) => false); + } + + getDocProfiles(ClinicModel clinicInfo) { + ProfileReqModel docInfo = new ProfileReqModel( + doctorID: clinicInfo.doctorID, + clinicID: clinicInfo.clinicID, + license: true, + projectID: clinicInfo.projectID, + tokenID: '', + languageID: 2); + doctorProfileViewModel.getDocProfiles(docInfo.toJson()).then((res) { + if (res['MessageStatus'] == 1) { + loginProcessCompleted(res['DoctorProfileList'][0]); + } else { + // changeLoadingState(false); + Helpers.showErrorToast(res['ErrorEndUserMessage']); + } + }).catchError((err) { + Helpers.showErrorToast(err); + }); } } diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart deleted file mode 100644 index faadbf9e..00000000 --- a/lib/widgets/auth/verification_methods.dart +++ /dev/null @@ -1,619 +0,0 @@ -import 'dart:io' show Platform; - -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/model/imei_details.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/models/auth/activation_Code_req_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; -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/screens/base/base_view.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/translations_delegate_base.dart'; -import 'package:doctor_app_flutter/widgets/auth/sms-popup.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/loader/gif_loader_dialog_utils.dart'; -import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:local_auth/auth_strings.dart'; -import 'package:local_auth/local_auth.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'; -import '../../util/helpers.dart'; -import 'method_card.dart'; - -DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); -Helpers helpers = Helpers(); - -class VerificationMethods extends StatefulWidget { - VerificationMethods({this.changeLoadingState, this.password}); - - final password; - final Function changeLoadingState; - - @override - _VerificationMethodsState createState() => _VerificationMethodsState(); -} - -class _VerificationMethodsState extends State { - - ProjectViewModel projectsProvider; - bool isMoreOption = false; - bool onlySMSBox = false; - var loginTokenID; - DoctorProfileViewModel doctorProfileViewModel; - - bool authenticated; - - AuthMethodTypes fingerPrintBefore; - - AuthMethodTypes selectedOption; - AuthenticationViewModel model; - - final LocalAuthentication auth = LocalAuthentication(); - - @override - void initState() { - super.initState(); - } - - - @override - void didChangeDependencies() async{ - super.didChangeDependencies(); - - } - - @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( - // widthFactor: 0.9, - 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: [ - Container( - child: Column( - - children: [ - SizedBox( - height: 100, - ), - model.user != null && isMoreOption == false - ? Column( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - 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 - ? model.getDate( - DateUtils - .convertStringToDate( - model.user - .editedOn)) - : model.user.createdOn != null - ? model - .getDate(DateUtils - .convertStringToDate( - model.user.createdOn)) - : '--', - textAlign: TextAlign.right, - fontSize: 14, - fontWeight: FontWeight.w800, - ), - subtitle: AppText( - model.user.editedOn != null - ? model.getTime( - DateUtils - .convertStringToDate( - model.user - .editedOn)) - : model.user.createdOn != null - ? model - .getTime(DateUtils - .convertStringToDate( - model.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, - ), - ]), - model.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: MethodCard( - authMethodType: model.user - .logInTypeID == - 4 - ? AuthMethodTypes.FaceID - : model.user.logInTypeID == 2 - ? AuthMethodTypes - .WhatsApp - : model.user.logInTypeID == - 3 - ? AuthMethodTypes - .Fingerprint - : AuthMethodTypes - .SMS, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => - authenticateUser( - authMethodType, - isActive), - )), - ), - Expanded( - child: MethodCard( - authMethodType: - AuthMethodTypes.MoreOptions, - onShowMore: () { - setState(() { - isMoreOption = true; - }); - }, - )) - ]), - ]) - : Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - onlySMSBox == false - ? Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: MethodCard( - authMethodType: - AuthMethodTypes.Fingerprint, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => - authenticateUser( - authMethodType, - isActive), - )), - Expanded( - child: MethodCard( - authMethodType: - AuthMethodTypes.FaceID, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => - authenticateUser( - authMethodType, - isActive), - )) - ], - ) - : SizedBox(), - Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - child: MethodCard( - authMethodType: AuthMethodTypes.SMS, - authenticateUser: - (AuthMethodTypes authMethodType, - isActive) => - authenticateUser( - authMethodType, isActive), - )), - Expanded( - child: MethodCard( - authMethodType: - AuthMethodTypes.WhatsApp, - authenticateUser: - (AuthMethodTypes authMethodType, - isActive) => - authenticateUser( - authMethodType, isActive), - )) - ], - ), - ]), - - // ) - ], - ), - ), - Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - model.user != null - ? Row( - children: [ - Expanded( - child: AppButton( - title: TranslationBase.of(context) - .useAnotherAccount, - color: Colors.red[700], - onPressed: () { - Navigator.of(context).pushNamed(LOGIN); - }, - )), - ], - ) - : SizedBox(), - ], - ), - ], - ), - ), - ), - ), - ), - )); - } - - sendActivationCodeByOtpNotificationType( - AuthMethodTypes authMethodType) async { - if (authMethodType == AuthMethodTypes.SMS || - authMethodType == AuthMethodTypes.WhatsApp) { - GifLoaderDialogUtils.showMyDialog(context); - - int projectID = await sharedPref.getInt(PROJECT_ID); - // TODO create model for model.loggedUser; - ActivationCodeModel activationCodeModel = ActivationCodeModel( - facilityId: projectID, - memberID: model.loggedUser['List_MemberInformation'][0]['MemberID'], - zipCode: model.loggedUser['ZipCode'], - mobileNumber: model.loggedUser['MobileNumber'], - otpSendType: authMethodType.getTypeIdService().toString(), - password: widget.password); - await model.sendActivationCodeForDoctorApp(activationCodeModel); - if (model.state == ViewState.ErrorLocal) { - Helpers.showErrorToast(model.error); - GifLoaderDialogUtils.hideDialog(context); - } else { - print("VerificationCode : " + - model.activationCodeForDoctorAppRes["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeForDoctorAppRes["VidaAuthTokenID"]); - sharedPref.setString(VIDA_REFRESH_TOKEN_ID, - model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeForDoctorAppRes["LogInTokenID"]); - sharedPref.setString(PASSWORD, widget.password); - GifLoaderDialogUtils.hideDialog(context); - this.startSMSService(authMethodType); - } - } else { - // TODO route to this page with parameters to inicate we should present 2 option - if (Platform.isAndroid && authMethodType == AuthMethodTypes.Fingerprint) { - Helpers.showErrorToast('Your device not support this feature'); - } else {} - } - } - - sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { - GifLoaderDialogUtils.showMyDialog(context); - ActivationCodeForVerificationScreenModel activationCodeModel = - ActivationCodeForVerificationScreenModel( - iMEI: model.user.iMEI, - facilityId: model.user.projectID, - memberID: model.user.doctorID, - zipCode: model.user.outSA == true ? '971' : '966', - mobileNumber: model.user.mobile, - oTPSendType: authMethodType.getTypeIdService(), - isMobileFingerPrint: 1, - vidaAuthTokenID: model.user.vidaAuthTokenID, - vidaRefreshTokenID: model.user.vidaRefreshTokenID); - - await model - .sendActivationCodeVerificationScreen(activationCodeModel); - - if (model.state == ViewState.ErrorLocal) { - GifLoaderDialogUtils.hideDialog(context); - Helpers.showErrorToast(model.error); - } else { - print("VerificationCode : " + - model.activationCodeVerificationScreenRes["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, - model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeVerificationScreenRes["LogInTokenID"]); - if (authMethodType == AuthMethodTypes.SMS || - authMethodType == AuthMethodTypes.WhatsApp) { - GifLoaderDialogUtils.hideDialog(context); - this.startSMSService(authMethodType); - } else { - checkActivationCode(); - } - } - } - - authenticateUser(AuthMethodTypes authMethodType, isActive) { - if (authMethodType == AuthMethodTypes.Fingerprint || - authMethodType == AuthMethodTypes.FaceID) { - fingerPrintBefore = authMethodType; - } - this.selectedOption = - fingerPrintBefore != null ? fingerPrintBefore : authMethodType; - - switch (authMethodType) { - case AuthMethodTypes.SMS: - sendActivationCode(authMethodType); - break; - case AuthMethodTypes.WhatsApp: - sendActivationCode(authMethodType); - break; - case AuthMethodTypes.Fingerprint: - this.loginWithFingerPrintOrFaceID( - AuthMethodTypes.Fingerprint, isActive); - break; - case AuthMethodTypes.FaceID: - this.loginWithFingerPrintOrFaceID(AuthMethodTypes.FaceID, isActive); - break; - default: - break; - } - sharedPref.setInt(OTP_TYPE, selectedOption.getTypeIdService()); - } - - sendActivationCode(AuthMethodTypes authMethodType) async { - if (model.user != null) { - sendActivationCodeVerificationScreen(authMethodType); - } else { - sendActivationCodeByOtpNotificationType(authMethodType); - } - } - - startSMSService(AuthMethodTypes type) { - // TODO improve this logic - new SMSOTP( - context, - type, - model.loggedUser != null ? model.loggedUser['MobileNumber'] : model.user.mobile, - (value) { - showDialog( - context: context, - builder: (BuildContext context) { - return Center( - child: CircularProgressIndicator(), - ); - }); - - this.checkActivationCode(value: value); - }, - () => - { - widget.changeLoadingState(false), - print('Faild..'), - }, - ).displayDialog(context); - } - - loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, - isActive) async { - if (isActive) { - const iosStrings = const IOSAuthMessages( - cancelButton: 'cancel', - goToSettingsButton: 'settings', - goToSettingsDescription: 'Please set up your Touch ID.', - lockOut: 'Please reenable your Touch ID'); - - try { - authenticated = await auth.authenticateWithBiometrics( - localizedReason: 'Scan your fingerprint to authenticate', - useErrorDialogs: true, - stickyAuth: true, - iOSAuthStrings: iosStrings); - } on PlatformException catch (e) { - DrAppToastMsg.showErrorToast(e.toString()); - } - if (!mounted) return; - if (model.user != null && (model.user.logInTypeID == 3 || model.user.logInTypeID == 4)) { - this.sendActivationCode(authMethodTypes); - } else { - setState(() { - this.onlySMSBox = true; - }); - } - } - } - - checkActivationCode({value}) async { - CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = - new CheckActivationCodeRequestModel( - zipCode: - model.loggedUser != null ? model.loggedUser['ZipCode'] : model.user.zipCode, - mobileNumber: - model.loggedUser != null ? model.loggedUser['MobileNumber'] : model.user.mobile, - projectID: await sharedPref.getInt(PROJECT_ID) != null - ? await sharedPref.getInt(PROJECT_ID) - : model.user.projectID, - logInTokenID: await sharedPref.getString(LOGIN_TOKEN_ID), - activationCode: value ?? '0000', - oTPSendType: await sharedPref.getInt(OTP_TYPE), - generalid: "Cs2020@2016\$2958"); - await model - .checkActivationCodeForDoctorApp(checkActivationCodeForDoctorApp); - - if (model.state == ViewState.ErrorLocal) { - Navigator.pop(context); - Helpers.showErrorToast(model.error); - } else { - sharedPref.setString( - TOKEN, - model - .checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); - if (model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != - null) { - loginProcessCompleted(model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); - sharedPref.setObj( - CLINIC_NAME, - model - .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); - } else { - sharedPref.setObj( - CLINIC_NAME, - model - .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); - ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); - getDocProfiles(clinic); - } - } - } - - loginProcessCompleted(Map profile) { - var doctor = DoctorProfileModel.fromJson(profile); - doctorProfileViewModel.setDoctorProfile(doctor); - sharedPref.setObj(DOCTOR_PROFILE, profile); - projectsProvider.isLogin = true; - - Navigator.pushAndRemoveUntil( - context, - FadePage( - page: LandingPage(), - ), - (r) => false); - } - - getDocProfiles(ClinicModel clinicInfo) { - ProfileReqModel docInfo = new ProfileReqModel( - doctorID: clinicInfo.doctorID, - clinicID: clinicInfo.clinicID, - license: true, - projectID: clinicInfo.projectID, - tokenID: '', - languageID: 2); - doctorProfileViewModel.getDocProfiles(docInfo.toJson()).then((res) { - if (res['MessageStatus'] == 1) { - loginProcessCompleted(res['DoctorProfileList'][0]); - } else { - // changeLoadingState(false); - Helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - Helpers.showErrorToast(err); - }); - } -} From 333d1e3f50d8e3c4b397ff9a8cd9a8dd200005cf Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 6 May 2021 13:45:25 +0300 Subject: [PATCH 11/28] first step from models --- ios/Podfile.lock | 2 +- .../auth/activation_Code_req_model.dart | 0 ...on_code_for_verification_screen_model.dart | 0 .../check_activation_code_request_model.dart | 0 lib/core/model/{ => auth}/imei_details.dart | 0 .../model/{ => auth}/insert_imei_model.dart | 0 .../new_login_information_response_model.dart | 113 ++++++++++++++++++ ...on_code_for_doctor_app_response_model.dart | 29 +++++ lib/core/service/authentication_service.dart | 30 ++--- .../viewModel/authentication_view_model.dart | 34 +++--- lib/screens/auth/login_screen.dart | 25 ++-- .../auth/verification_methods_screen.dart | 18 ++- 12 files changed, 198 insertions(+), 53 deletions(-) rename lib/{models => core/model}/auth/activation_Code_req_model.dart (100%) rename lib/{models => core/model}/auth/activation_code_for_verification_screen_model.dart (100%) rename lib/{models => core/model}/auth/check_activation_code_request_model.dart (100%) rename lib/core/model/{ => auth}/imei_details.dart (100%) rename lib/core/model/{ => auth}/insert_imei_model.dart (100%) create mode 100644 lib/core/model/auth/new_login_information_response_model.dart create mode 100644 lib/core/model/auth/send_activation_code_for_doctor_app_response_model.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 878a1850..2f4607e0 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -322,4 +322,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 -COCOAPODS: 1.10.1 +COCOAPODS: 1.10.0.rc.1 diff --git a/lib/models/auth/activation_Code_req_model.dart b/lib/core/model/auth/activation_Code_req_model.dart similarity index 100% rename from lib/models/auth/activation_Code_req_model.dart rename to lib/core/model/auth/activation_Code_req_model.dart diff --git a/lib/models/auth/activation_code_for_verification_screen_model.dart b/lib/core/model/auth/activation_code_for_verification_screen_model.dart similarity index 100% rename from lib/models/auth/activation_code_for_verification_screen_model.dart rename to lib/core/model/auth/activation_code_for_verification_screen_model.dart diff --git a/lib/models/auth/check_activation_code_request_model.dart b/lib/core/model/auth/check_activation_code_request_model.dart similarity index 100% rename from lib/models/auth/check_activation_code_request_model.dart rename to lib/core/model/auth/check_activation_code_request_model.dart diff --git a/lib/core/model/imei_details.dart b/lib/core/model/auth/imei_details.dart similarity index 100% rename from lib/core/model/imei_details.dart rename to lib/core/model/auth/imei_details.dart diff --git a/lib/core/model/insert_imei_model.dart b/lib/core/model/auth/insert_imei_model.dart similarity index 100% rename from lib/core/model/insert_imei_model.dart rename to lib/core/model/auth/insert_imei_model.dart diff --git a/lib/core/model/auth/new_login_information_response_model.dart b/lib/core/model/auth/new_login_information_response_model.dart new file mode 100644 index 00000000..117060e4 --- /dev/null +++ b/lib/core/model/auth/new_login_information_response_model.dart @@ -0,0 +1,113 @@ +class NewLoginInformationModel { + int doctorID; + List listMemberInformation; + String logInTokenID; + String mobileNumber; + Null sELECTDeviceIMEIbyIMEIList; + int userID; + String zipCode; + bool isActiveCode; + bool isSMSSent; + + NewLoginInformationModel( + {this.doctorID, + this.listMemberInformation, + this.logInTokenID, + this.mobileNumber, + this.sELECTDeviceIMEIbyIMEIList, + this.userID, + this.zipCode, + this.isActiveCode, + this.isSMSSent}); + + NewLoginInformationModel.fromJson(Map json) { + doctorID = json['DoctorID']; + if (json['List_MemberInformation'] != null) { + listMemberInformation = new List(); + json['List_MemberInformation'].forEach((v) { + listMemberInformation.add(new ListMemberInformation.fromJson(v)); + }); + } + logInTokenID = json['LogInTokenID']; + mobileNumber = json['MobileNumber']; + sELECTDeviceIMEIbyIMEIList = json['SELECTDeviceIMEIbyIMEI_List']; + userID = json['UserID']; + zipCode = json['ZipCode']; + isActiveCode = json['isActiveCode']; + isSMSSent = json['isSMSSent']; + } + + Map toJson() { + final Map data = new Map(); + data['DoctorID'] = this.doctorID; + if (this.listMemberInformation != null) { + data['List_MemberInformation'] = + this.listMemberInformation.map((v) => v.toJson()).toList(); + } + data['LogInTokenID'] = this.logInTokenID; + data['MobileNumber'] = this.mobileNumber; + data['SELECTDeviceIMEIbyIMEI_List'] = this.sELECTDeviceIMEIbyIMEIList; + data['UserID'] = this.userID; + data['ZipCode'] = this.zipCode; + data['isActiveCode'] = this.isActiveCode; + data['isSMSSent'] = this.isSMSSent; + return data; + } +} + +class ListMemberInformation { + Null setupID; + int memberID; + String memberName; + Null memberNameN; + String preferredLang; + String pIN; + String saltHash; + int referenceID; + int employeeID; + int roleID; + int projectid; + + ListMemberInformation( + {this.setupID, + this.memberID, + this.memberName, + this.memberNameN, + this.preferredLang, + this.pIN, + this.saltHash, + this.referenceID, + this.employeeID, + this.roleID, + this.projectid}); + + ListMemberInformation.fromJson(Map json) { + setupID = json['SetupID']; + memberID = json['MemberID']; + memberName = json['MemberName']; + memberNameN = json['MemberNameN']; + preferredLang = json['PreferredLang']; + pIN = json['PIN']; + saltHash = json['SaltHash']; + referenceID = json['ReferenceID']; + employeeID = json['EmployeeID']; + roleID = json['RoleID']; + projectid = json['projectid']; + } + + Map toJson() { + final Map data = new Map(); + data['SetupID'] = this.setupID; + data['MemberID'] = this.memberID; + data['MemberName'] = this.memberName; + data['MemberNameN'] = this.memberNameN; + data['PreferredLang'] = this.preferredLang; + data['PIN'] = this.pIN; + data['SaltHash'] = this.saltHash; + data['ReferenceID'] = this.referenceID; + data['EmployeeID'] = this.employeeID; + data['RoleID'] = this.roleID; + data['projectid'] = this.projectid; + return data; + } +} diff --git a/lib/core/model/auth/send_activation_code_for_doctor_app_response_model.dart b/lib/core/model/auth/send_activation_code_for_doctor_app_response_model.dart new file mode 100644 index 00000000..ceaf4c65 --- /dev/null +++ b/lib/core/model/auth/send_activation_code_for_doctor_app_response_model.dart @@ -0,0 +1,29 @@ +class SendActivationCodeForDoctorAppResponseModel { + String logInTokenID; + String verificationCode; + String vidaAuthTokenID; + String vidaRefreshTokenID; + + SendActivationCodeForDoctorAppResponseModel( + {this.logInTokenID, + this.verificationCode, + this.vidaAuthTokenID, + this.vidaRefreshTokenID}); + + SendActivationCodeForDoctorAppResponseModel.fromJson( + Map json) { + logInTokenID = json['LogInTokenID']; + verificationCode = json['VerificationCode']; + vidaAuthTokenID = json['VidaAuthTokenID']; + vidaRefreshTokenID = json['VidaRefreshTokenID']; + } + + Map toJson() { + final Map data = new Map(); + data['LogInTokenID'] = this.logInTokenID; + data['VerificationCode'] = this.verificationCode; + data['VidaAuthTokenID'] = this.vidaAuthTokenID; + data['VidaRefreshTokenID'] = this.vidaRefreshTokenID; + return data; + } +} diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index 59d8e34a..18624d58 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -1,11 +1,13 @@ import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/core/model/imei_details.dart'; -import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; +import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:provider/provider.dart'; @@ -14,15 +16,15 @@ class AuthenticationService extends BaseService { List _imeiDetails = []; List get dashboardItemsList => _imeiDetails; //TODO Change this to models - Map _loginInfo = {}; - Map get loginInfo => _loginInfo; + NewLoginInformationModel _loginInfo = NewLoginInformationModel(); + NewLoginInformationModel get loginInfo => _loginInfo; Map _activationCodeVerificationScreenRes = {}; Map get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes; - Map _activationCodeForDoctorAppRes = {}; + SendActivationCodeForDoctorAppResponseModel _activationCodeForDoctorAppRes = SendActivationCodeForDoctorAppResponseModel(); - Map get activationCodeForDoctorAppRes => _activationCodeForDoctorAppRes; + SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _activationCodeForDoctorAppRes; Map _checkActivationCodeForDoctorAppRes = {}; Map get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; @@ -31,7 +33,6 @@ class AuthenticationService extends BaseService { Map get insertDeviceImeiRes => _insertDeviceImeiRes; Future selectDeviceImei(imei) async { try { - // dynamic localRes; await baseAppClient.post(SELECT_DEVICE_IMEI, onSuccess: (dynamic response, int statusCode) { _imeiDetails = []; @@ -42,7 +43,6 @@ class AuthenticationService extends BaseService { hasError = true; super.error = error; }, body: {"IMEI": imei, "TokenID": "@dm!n"}); - //return Future.value(localRes); } catch (error) { hasError = true; super.error = error; @@ -51,11 +51,11 @@ class AuthenticationService extends BaseService { Future login(UserModel userInfo) async { hasError = false; - _loginInfo = {}; + _loginInfo = NewLoginInformationModel(); try { await baseAppClient.post(LOGIN_URL, onSuccess: (dynamic response, int statusCode) { - _loginInfo = response; + _loginInfo = NewLoginInformationModel.fromJson(response); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; @@ -87,11 +87,11 @@ class AuthenticationService extends BaseService { Future sendActivationCodeForDoctorApp(ActivationCodeModel activationCodeModel)async { hasError = false; - _activationCodeForDoctorAppRes = {}; + _activationCodeForDoctorAppRes = SendActivationCodeForDoctorAppResponseModel(); try { await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_DOCTOR_APP, onSuccess: (dynamic response, int statusCode) { - _activationCodeForDoctorAppRes = response; + _activationCodeForDoctorAppRes = SendActivationCodeForDoctorAppResponseModel.fromJson(response); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index a8dda45f..a9986cec 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -2,17 +2,19 @@ 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'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; -import 'package:doctor_app_flutter/core/model/imei_details.dart'; -import 'package:doctor_app_flutter/core/model/insert_imei_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; -import 'package:doctor_app_flutter/models/auth/activation_Code_req_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/models/doctor/user_model.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:intl/intl.dart'; @@ -23,12 +25,12 @@ class AuthenticationViewModel extends BaseViewModel { List get imeiDetails => _authService.dashboardItemsList; List get hospitals => _hospitalsService.hospitals; - get loginInfo => _authService.loginInfo; + NewLoginInformationModel get loginInfo => _authService.loginInfo; get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; - get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; + SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; - var loggedUser; + NewLoginInformationModel loggedUser; GetIMEIDetailsModel user; Future selectDeviceImei(imei) async { setState(ViewState.Busy); @@ -115,9 +117,9 @@ class AuthenticationViewModel extends BaseViewModel { int projectID = await sharedPref.getInt(PROJECT_ID); ActivationCodeModel activationCodeModel = ActivationCodeModel( facilityId: projectID, - memberID: loggedUser['List_MemberInformation'][0]['MemberID'], - zipCode: loggedUser['ZipCode'], - mobileNumber: loggedUser['MobileNumber'], + memberID: loggedUser.listMemberInformation[0].memberID, + zipCode: loggedUser.zipCode, + mobileNumber: loggedUser.mobileNumber, otpSendType: authMethodType.getTypeIdService().toString(), password: password); await _authService.sendActivationCodeForDoctorApp(activationCodeModel); @@ -133,9 +135,9 @@ class AuthenticationViewModel extends BaseViewModel { CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = new CheckActivationCodeRequestModel( zipCode: - loggedUser != null ? loggedUser['ZipCode'] :user.zipCode, + loggedUser != null ? loggedUser.zipCode :user.zipCode, mobileNumber: - loggedUser != null ? loggedUser['MobileNumber'] : user.mobile, + loggedUser != null ? loggedUser.mobileNumber : user.mobile, projectID: await sharedPref.getInt(PROJECT_ID) != null ? await sharedPref.getInt(PROJECT_ID) : user.projectID, @@ -208,7 +210,11 @@ class AuthenticationViewModel extends BaseViewModel { getInitUserInfo()async{ setState(ViewState.Busy); - loggedUser = await sharedPref.getObj(LOGGED_IN_USER); + var localLoggedUser = await sharedPref.getObj(LOGGED_IN_USER); + if(localLoggedUser!= null) { + loggedUser = NewLoginInformationModel.fromJson(localLoggedUser); + + } var lastLogin = await sharedPref.getObj(LAST_LOGIN_USER); if (lastLogin != null) { user = GetIMEIDetailsModel.fromJson(lastLogin); diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 0048b10c..a6eab35b 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -10,10 +10,10 @@ 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/models/doctor/user_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/screens/auth/verification_methods_screen.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'; @@ -463,25 +463,24 @@ class _LoginsreenState extends State { Helpers.showErrorToast(model.error); } else { - if (model.loginInfo['MessageStatus'] == 1) { - saveObjToString(LOGGED_IN_USER, model.loginInfo); - sharedPref.remove(LAST_LOGIN_USER); - sharedPref.setString(TOKEN, model.loginInfo['LogInTokenID']); - GifLoaderDialogUtils.hideDialog(context); + saveObjToString(LOGGED_IN_USER, model.loginInfo); + sharedPref.remove(LAST_LOGIN_USER); + sharedPref.setString(TOKEN, model.loginInfo.logInTokenID); + GifLoaderDialogUtils.hideDialog(context); - Navigator.of(context).pushReplacement(MaterialPageRoute( - builder: (BuildContext context) => - VerificationMethodsScreen( - password: userInfo.password, - ))); - } + Navigator.of(context).pushReplacement( + MaterialPageRoute( + builder: (BuildContext context) => VerificationMethodsScreen( + password: userInfo.password, + ), + ), + ); } } } Future setSharedPref(key, value) async { sharedPref.setString(key, value).then((success) { - print("sharedPref.setString" + success.toString()); }); } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 2b906588..ce783901 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -3,12 +3,11 @@ import 'dart:io' show Platform; 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/model/imei_details.dart'; +import 'package:doctor_app_flutter/core/model/auth/imei_details.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/models/auth/activation_Code_req_model.dart'; -import 'package:doctor_app_flutter/models/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/models/auth/check_activation_code_request_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; 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'; @@ -384,13 +383,13 @@ class _VerificationMethodsScreenState extends State { } else { // TODO move it model print("VerificationCode : " + - model.activationCodeForDoctorAppRes["VerificationCode"]); + model.activationCodeForDoctorAppRes.verificationCode); sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeForDoctorAppRes["VidaAuthTokenID"]); + model.activationCodeForDoctorAppRes.vidaAuthTokenID); sharedPref.setString(VIDA_REFRESH_TOKEN_ID, - model.activationCodeForDoctorAppRes["VidaRefreshTokenID"]); + model.activationCodeForDoctorAppRes.vidaRefreshTokenID); sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeForDoctorAppRes["LogInTokenID"]); + model.activationCodeForDoctorAppRes.logInTokenID); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); @@ -475,7 +474,7 @@ class _VerificationMethodsScreenState extends State { new SMSOTP( context, type, - model.loggedUser != null ? model.loggedUser['MobileNumber'] : model.user.mobile, + model.loggedUser != null ? model.loggedUser.mobileNumber : model.user.mobile, (value) { showDialog( context: context, @@ -581,7 +580,6 @@ class _VerificationMethodsScreenState extends State { if (res['MessageStatus'] == 1) { loginProcessCompleted(res['DoctorProfileList'][0]); } else { - // changeLoadingState(false); Helpers.showErrorToast(res['ErrorEndUserMessage']); } }).catchError((err) { From 745545ffc3afb722c0d4ffc1da4e04d094569704 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Thu, 6 May 2021 14:57:11 +0300 Subject: [PATCH 12/28] add models --- ...on_code_for_doctor_app_response_model.dart | 181 ++++++++++++++++++ lib/core/service/authentication_service.dart | 19 +- .../viewModel/authentication_view_model.dart | 16 +- .../auth/verification_methods_screen.dart | 38 +--- 4 files changed, 213 insertions(+), 41 deletions(-) create mode 100644 lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart diff --git a/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart b/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart new file mode 100644 index 00000000..283e617f --- /dev/null +++ b/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart @@ -0,0 +1,181 @@ +class CheckActivationCodeForDoctorAppResponseModel { + String authenticationTokenID; + List listDoctorsClinic; + List list_DoctorProfile; + MemberInformation memberInformation; + + CheckActivationCodeForDoctorAppResponseModel( + {this.authenticationTokenID, + this.listDoctorsClinic, + this.memberInformation}); + + CheckActivationCodeForDoctorAppResponseModel.fromJson( + Map json) { + authenticationTokenID = json['AuthenticationTokenID']; + list_DoctorProfile = json['List_DoctorProfile']; + if (json['List_DoctorsClinic'] != null) { + listDoctorsClinic = new List(); + json['List_DoctorsClinic'].forEach((v) { + listDoctorsClinic.add(new ListDoctorsClinic.fromJson(v)); + }); + } + memberInformation = json['memberInformation'] != null + ? new MemberInformation.fromJson(json['memberInformation']) + : null; + } + + Map toJson() { + final Map data = new Map(); + data['AuthenticationTokenID'] = this.authenticationTokenID; + data['List_DoctorProfile'] = this.list_DoctorProfile; + if (this.listDoctorsClinic != null) { + data['List_DoctorsClinic'] = + this.listDoctorsClinic.map((v) => v.toJson()).toList(); + } + if (this.memberInformation != null) { + data['memberInformation'] = this.memberInformation.toJson(); + } + return data; + } +} + +class ListDoctorsClinic { + Null setupID; + int projectID; + int doctorID; + int clinicID; + bool isActive; + String clinicName; + + ListDoctorsClinic( + {this.setupID, + this.projectID, + this.doctorID, + this.clinicID, + this.isActive, + this.clinicName}); + + ListDoctorsClinic.fromJson(Map json) { + setupID = json['SetupID']; + projectID = json['ProjectID']; + doctorID = json['DoctorID']; + clinicID = json['ClinicID']; + isActive = json['IsActive']; + clinicName = json['ClinicName']; + } + + Map toJson() { + final Map data = new Map(); + data['SetupID'] = this.setupID; + data['ProjectID'] = this.projectID; + data['DoctorID'] = this.doctorID; + data['ClinicID'] = this.clinicID; + data['IsActive'] = this.isActive; + data['ClinicName'] = this.clinicName; + return data; + } +} + +class MemberInformation { + List clinics; + int doctorId; + String email; + int employeeId; + int memberId; + Null memberName; + Null memberNameArabic; + String preferredLanguage; + List roles; + + MemberInformation( + {this.clinics, + this.doctorId, + this.email, + this.employeeId, + this.memberId, + this.memberName, + this.memberNameArabic, + this.preferredLanguage, + this.roles}); + + MemberInformation.fromJson(Map json) { + if (json['clinics'] != null) { + clinics = new List(); + json['clinics'].forEach((v) { + clinics.add(new Clinics.fromJson(v)); + }); + } + doctorId = json['doctorId']; + email = json['email']; + employeeId = json['employeeId']; + memberId = json['memberId']; + memberName = json['memberName']; + memberNameArabic = json['memberNameArabic']; + preferredLanguage = json['preferredLanguage']; + if (json['roles'] != null) { + roles = new List(); + json['roles'].forEach((v) { + roles.add(new Roles.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + if (this.clinics != null) { + data['clinics'] = this.clinics.map((v) => v.toJson()).toList(); + } + data['doctorId'] = this.doctorId; + data['email'] = this.email; + data['employeeId'] = this.employeeId; + data['memberId'] = this.memberId; + data['memberName'] = this.memberName; + data['memberNameArabic'] = this.memberNameArabic; + data['preferredLanguage'] = this.preferredLanguage; + if (this.roles != null) { + data['roles'] = this.roles.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class Clinics { + bool defaultClinic; + int id; + String name; + + Clinics({this.defaultClinic, this.id, this.name}); + + Clinics.fromJson(Map json) { + defaultClinic = json['defaultClinic']; + id = json['id']; + name = json['name']; + } + + Map toJson() { + final Map data = new Map(); + data['defaultClinic'] = this.defaultClinic; + data['id'] = this.id; + data['name'] = this.name; + return data; + } +} + +class Roles { + String name; + int roleId; + + Roles({this.name, this.roleId}); + + Roles.fromJson(Map json) { + name = json['name']; + roleId = json['roleId']; + } + + Map toJson() { + final Map data = new Map(); + data['name'] = this.name; + data['roleId'] = this.roleId; + return data; + } +} diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index 18624d58..9f67a3b8 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -1,5 +1,6 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; @@ -15,22 +16,20 @@ import 'package:provider/provider.dart'; class AuthenticationService extends BaseService { List _imeiDetails = []; List get dashboardItemsList => _imeiDetails; - //TODO Change this to models NewLoginInformationModel _loginInfo = NewLoginInformationModel(); NewLoginInformationModel get loginInfo => _loginInfo; - Map _activationCodeVerificationScreenRes = {}; + SendActivationCodeForDoctorAppResponseModel _activationCodeVerificationScreenRes = SendActivationCodeForDoctorAppResponseModel(); - Map get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes; + SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes => _activationCodeVerificationScreenRes; SendActivationCodeForDoctorAppResponseModel _activationCodeForDoctorAppRes = SendActivationCodeForDoctorAppResponseModel(); SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _activationCodeForDoctorAppRes; - Map _checkActivationCodeForDoctorAppRes = {}; + CheckActivationCodeForDoctorAppResponseModel _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel(); - Map get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; + CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; Map _insertDeviceImeiRes = {}; - Map get insertDeviceImeiRes => _insertDeviceImeiRes; Future selectDeviceImei(imei) async { try { await baseAppClient.post(SELECT_DEVICE_IMEI, @@ -69,11 +68,11 @@ class AuthenticationService extends BaseService { Future sendActivationCodeVerificationScreen(ActivationCodeForVerificationScreenModel activationCodeModel) async { hasError = false; - _activationCodeVerificationScreenRes = {}; + _activationCodeVerificationScreenRes = SendActivationCodeForDoctorAppResponseModel(); try { await baseAppClient.post(SEND_ACTIVATION_CODE_FOR_VERIFICATION_SCREEN, onSuccess: (dynamic response, int statusCode) { - _activationCodeVerificationScreenRes = response; + _activationCodeVerificationScreenRes = SendActivationCodeForDoctorAppResponseModel.fromJson(response); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; @@ -104,13 +103,13 @@ class AuthenticationService extends BaseService { Future checkActivationCodeForDoctorApp(CheckActivationCodeRequestModel checkActivationCodeRequestModel)async { hasError = false; - _checkActivationCodeForDoctorAppRes = {}; + _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel(); try { await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP, onSuccess: (dynamic response, int statusCode) { // TODO improve the logic here Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear(); - _checkActivationCodeForDoctorAppRes = response; + _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel.fromJson(response); Provider.of(AppGlobal.CONTEX, listen: false).selectedClinicName = ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index a9986cec..f33ec782 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -3,6 +3,7 @@ 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/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; @@ -26,9 +27,9 @@ class AuthenticationViewModel extends BaseViewModel { List get imeiDetails => _authService.dashboardItemsList; List get hospitals => _hospitalsService.hospitals; NewLoginInformationModel get loginInfo => _authService.loginInfo; - get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; + SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; - get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; + CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; NewLoginInformationModel loggedUser; GetIMEIDetailsModel user; @@ -222,4 +223,15 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + + setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel){ + print("VerificationCode : " + + sendActivationCodeForDoctorAppResponseModel.verificationCode); + sharedPref.setString(VIDA_AUTH_TOKEN_ID, + sendActivationCodeForDoctorAppResponseModel.vidaAuthTokenID); + sharedPref.setString(VIDA_REFRESH_TOKEN_ID, + sendActivationCodeForDoctorAppResponseModel.vidaRefreshTokenID); + sharedPref.setString(LOGIN_TOKEN_ID, + sendActivationCodeForDoctorAppResponseModel.logInTokenID); + } } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index ce783901..29188194 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -3,11 +3,8 @@ import 'dart:io' show Platform; 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/model/auth/imei_details.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/core/model/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; 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'; @@ -381,15 +378,7 @@ class _VerificationMethodsScreenState extends State { Helpers.showErrorToast(model.error); GifLoaderDialogUtils.hideDialog(context); } else { - // TODO move it model - print("VerificationCode : " + - model.activationCodeForDoctorAppRes.verificationCode); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeForDoctorAppRes.vidaAuthTokenID); - sharedPref.setString(VIDA_REFRESH_TOKEN_ID, - model.activationCodeForDoctorAppRes.vidaRefreshTokenID); - sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeForDoctorAppRes.logInTokenID); + model.setDataAfterSendActivationSuccsess(model.activationCodeForDoctorAppRes); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); @@ -413,16 +402,7 @@ class _VerificationMethodsScreenState extends State { GifLoaderDialogUtils.hideDialog(context); Helpers.showErrorToast(model.error); } else { - //TODO Move it to view model - print("VerificationCode : " + - model.activationCodeVerificationScreenRes["VerificationCode"]); - sharedPref.setString(VIDA_AUTH_TOKEN_ID, - model.activationCodeVerificationScreenRes["VidaAuthTokenID"]); - sharedPref.setString( - VIDA_REFRESH_TOKEN_ID, - model.activationCodeVerificationScreenRes["VidaRefreshTokenID"]); - sharedPref.setString(LOGIN_TOKEN_ID, - model.activationCodeVerificationScreenRes["LogInTokenID"]); + model.setDataAfterSendActivationSuccsess(model.activationCodeVerificationScreenRes); if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.hideDialog(context); @@ -535,20 +515,19 @@ class _VerificationMethodsScreenState extends State { sharedPref.setString( TOKEN, model - .checkActivationCodeForDoctorAppRes['AuthenticationTokenID']); - if (model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'] != - null) { - loginProcessCompleted(model.checkActivationCodeForDoctorAppRes['List_DoctorProfile'][0]); + .checkActivationCodeForDoctorAppRes.authenticationTokenID); + if (model.checkActivationCodeForDoctorAppRes.listDoctorsClinic.isNotEmpty) { + loginProcessCompleted(model.checkActivationCodeForDoctorAppRes.list_DoctorProfile[0]); sharedPref.setObj( CLINIC_NAME, model - .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); + .checkActivationCodeForDoctorAppRes.listDoctorsClinic); } else { sharedPref.setObj( CLINIC_NAME, model - .checkActivationCodeForDoctorAppRes['List_DoctorsClinic']); - ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes['List_DoctorsClinic'][0]); + .checkActivationCodeForDoctorAppRes.listDoctorsClinic); + ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes.listDoctorsClinic[0].toJson()); getDocProfiles(clinic); } } @@ -586,4 +565,5 @@ class _VerificationMethodsScreenState extends State { Helpers.showErrorToast(err); }); } + } From 081bfe3f61b0f17b0b38f70a1a2b631187109ab2 Mon Sep 17 00:00:00 2001 From: Mohammad Aljammal Date: Thu, 6 May 2021 15:51:58 +0300 Subject: [PATCH 13/28] add TODO to Elham --- ios/Podfile.lock | 2 +- .../viewModel/authentication_view_model.dart | 4 +-- .../viewModel/doctor_profile_view_model.dart | 2 +- lib/screens/auth/login_screen.dart | 15 +++++++---- .../auth/verification_methods_screen.dart | 25 ++++++++----------- lib/widgets/auth/auth_header.dart | 2 +- lib/widgets/auth/method_card.dart | 2 ++ lib/widgets/auth/sms-popup.dart | 2 +- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2f4607e0..878a1850 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -322,4 +322,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 -COCOAPODS: 1.10.0.rc.1 +COCOAPODS: 1.10.1 diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index f33ec782..228a63e7 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -169,13 +169,13 @@ class AuthenticationViewModel extends BaseViewModel { } - + //TODO Elham remove it getDate(DateTime date) { final DateFormat formatter = DateFormat('dd MMM yyyy'); return formatter.format(date); } - + //TODO Elham remove it getTime(DateTime date) { final DateFormat formatter = DateFormat('HH:mm a'); diff --git a/lib/core/viewModel/doctor_profile_view_model.dart b/lib/core/viewModel/doctor_profile_view_model.dart index 24f53e5b..d336dd8d 100644 --- a/lib/core/viewModel/doctor_profile_view_model.dart +++ b/lib/core/viewModel/doctor_profile_view_model.dart @@ -36,7 +36,7 @@ class DoctorProfileViewModel extends BaseViewModel { } notifyListeners(); } - +//TODO Elham move it auth view model APP_STATUS get stutas { if (isLoading) { return APP_STATUS.LOADING; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index a6eab35b..91af7a2f 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -28,9 +28,9 @@ import '../../lookups/auth_lookup.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../widgets/auth/auth_header.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; - +//TODO Elham remove it DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); - +//TODO Elham change the name class Loginsreen extends StatefulWidget { @override _LoginsreenState createState() => _LoginsreenState(); @@ -51,12 +51,13 @@ class _LoginsreenState extends State { FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); // HospitalViewModel hospitalViewModel; + //TODO Elham to change it ti UserModel var userInfo = UserModel(); @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(); @@ -88,6 +89,7 @@ class _LoginsreenState extends State { }); } + //TODO Elham change it to GIF void changeLoadingState(isLoading) { setState(() { _isLoading = isLoading; @@ -100,6 +102,7 @@ class _LoginsreenState extends State { return BaseView( + //TODO Elham remove it onModelReady: (model) => {}, builder: (_, model, w) => AppScaffold( @@ -457,6 +460,7 @@ class _LoginsreenState extends State { loginFormKey.currentState.save(); GifLoaderDialogUtils.showMyDialog(context); sharedPref.setInt(PROJECT_ID, userInfo.projectID); + //TODO Elham move the sharedPref to view model await model.login(userInfo); if (model.state == ViewState.ErrorLocal) { GifLoaderDialogUtils.hideDialog(context); @@ -466,6 +470,7 @@ class _LoginsreenState extends State { saveObjToString(LOGGED_IN_USER, model.loginInfo); sharedPref.remove(LAST_LOGIN_USER); sharedPref.setString(TOKEN, model.loginInfo.logInTokenID); + //TODO Elham move the sharedPref to view model GifLoaderDialogUtils.hideDialog(context); Navigator.of(context).pushReplacement( @@ -478,13 +483,13 @@ class _LoginsreenState extends State { } } } - + //TODO Elham to it view model Future setSharedPref(key, value) async { sharedPref.setString(key, value).then((success) { }); } - +//TODO Elham to it view model saveObjToString(String key, value) async { sharedPref.setObj(key, value); } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 29188194..521dd5f6 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -39,6 +39,7 @@ class VerificationMethodsScreen extends StatefulWidget { VerificationMethodsScreen({this.changeLoadingState, this.password}); final password; + //TODO Elham remove this fun final Function changeLoadingState; @override @@ -62,12 +63,13 @@ class _VerificationMethodsScreenState extends State { final LocalAuthentication auth = LocalAuthentication(); + //TODO Elham remove this fun @override void initState() { super.initState(); } - +//TODO Elham remove this fun @override void didChangeDependencies() async{ super.didChangeDependencies(); @@ -229,11 +231,7 @@ class _VerificationMethodsScreenState extends State { child: InkWell( onTap: () => { // TODO check this logic it seem it will create bug to us - - authenticateUser( - AuthMethodTypes - .Fingerprint, - true) + authenticateUser(AuthMethodTypes.Fingerprint, true) }, child: MethodCard( authMethodType: model.user @@ -337,6 +335,7 @@ class _VerificationMethodsScreenState extends State { ], ), ), + //TODO Elham move it to bottom sheet Column( mainAxisAlignment: MainAxisAlignment.end, children: [ @@ -473,7 +472,7 @@ class _VerificationMethodsScreenState extends State { }, ).displayDialog(context); } - +//TODO Elham move it to view model loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async { if (isActive) { @@ -505,17 +504,15 @@ class _VerificationMethodsScreenState extends State { checkActivationCode({value}) async { - await model - .checkActivationCodeForDoctorApp(activationCode:value ); + await model.checkActivationCodeForDoctorApp(activationCode:value ); if (model.state == ViewState.ErrorLocal) { Navigator.pop(context); Helpers.showErrorToast(model.error); } else { sharedPref.setString( - TOKEN, - model - .checkActivationCodeForDoctorAppRes.authenticationTokenID); + TOKEN, model.checkActivationCodeForDoctorAppRes.authenticationTokenID); + //TODO Elham check the logic if (model.checkActivationCodeForDoctorAppRes.listDoctorsClinic.isNotEmpty) { loginProcessCompleted(model.checkActivationCodeForDoctorAppRes.list_DoctorProfile[0]); sharedPref.setObj( @@ -532,7 +529,7 @@ class _VerificationMethodsScreenState extends State { } } } - + //TODO Elham move it to view model loginProcessCompleted(Map profile) { var doctor = DoctorProfileModel.fromJson(profile); doctorProfileViewModel.setDoctorProfile(doctor); @@ -546,7 +543,7 @@ class _VerificationMethodsScreenState extends State { ), (r) => false); } - +//TODO Elham move it to view model getDocProfiles(ClinicModel clinicInfo) { ProfileReqModel docInfo = new ProfileReqModel( doctorID: clinicInfo.doctorID, diff --git a/lib/widgets/auth/auth_header.dart b/lib/widgets/auth/auth_header.dart index 47e128be..27396980 100644 --- a/lib/widgets/auth/auth_header.dart +++ b/lib/widgets/auth/auth_header.dart @@ -6,7 +6,7 @@ import 'package:hexcolor/hexcolor.dart'; import '../../config/size_config.dart'; import '../../lookups/auth_lookup.dart'; - +//TODO Elham delete this widget class AuthHeader extends StatelessWidget { var userType; AuthHeader(this.userType); diff --git a/lib/widgets/auth/method_card.dart b/lib/widgets/auth/method_card.dart index 94bd261b..79721381 100644 --- a/lib/widgets/auth/method_card.dart +++ b/lib/widgets/auth/method_card.dart @@ -20,6 +20,7 @@ class MethodCard extends StatefulWidget { class _MethodCardState extends State { + //TODO Elham change it to list Enum var _availableBiometrics; final LocalAuthentication auth = LocalAuthentication(); @@ -65,6 +66,7 @@ class _MethodCardState extends State { case AuthMethodTypes.WhatsApp: return InkWell( onTap: () => {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)}, + //TODO Elham change it to widget child: Container( margin: EdgeInsets.all(10), decoration: BoxDecoration( diff --git a/lib/widgets/auth/sms-popup.dart b/lib/widgets/auth/sms-popup.dart index 61329758..6cbeab49 100644 --- a/lib/widgets/auth/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -8,7 +8,7 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; - +//TODO Elham check it class SMSOTP { final AuthMethodTypes type; final mobileNo; From 301972f9b74567c9d16d2b794bbd0210035a0ef7 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 9 May 2021 12:15:32 +0300 Subject: [PATCH 14/28] small fixes --- lib/screens/auth/login_screen.dart | 7 ------- lib/screens/auth/verification_methods_screen.dart | 1 - 2 files changed, 8 deletions(-) diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index a6eab35b..c7e15b9c 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -50,7 +50,6 @@ class _LoginsreenState extends State { List projectsList = []; FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); - // HospitalViewModel hospitalViewModel; var userInfo = UserModel(); @override @@ -479,12 +478,6 @@ class _LoginsreenState extends State { } } - Future setSharedPref(key, value) async { - sharedPref.setString(key, value).then((success) { - }); - } - - saveObjToString(String key, value) async { sharedPref.setObj(key, value); } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 29188194..dabe184e 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -89,7 +89,6 @@ class _VerificationMethodsScreenState extends State { body: SingleChildScrollView( child: Center( child: FractionallySizedBox( - // widthFactor: 0.9, child: Container( margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), From fd9f93a9365bdfe385617c3bb709c1bbee80b060 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 9 May 2021 17:33:33 +0300 Subject: [PATCH 15/28] do some refactor and change the code to view model --- ios/Podfile.lock | 2 +- lib/core/enum/auth_method_types.dart | 22 + ...on_code_for_doctor_app_response_model.dart | 55 ++- lib/core/service/authentication_service.dart | 24 + .../viewModel/authentication_view_model.dart | 156 +++++-- lib/core/viewModel/base_view_model.dart | 7 +- .../viewModel/doctor_profile_view_model.dart | 5 + lib/root_page.dart | 2 +- lib/routes.dart | 2 +- lib/screens/auth/login_screen.dart | 141 +++--- .../auth/verification_methods_screen.dart | 413 ++++++++---------- lib/util/helpers.dart | 14 +- lib/widgets/auth/auth_header.dart | 113 ----- lib/widgets/auth/method_card.dart | 244 ----------- lib/widgets/auth/method_type_card.dart | 53 +++ .../auth/verification_methods_list.dart | 87 ++++ 16 files changed, 642 insertions(+), 698 deletions(-) delete mode 100644 lib/widgets/auth/auth_header.dart delete mode 100644 lib/widgets/auth/method_card.dart create mode 100644 lib/widgets/auth/method_type_card.dart create mode 100644 lib/widgets/auth/verification_methods_list.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 878a1850..2f4607e0 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -322,4 +322,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 -COCOAPODS: 1.10.1 +COCOAPODS: 1.10.0.rc.1 diff --git a/lib/core/enum/auth_method_types.dart b/lib/core/enum/auth_method_types.dart index 3faff89c..82577eeb 100644 --- a/lib/core/enum/auth_method_types.dart +++ b/lib/core/enum/auth_method_types.dart @@ -21,4 +21,26 @@ extension SelectedAuthMethodTypesService on AuthMethodTypes { } } + + // ignore: missing_return + static getMethodsTypeService( int typeId) { + switch (typeId) { + case 1: + return AuthMethodTypes.SMS; + break; + case 2: + return AuthMethodTypes.WhatsApp; + break; + case 3: + return AuthMethodTypes.Fingerprint; + break; + case 4: + return AuthMethodTypes.FaceID; + break; + case 5: + return AuthMethodTypes.MoreOptions; + break; + + } + } } \ No newline at end of file diff --git a/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart b/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart index 283e617f..c5ff29e6 100644 --- a/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart +++ b/lib/core/model/auth/check_activation_code_for_doctor_app_response_model.dart @@ -1,24 +1,33 @@ +import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; + class CheckActivationCodeForDoctorAppResponseModel { String authenticationTokenID; List listDoctorsClinic; - List list_DoctorProfile; + List listDoctorProfile; MemberInformation memberInformation; CheckActivationCodeForDoctorAppResponseModel( {this.authenticationTokenID, - this.listDoctorsClinic, - this.memberInformation}); + this.listDoctorsClinic, + this.memberInformation}); CheckActivationCodeForDoctorAppResponseModel.fromJson( Map json) { authenticationTokenID = json['AuthenticationTokenID']; - list_DoctorProfile = json['List_DoctorProfile']; if (json['List_DoctorsClinic'] != null) { listDoctorsClinic = new List(); json['List_DoctorsClinic'].forEach((v) { listDoctorsClinic.add(new ListDoctorsClinic.fromJson(v)); }); } + + if (json['List_DoctorProfile'] != null) { + listDoctorProfile = new List(); + json['List_DoctorProfile'].forEach((v) { + listDoctorProfile.add(new DoctorProfileModel.fromJson(v)); + }); + } + memberInformation = json['memberInformation'] != null ? new MemberInformation.fromJson(json['memberInformation']) : null; @@ -27,11 +36,15 @@ class CheckActivationCodeForDoctorAppResponseModel { Map toJson() { final Map data = new Map(); data['AuthenticationTokenID'] = this.authenticationTokenID; - data['List_DoctorProfile'] = this.list_DoctorProfile; if (this.listDoctorsClinic != null) { data['List_DoctorsClinic'] = this.listDoctorsClinic.map((v) => v.toJson()).toList(); } + + if (this.listDoctorProfile != null) { + data['List_DoctorProfile'] = + this.listDoctorProfile.map((v) => v.toJson()).toList(); + } if (this.memberInformation != null) { data['memberInformation'] = this.memberInformation.toJson(); } @@ -47,13 +60,12 @@ class ListDoctorsClinic { bool isActive; String clinicName; - ListDoctorsClinic( - {this.setupID, - this.projectID, - this.doctorID, - this.clinicID, - this.isActive, - this.clinicName}); + ListDoctorsClinic({this.setupID, + this.projectID, + this.doctorID, + this.clinicID, + this.isActive, + this.clinicName}); ListDoctorsClinic.fromJson(Map json) { setupID = json['SetupID']; @@ -87,16 +99,15 @@ class MemberInformation { String preferredLanguage; List roles; - MemberInformation( - {this.clinics, - this.doctorId, - this.email, - this.employeeId, - this.memberId, - this.memberName, - this.memberNameArabic, - this.preferredLanguage, - this.roles}); + MemberInformation({this.clinics, + this.doctorId, + this.email, + this.employeeId, + this.memberId, + this.memberName, + this.memberNameArabic, + this.preferredLanguage, + this.roles}); MemberInformation.fromJson(Map json) { if (json['clinics'] != null) { diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index 9f67a3b8..d20f5dbf 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -10,6 +10,8 @@ import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; 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:provider/provider.dart'; @@ -30,6 +32,9 @@ class AuthenticationService extends BaseService { CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _checkActivationCodeForDoctorAppRes; Map _insertDeviceImeiRes = {}; + List _doctorProfilesList = []; + List get doctorProfilesList => _doctorProfilesList; + Future selectDeviceImei(imei) async { try { await baseAppClient.post(SELECT_DEVICE_IMEI, @@ -144,4 +149,23 @@ class AuthenticationService extends BaseService { super.error = error; } } + + Future getDoctorProfileBasedOnClinic(ProfileReqModel profileReqModel)async { + hasError = false; + try { + await baseAppClient.post(GET_DOC_PROFILES, + onSuccess: (dynamic response, int statusCode) { + _doctorProfilesList.clear(); + response['DoctorProfileList'].forEach((v) { + _doctorProfilesList.add(DoctorProfileModel.fromJson(v)); + }); + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: profileReqModel.toJson()); + } catch (error) { + hasError = true; + super.error = error; + } + } } diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 228a63e7..b5f61b05 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -3,36 +3,62 @@ 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/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_request_model.dart'; import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; -import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; +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/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; -import 'package:intl/intl.dart'; +import 'package:flutter/services.dart'; +import 'package:local_auth/auth_strings.dart'; +import 'package:local_auth/local_auth.dart'; +import 'package:provider/provider.dart'; + +import 'doctor_profile_view_model.dart'; class AuthenticationViewModel extends BaseViewModel { AuthenticationService _authService = locator(); HospitalsService _hospitalsService = locator(); List get imeiDetails => _authService.dashboardItemsList; + List get hospitals => _hospitalsService.hospitals; + NewLoginInformationModel get loginInfo => _authService.loginInfo; - SendActivationCodeForDoctorAppResponseModel get activationCodeVerificationScreenRes => _authService.activationCodeVerificationScreenRes; - SendActivationCodeForDoctorAppResponseModel get activationCodeForDoctorAppRes => _authService.activationCodeForDoctorAppRes; - CheckActivationCodeForDoctorAppResponseModel get checkActivationCodeForDoctorAppRes => _authService.checkActivationCodeForDoctorAppRes; + List get doctorProfilesList => _authService.doctorProfilesList; + SendActivationCodeForDoctorAppResponseModel + get activationCodeVerificationScreenRes => + _authService.activationCodeVerificationScreenRes; + + SendActivationCodeForDoctorAppResponseModel + get activationCodeForDoctorAppRes => + _authService.activationCodeForDoctorAppRes; + + CheckActivationCodeForDoctorAppResponseModel + get checkActivationCodeForDoctorAppRes => + _authService.checkActivationCodeForDoctorAppRes; NewLoginInformationModel loggedUser; GetIMEIDetailsModel user; + + UserModel userInfo = UserModel(); + final LocalAuthentication auth = LocalAuthentication(); + List _availableBiometrics; + + Future selectDeviceImei(imei) async { setState(ViewState.Busy); await _authService.selectDeviceImei(imei); @@ -88,8 +114,13 @@ class AuthenticationViewModel extends BaseViewModel { if (_authService.hasError) { error = _authService.error; setState(ViewState.ErrorLocal); - } else + } else { + sharedPref.setInt(PROJECT_ID, userInfo.projectID); + saveObjToString(LOGGED_IN_USER, loginInfo); + sharedPref.remove(LAST_LOGIN_USER); + sharedPref.setString(TOKEN, loginInfo.logInTokenID); setState(ViewState.Idle); + } } Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async { @@ -168,21 +199,6 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } - - //TODO Elham remove it - getDate(DateTime date) { - final DateFormat formatter = DateFormat('dd MMM yyyy'); - - return formatter.format(date); - } - //TODO Elham remove it - getTime(DateTime date) { - final DateFormat formatter = DateFormat('HH:mm a'); - - return formatter.format(date); - } - - getType(type, context) { switch (type) { case 1: @@ -214,17 +230,16 @@ class AuthenticationViewModel extends BaseViewModel { var localLoggedUser = await sharedPref.getObj(LOGGED_IN_USER); if(localLoggedUser!= null) { loggedUser = NewLoginInformationModel.fromJson(localLoggedUser); - } var lastLogin = await sharedPref.getObj(LAST_LOGIN_USER); if (lastLogin != null) { user = GetIMEIDetailsModel.fromJson(lastLogin); } setState(ViewState.Idle); - } - setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel){ + setDataAfterSendActivationSuccsess( + SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); sharedPref.setString(VIDA_AUTH_TOKEN_ID, @@ -234,4 +249,93 @@ class AuthenticationViewModel extends BaseViewModel { sharedPref.setString(LOGIN_TOKEN_ID, sendActivationCodeForDoctorAppResponseModel.logInTokenID); } + + saveObjToString(String key, value) async { + sharedPref.setObj(key, value); + } + + showIOSAuthMessages() async { + const iosStrings = const IOSAuthMessages( + cancelButton: 'cancel', + goToSettingsButton: 'settings', + goToSettingsDescription: 'Please set up your Touch ID.', + lockOut: 'Please Enable Your Touch ID'); + + try { + await auth.authenticateWithBiometrics( + localizedReason: 'Scan your fingerprint to authenticate', + useErrorDialogs: true, + stickyAuth: true, + iOSAuthStrings: iosStrings); + } on PlatformException catch (e) { + DrAppToastMsg.showErrorToast(e.toString()); + } + } + + localSetDoctorProfile(DoctorProfileModel profile) { + super.setDoctorProfile(profile); + //TODO: Remove it when we remove Doctor Profile View Model and start to use profile form base view model + Provider.of(AppGlobal.CONTEX, listen: false) + .setDoctorProfile(profile); + } + + Future getDoctorProfileBasedOnClinic(ClinicModel clinicInfo) async { + ProfileReqModel docInfo = new ProfileReqModel( + doctorID: clinicInfo.doctorID, + clinicID: clinicInfo.clinicID, + license: true, + projectID: clinicInfo.projectID, + tokenID: '', + languageID: 2); + await _authService.getDoctorProfileBasedOnClinic(docInfo); + if (_authService.hasError) { + error = _authService.error; + setState(ViewState.ErrorLocal); + } else { + localSetDoctorProfile(doctorProfilesList.first); + setState(ViewState.Idle); + } + } + + onCheckActivationCodeSuccess() async { + sharedPref.setString( + TOKEN, + checkActivationCodeForDoctorAppRes.authenticationTokenID); + if (checkActivationCodeForDoctorAppRes.listDoctorProfile != null && + checkActivationCodeForDoctorAppRes.listDoctorProfile + .isNotEmpty) { + localSetDoctorProfile( + checkActivationCodeForDoctorAppRes.listDoctorProfile[0]); + + + } else { + sharedPref.setObj( + CLINIC_NAME, + checkActivationCodeForDoctorAppRes.listDoctorsClinic); + ClinicModel clinic = ClinicModel.fromJson( + checkActivationCodeForDoctorAppRes.listDoctorsClinic[0] + .toJson()); + await getDoctorProfileBasedOnClinic(clinic); + } + } + + Future checkIfBiometricAvailable(BiometricType biometricType) async { + bool isAvailable = false; + await _getAvailableBiometrics(); + if (_availableBiometrics != null) { + for (var i = 0; i < _availableBiometrics.length; i++) { + if (biometricType == _availableBiometrics[i]) isAvailable = true; + } + } + return isAvailable; + } + + Future _getAvailableBiometrics() async { + try { + _availableBiometrics = await auth.getAvailableBiometrics(); + } on PlatformException catch (e) { + print(e); + } + } + } diff --git a/lib/core/viewModel/base_view_model.dart b/lib/core/viewModel/base_view_model.dart index 43e83c9b..fe4dbd22 100644 --- a/lib/core/viewModel/base_view_model.dart +++ b/lib/core/viewModel/base_view_model.dart @@ -45,5 +45,10 @@ class BaseViewModel extends ChangeNotifier { } else { return doctorProfile; } -} + } + + setDoctorProfile(DoctorProfileModel doctorProfile){ + sharedPref.setObj(DOCTOR_PROFILE, doctorProfile); + doctorProfile = doctorProfile; + } } diff --git a/lib/core/viewModel/doctor_profile_view_model.dart b/lib/core/viewModel/doctor_profile_view_model.dart index d336dd8d..4dcaf050 100644 --- a/lib/core/viewModel/doctor_profile_view_model.dart +++ b/lib/core/viewModel/doctor_profile_view_model.dart @@ -1,14 +1,19 @@ import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; 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 = []; + AuthenticationService _authService = locator(); + String selectedClinicName; bool isLogin = false; diff --git a/lib/root_page.dart b/lib/root_page.dart index 7df1b7cb..3b47290b 100644 --- a/lib/root_page.dart +++ b/lib/root_page.dart @@ -21,7 +21,7 @@ class RootPage extends StatelessWidget { ); break; case APP_STATUS.UNAUTHENTICATED: - return Loginsreen(); + return LoginScreen(); break; case APP_STATUS.AUTHENTICATED: return LandingPage(); diff --git a/lib/routes.dart b/lib/routes.dart index 90e061b8..5ec36ae3 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -64,7 +64,7 @@ const String RADIOLOGY_PATIENT = 'radiology-patient'; var routes = { ROOT: (_) => RootPage(), HOME: (_) => LandingPage(), - LOGIN: (_) => Loginsreen(), + LOGIN: (_) => LoginScreen(), VERIFICATION_METHODS: (_) => VerificationMethodsScreen(), PATIENTS_PROFILE: (_) => PatientProfileScreen(), LAB_RESULT: (_) => LabsHomePage(), diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 91af7a2f..429aff5a 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -1,4 +1,3 @@ -import 'dart:async'; import 'dart:io'; import 'package:doctor_app_flutter/config/config.dart'; @@ -9,7 +8,6 @@ import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_m 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/models/doctor/user_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'; @@ -24,20 +22,18 @@ import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; -import '../../lookups/auth_lookup.dart'; import '../../util/dr_app_shared_pref.dart'; -import '../../widgets/auth/auth_header.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; + //TODO Elham remove it DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); -//TODO Elham change the name -class Loginsreen extends StatefulWidget { + +class LoginScreen extends StatefulWidget { @override - _LoginsreenState createState() => _LoginsreenState(); + _LoginScreenState createState() => _LoginScreenState(); } -class _LoginsreenState extends State { - +class _LoginScreenState extends State { String platformImei; final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); bool _isLoading = true; @@ -50,9 +46,7 @@ class _LoginsreenState extends State { List projectsList = []; FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); - // HospitalViewModel hospitalViewModel; - //TODO Elham to change it ti UserModel - var userInfo = UserModel(); + @override void initState() { @@ -99,11 +93,7 @@ class _LoginsreenState extends State { @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); - - return BaseView( - //TODO Elham remove it - onModelReady: (model) => {}, builder: (_, model, w) => AppScaffold( baseViewModel: model, @@ -123,7 +113,71 @@ class _LoginsreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ - AuthHeader(loginType.knownUser), + //TODO Use App Text rather than text + Container( + + child: Column( + 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'), + ), + + Text( + "Doctor App", + style: TextStyle( + fontSize: + SizeConfig.isMobile + ? 16 + : SizeConfig + .realScreenWidth * + 0.030, + fontWeight: FontWeight + .w800, + color: HexColor( + '#B8382C')), + ), + ]), + ], + )), SizedBox( height: 40, ), @@ -203,7 +257,7 @@ class _LoginsreenState extends State { onSaved: (value) { if (value != null) setState(() { - userInfo + model.userInfo .userID = value .trim(); @@ -212,7 +266,7 @@ class _LoginsreenState extends State { onChanged: (value) { if (value != null) setState(() { - userInfo + model.userInfo .userID = value .trim(); @@ -276,7 +330,7 @@ class _LoginsreenState extends State { if (value != null) setState(() { - userInfo + model.userInfo .password = value; }); @@ -286,7 +340,7 @@ class _LoginsreenState extends State { if (value != null) setState(() { - userInfo + model.userInfo .password = value; }); @@ -300,11 +354,12 @@ class _LoginsreenState extends State { context, projectsList, 'facilityName', - onSelectProject); + onSelectProject, + model); }, onTap: () { this.getProjects( - userInfo + model.userInfo .userID, model); }, ) @@ -352,7 +407,8 @@ class _LoginsreenState extends State { context, projectsList, 'facilityName', - onSelectProject); + onSelectProject, + model); }, validator: ( value) { @@ -424,9 +480,10 @@ class _LoginsreenState extends State { .login, color: HexColor( '#D02127'), - disabled: userInfo + disabled: model.userInfo .userID == null || - userInfo.password == + model.userInfo + .password == null, fontWeight: FontWeight .bold, @@ -445,7 +502,7 @@ class _LoginsreenState extends State { ]) : Center(child: AppLoaderWidget()), ), - )); + ), ); } SizedBox buildSizedBox() { @@ -459,44 +516,28 @@ class _LoginsreenState extends State { if (loginFormKey.currentState.validate()) { loginFormKey.currentState.save(); GifLoaderDialogUtils.showMyDialog(context); - sharedPref.setInt(PROJECT_ID, userInfo.projectID); - //TODO Elham move the sharedPref to view model - await model.login(userInfo); + await model.login(model.userInfo); if (model.state == ViewState.ErrorLocal) { GifLoaderDialogUtils.hideDialog(context); Helpers.showErrorToast(model.error); - } else { - saveObjToString(LOGGED_IN_USER, model.loginInfo); - sharedPref.remove(LAST_LOGIN_USER); - sharedPref.setString(TOKEN, model.loginInfo.logInTokenID); - //TODO Elham move the sharedPref to view model GifLoaderDialogUtils.hideDialog(context); Navigator.of(context).pushReplacement( MaterialPageRoute( - builder: (BuildContext context) => VerificationMethodsScreen( - password: userInfo.password, + builder: (BuildContext context) => + VerificationMethodsScreen( + password: model.userInfo.password, ), ), ); } } } - //TODO Elham to it view model - Future setSharedPref(key, value) async { - sharedPref.setString(key, value).then((success) { - }); - } - -//TODO Elham to it view model - saveObjToString(String key, value) async { - sharedPref.setObj(key, value); - } - onSelectProject(index) { + onSelectProject(index, AuthenticationViewModel model) { setState(() { - userInfo.projectID = projectsList[index].facilityId; + model.userInfo.projectID = projectsList[index].facilityId; projectIdController.text = projectsList[index].facilityName; }); @@ -510,7 +551,7 @@ class _LoginsreenState extends State { if(model.state == ViewState.Idle) { projectsList = model.hospitals; setState(() { - userInfo.projectID = projectsList[0].facilityId; + model.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 5105707a..1c16bda9 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -5,12 +5,8 @@ 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/project_view_model.dart'; -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/screens/base/base_view.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/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/auth/sms-popup.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; @@ -19,9 +15,7 @@ import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dar 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'; -import 'package:flutter/services.dart'; -import 'package:local_auth/auth_strings.dart'; -import 'package:local_auth/local_auth.dart'; +import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; import '../../config/size_config.dart'; @@ -30,17 +24,15 @@ import '../../landing_page.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../util/helpers.dart'; -import '../../widgets/auth/method_card.dart'; +import '../../widgets/auth/verification_methods_list.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); class VerificationMethodsScreen extends StatefulWidget { - VerificationMethodsScreen({this.changeLoadingState, this.password}); + VerificationMethodsScreen({this.password}); final password; - //TODO Elham remove this fun - final Function changeLoadingState; @override _VerificationMethodsScreenState createState() => _VerificationMethodsScreenState(); @@ -51,31 +43,11 @@ class _VerificationMethodsScreenState extends State { ProjectViewModel projectsProvider; bool isMoreOption = false; bool onlySMSBox = false; - var loginTokenID; DoctorProfileViewModel doctorProfileViewModel; - - bool authenticated; - AuthMethodTypes fingerPrintBefore; - AuthMethodTypes selectedOption; AuthenticationViewModel model; - final LocalAuthentication auth = LocalAuthentication(); - - //TODO Elham remove this fun - @override - void initState() { - super.initState(); - } - -//TODO Elham remove this fun - @override - void didChangeDependencies() async{ - super.didChangeDependencies(); - - } - @override Widget build(BuildContext context) { doctorProfileViewModel = Provider.of(context); @@ -93,7 +65,6 @@ class _VerificationMethodsScreenState extends State { child: FractionallySizedBox( child: Container( margin: EdgeInsetsDirectional.fromSTEB(30, 0, 30, 0), - height: SizeConfig.realScreenHeight * .95, width: SizeConfig.realScreenWidth, child: Column( @@ -102,7 +73,6 @@ class _VerificationMethodsScreenState extends State { children: [ Container( child: Column( - children: [ SizedBox( height: 100, @@ -146,54 +116,61 @@ class _VerificationMethodsScreenState extends State { 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 - ? model.getDate( - DateUtils - .convertStringToDate( - model.user - .editedOn)) - : model.user.createdOn != null - ? model - .getDate(DateUtils - .convertStringToDate( - model.user.createdOn)) - : '--', - textAlign: TextAlign.right, - fontSize: 14, - fontWeight: FontWeight.w800, - ), - subtitle: AppText( - model.user.editedOn != null - ? model.getTime( - DateUtils - .convertStringToDate( - model.user - .editedOn)) - : model.user.createdOn != null - ? model - .getTime(DateUtils - .convertStringToDate( - model.user.createdOn)) - : '--', - textAlign: TextAlign.right, - fontSize: 14, - ), - )) - ], - )), + 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, + ), + )) + ], + )), ], ) : Column( @@ -228,43 +205,39 @@ class _VerificationMethodsScreenState extends State { children: [ Expanded( child: InkWell( - onTap: () => { - // TODO check this logic it seem it will create bug to us - authenticateUser(AuthMethodTypes.Fingerprint, true) - }, - child: MethodCard( - authMethodType: model.user - .logInTypeID == - 4 - ? AuthMethodTypes.FaceID - : model.user.logInTypeID == 2 - ? AuthMethodTypes - .WhatsApp - : model.user.logInTypeID == - 3 - ? AuthMethodTypes - .Fingerprint - : AuthMethodTypes - .SMS, + 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), + authMethodType, + isActive) => + authenticateUser( + authMethodType, + isActive), )), ), Expanded( - child: MethodCard( - authMethodType: + child: VerificationMethodsList( + model: model, + authMethodType: AuthMethodTypes.MoreOptions, - onShowMore: () { - setState(() { - isMoreOption = true; - }); - }, - )) + onShowMore: () { + setState(() { + isMoreOption = true; + }); + }, + )) ]), ]) : Column( @@ -277,29 +250,31 @@ class _VerificationMethodsScreenState extends State { MainAxisAlignment.center, children: [ Expanded( - child: MethodCard( - authMethodType: + child: VerificationMethodsList( + model: model, + authMethodType: AuthMethodTypes.Fingerprint, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => authenticateUser( authMethodType, isActive), - )), + )), Expanded( - child: MethodCard( - authMethodType: + child: VerificationMethodsList( + model: model, + authMethodType: AuthMethodTypes.FaceID, - authenticateUser: - (AuthMethodTypes - authMethodType, - isActive) => + authenticateUser: + (AuthMethodTypes + authMethodType, + isActive) => authenticateUser( authMethodType, isActive), - )) + )) ], ) : SizedBox(), @@ -308,60 +283,79 @@ class _VerificationMethodsScreenState extends State { MainAxisAlignment.center, children: [ Expanded( - child: MethodCard( - authMethodType: AuthMethodTypes.SMS, - authenticateUser: - (AuthMethodTypes authMethodType, - isActive) => + child: VerificationMethodsList( + model: model, + authMethodType: AuthMethodTypes + .SMS, + authenticateUser: + ( + AuthMethodTypes authMethodType, + isActive) => authenticateUser( authMethodType, isActive), - )), + )), Expanded( - child: MethodCard( - authMethodType: + child: VerificationMethodsList( + model: model, + authMethodType: AuthMethodTypes.WhatsApp, - authenticateUser: - (AuthMethodTypes authMethodType, - isActive) => + authenticateUser: + ( + AuthMethodTypes authMethodType, + isActive) => authenticateUser( authMethodType, isActive), - )) + )) ], ), - ]), + ]), // ) ], ), ), - //TODO Elham move it to bottom sheet - Column( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - model.user != null - ? Row( - children: [ - Expanded( - child: AppButton( - title: TranslationBase.of(context) - .useAnotherAccount, - color: Colors.red[700], - onPressed: () { - Navigator.of(context).pushNamed(LOGIN); - }, - )), - ], - ) - : SizedBox(), - ], - ), ], ), - ), + ), ), ), ), - )); + 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,) + ], + ), + ), + ),), + ) + + ); } sendActivationCodeByOtpNotificationType( @@ -391,8 +385,6 @@ class _VerificationMethodsScreenState extends State { sendActivationCodeVerificationScreen(AuthMethodTypes authMethodType) async { GifLoaderDialogUtils.showMyDialog(context); - - await model .sendActivationCodeVerificationScreen(authMethodType); @@ -466,32 +458,21 @@ class _VerificationMethodsScreenState extends State { }, () => { - widget.changeLoadingState(false), print('Faild..'), }, ).displayDialog(context); } -//TODO Elham move it to view model loginWithFingerPrintOrFaceID(AuthMethodTypes authMethodTypes, isActive) async { if (isActive) { - const iosStrings = const IOSAuthMessages( - cancelButton: 'cancel', - goToSettingsButton: 'settings', - goToSettingsDescription: 'Please set up your Touch ID.', - lockOut: 'Please reenable your Touch ID'); - - try { - authenticated = await auth.authenticateWithBiometrics( - localizedReason: 'Scan your fingerprint to authenticate', - useErrorDialogs: true, - stickyAuth: true, - iOSAuthStrings: iosStrings); - } on PlatformException catch (e) { - DrAppToastMsg.showErrorToast(e.toString()); - } + await model.showIOSAuthMessages(); if (!mounted) return; - if (model.user != null && (model.user.logInTypeID == 3 || model.user.logInTypeID == 4)) { + if (model.user != null && + (SelectedAuthMethodTypesService.getMethodsTypeService( + model.user.logInTypeID) == + AuthMethodTypes.Fingerprint || + SelectedAuthMethodTypesService.getMethodsTypeService( + model.user.logInTypeID) == AuthMethodTypes.FaceID)) { this.sendActivationCode(authMethodTypes); } else { setState(() { @@ -502,64 +483,30 @@ class _VerificationMethodsScreenState extends State { } checkActivationCode({value}) async { - - await model.checkActivationCodeForDoctorApp(activationCode:value ); - + await model.checkActivationCodeForDoctorApp(activationCode: value); if (model.state == ViewState.ErrorLocal) { Navigator.pop(context); Helpers.showErrorToast(model.error); } else { - sharedPref.setString( - TOKEN, model.checkActivationCodeForDoctorAppRes.authenticationTokenID); - //TODO Elham check the logic - if (model.checkActivationCodeForDoctorAppRes.listDoctorsClinic.isNotEmpty) { - loginProcessCompleted(model.checkActivationCodeForDoctorAppRes.list_DoctorProfile[0]); - sharedPref.setObj( - CLINIC_NAME, - model - .checkActivationCodeForDoctorAppRes.listDoctorsClinic); - } else { - sharedPref.setObj( - CLINIC_NAME, - model - .checkActivationCodeForDoctorAppRes.listDoctorsClinic); - ClinicModel clinic = ClinicModel.fromJson(model.checkActivationCodeForDoctorAppRes.listDoctorsClinic[0].toJson()); - getDocProfiles(clinic); - } + await model.onCheckActivationCodeSuccess(); + navigateToLandingPage(); } } - //TODO Elham move it to view model - loginProcessCompleted(Map profile) { - var doctor = DoctorProfileModel.fromJson(profile); - doctorProfileViewModel.setDoctorProfile(doctor); - sharedPref.setObj(DOCTOR_PROFILE, profile); - projectsProvider.isLogin = true; - Navigator.pushAndRemoveUntil( - context, - FadePage( - page: LandingPage(), - ), - (r) => false); - } -//TODO Elham move it to view model - getDocProfiles(ClinicModel clinicInfo) { - ProfileReqModel docInfo = new ProfileReqModel( - doctorID: clinicInfo.doctorID, - clinicID: clinicInfo.clinicID, - license: true, - projectID: clinicInfo.projectID, - tokenID: '', - languageID: 2); - doctorProfileViewModel.getDocProfiles(docInfo.toJson()).then((res) { - if (res['MessageStatus'] == 1) { - loginProcessCompleted(res['DoctorProfileList'][0]); - } else { - Helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - Helpers.showErrorToast(err); - }); + navigateToLandingPage() { + if (model.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(model.error); + } else { + projectsProvider.isLogin = true; + + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: LandingPage(), + ), (r) => false); + } } + + } diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 6967a8aa..eb702d8d 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -1,6 +1,8 @@ import 'package:connectivity/connectivity.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_model.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/models/doctor/list_doctor_working_hours_table_model.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; @@ -22,7 +24,7 @@ class Helpers { static int cupertinoPickerIndex = 0; get currentLanguage => null; - static showCupertinoPicker(context, items, decKey, onSelectFun) { + static showCupertinoPicker(context, List items, decKey, onSelectFun, AuthenticationViewModel model) { showModalBottomSheet( isDismissible: false, context: context, @@ -53,7 +55,7 @@ class Helpers { ), onPressed: () { Navigator.pop(context); - onSelectFun(cupertinoPickerIndex); + onSelectFun(cupertinoPickerIndex, model); }, ) ], @@ -63,7 +65,7 @@ class Helpers { height: SizeConfig.realScreenHeight * 0.3, color: Color(0xfff7f7f7), child: - buildPickerItems(context, items, decKey, onSelectFun)) + buildPickerItems(context, items, decKey, onSelectFun, model)) ], ), ); @@ -73,14 +75,14 @@ class Helpers { static TextStyle textStyle(context) => TextStyle(color: Theme.of(context).primaryColor); - static buildPickerItems(context, List items, decKey, onSelectFun) { + static buildPickerItems(context, List items, decKey, onSelectFun, model) { return CupertinoPicker( magnification: 1.5, scrollController: FixedExtentScrollController(initialItem: cupertinoPickerIndex), children: items.map((item) { return Text( - '${item["$decKey"]}', + '${item.facilityName}', style: TextStyle(fontSize: SizeConfig.textMultiplier * 2), ); }).toList(), @@ -151,7 +153,7 @@ class Helpers { Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( - page: Loginsreen(), + page: LoginScreen(), ), (r) => false); } diff --git a/lib/widgets/auth/auth_header.dart b/lib/widgets/auth/auth_header.dart deleted file mode 100644 index 27396980..00000000 --- a/lib/widgets/auth/auth_header.dart +++ /dev/null @@ -1,113 +0,0 @@ -import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:hexcolor/hexcolor.dart'; - -import '../../config/size_config.dart'; -import '../../lookups/auth_lookup.dart'; -//TODO Elham delete this widget -class AuthHeader extends StatelessWidget { - var userType; - AuthHeader(this.userType); - - @override - Widget build(BuildContext context) { - var screen = Container( - margin: SizeConfig.isMobile - ? null - : EdgeInsetsDirectional.fromSTEB(SizeConfig.realScreenWidth * 0.30, - SizeConfig.realScreenWidth * 0.1, 0, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - height: 30, - ), - ], - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: SizeConfig.isMobile - ? [ - SizedBox( - height: 10, - ), - buildWelText(context), - buildDrSulText(context), - ] - : [ - SizedBox( - height: 10, - ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - buildWelText(context), - buildDrSulText(context), - ], - ), - ], - ), - buildDrAppContainer(context) - ], - )); - return screen; - } - - - Container buildDrAppContainer(BuildContext context) { - if (userType == loginType.changePassword || - userType == loginType.verifyPassword || - userType == loginType.verificationMethods) { - return Container(); - } - return Container( - child: Text( - "Doctor App", - style: TextStyle( - fontSize: - SizeConfig.isMobile ? 16 : SizeConfig.realScreenWidth * 0.030, - fontWeight: FontWeight.w800, - color: HexColor('#B8382C')), - ), - ); - } - - Text buildDrSulText(BuildContext context) { - if (userType == loginType.changePassword || - userType == loginType.verifyPassword || - userType == loginType.verificationMethods) { - return Text(''); - } - return Text( - TranslationBase.of(context).drSulaimanAlHabib, - style: TextStyle( - fontWeight: FontWeight.w800, - fontSize: - SizeConfig.isMobile ? 24 : SizeConfig.realScreenWidth * 0.029, - fontFamily: 'Poppins'), - ); - } - - Widget buildWelText(BuildContext context) { - String text = TranslationBase.of(context).welcomeTo; - if (userType == loginType.unknownUser) { - text = TranslationBase.of(context).welcomeBackTo; - } - if (userType == loginType.changePassword || - userType == loginType.verifyPassword || - userType == loginType.verificationMethods) { - return Text(''); - } - return AppText( - text, - // style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - ); - } -} diff --git a/lib/widgets/auth/method_card.dart b/lib/widgets/auth/method_card.dart deleted file mode 100644 index 79721381..00000000 --- a/lib/widgets/auth/method_card.dart +++ /dev/null @@ -1,244 +0,0 @@ -import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; -import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; -import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:local_auth/local_auth.dart'; -import 'package:provider/provider.dart'; - -class MethodCard extends StatefulWidget { - final AuthMethodTypes authMethodType; - final Function ( AuthMethodTypes type, bool isActive) authenticateUser; - final Function onShowMore; - - const MethodCard({Key key, this.authMethodType, this.authenticateUser, this.onShowMore}) : super(key: key); - - @override - _MethodCardState createState() => _MethodCardState(); -} - -class _MethodCardState extends State { - - //TODO Elham change it to list Enum - var _availableBiometrics; - - final LocalAuthentication auth = LocalAuthentication(); - ProjectViewModel projectsProvider; - - - - @override - void initState() { - super.initState(); - _getAvailableBiometrics(); - } - - - bool checkIfBiometricAvailable(BiometricType biometricType) { - bool isAvailable = false; - if (_availableBiometrics != null) { - for (var i = 0; i < _availableBiometrics.length; i++) { - if (biometricType == _availableBiometrics[i]) isAvailable = true; - } - } - return isAvailable; - } - - Future _getAvailableBiometrics() async { - var availableBiometrics; - try { - availableBiometrics = await auth.getAvailableBiometrics(); - } on PlatformException catch (e) { - print(e); - } - if (!mounted) return; - - setState(() { - _availableBiometrics = availableBiometrics; - }); - } - @override - Widget build(BuildContext context) { - projectsProvider = Provider.of(context); - - switch (widget.authMethodType) { - case AuthMethodTypes.WhatsApp: - return InkWell( - onTap: () => {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)}, - //TODO Elham change it to widget - child: Container( - margin: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Image.asset( - 'assets/images/verify-whtsapp.png', - height: 60, - width: 60, - ), - ], - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifyWhatsApp, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - case AuthMethodTypes.SMS: - return InkWell( - onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)}, - child: Container( - margin: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/verify-sms.png', - height: 60, - width: 60, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifySMS, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - case AuthMethodTypes.Fingerprint: - return InkWell( - onTap: () => { - if (checkIfBiometricAvailable(BiometricType.fingerprint)) - {widget.authenticateUser(AuthMethodTypes.Fingerprint, true)} - }, - child: Container( - margin: EdgeInsets.all(10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/verification_fingerprint_icon.png', - height: 60, - width: 60, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifyFingerprint, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - case AuthMethodTypes.FaceID: - return InkWell( - onTap: () { - if (checkIfBiometricAvailable(BiometricType.face)) { - widget.authenticateUser(AuthMethodTypes.FaceID, true); - } - }, - child: - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - margin: EdgeInsets.all(10), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/verification_faceid_icon.png', - height: 60, - width: 60, - ), - SizedBox( - height: 20, - ), - AppText( - TranslationBase.of(context).verifyFaceID, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - break; - - default: - return InkWell( - onTap: widget.onShowMore, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Colors.white, - ), - child: Padding( - padding: EdgeInsets.fromLTRB(20, 15, 20, 15), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - 'assets/images/login/more_icon.png', - height: 60, - width: 60, - ), - projectsProvider.isArabic - ? SizedBox( - height: 20, - ) - : SizedBox( - height: 10, - ), - AppText( - TranslationBase.of(context).moreVerification, - fontSize: 14, - fontWeight: FontWeight.w600, - ) - ], - ), - ))); - }; - } -} diff --git a/lib/widgets/auth/method_type_card.dart b/lib/widgets/auth/method_type_card.dart new file mode 100644 index 00000000..45190d2c --- /dev/null +++ b/lib/widgets/auth/method_type_card.dart @@ -0,0 +1,53 @@ +import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; +import 'package:flutter/material.dart'; + +class MethodTypeCard extends StatelessWidget { + const MethodTypeCard({ + Key key, + this.assetPath, + this.onTap, + this.label, + }) : super(key: key); + final String assetPath; + final Function onTap; + final String label; + + @override + Widget build(BuildContext context) { + return InkWell( + onTap: onTap, + child: Container( + margin: EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + ), + child: Padding( + padding: EdgeInsets.fromLTRB(20, 15, 20, 15), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Image.asset( + assetPath, + height: 60, + width: 60, + ), + ], + ), + SizedBox( + height: 20, + ), + AppText( + label, + fontSize: 14, + fontWeight: FontWeight.w600, + ) + ], + ), + )), + ); + } +} diff --git a/lib/widgets/auth/verification_methods_list.dart b/lib/widgets/auth/verification_methods_list.dart new file mode 100644 index 00000000..e42e33ba --- /dev/null +++ b/lib/widgets/auth/verification_methods_list.dart @@ -0,0 +1,87 @@ +import 'package:doctor_app_flutter/core/enum/auth_method_types.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/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/auth/method_type_card.dart'; +import 'package:flutter/material.dart'; +import 'package:local_auth/local_auth.dart'; +import 'package:provider/provider.dart'; + +class VerificationMethodsList extends StatefulWidget { + final AuthMethodTypes authMethodType; + final Function(AuthMethodTypes type, bool isActive) authenticateUser; + final Function onShowMore; + final AuthenticationViewModel model; + + const VerificationMethodsList( + {Key key, + this.authMethodType, + this.authenticateUser, + this.onShowMore, + this.model}) + : super(key: key); + + @override + _VerificationMethodsListState createState() => + _VerificationMethodsListState(); +} + +class _VerificationMethodsListState extends State { + final LocalAuthentication auth = LocalAuthentication(); + ProjectViewModel projectsProvider; + + @override + Widget build(BuildContext context) { + projectsProvider = Provider.of(context); + + switch (widget.authMethodType) { + case AuthMethodTypes.WhatsApp: + return MethodTypeCard( + assetPath: 'assets/images/verify-whtsapp.png', + onTap: () => + {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)}, + label: TranslationBase.of(context).verifyWhatsApp, + ); + break; + case AuthMethodTypes.SMS: + return MethodTypeCard( + assetPath: "assets/images/verify-sms.png", + onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)}, + label: TranslationBase.of(context).verifySMS, + ); + break; + case AuthMethodTypes.Fingerprint: + return MethodTypeCard( + assetPath: 'assets/images/verification_fingerprint_icon.png', + onTap: () async { + if (await widget.model + .checkIfBiometricAvailable(BiometricType.fingerprint)) { + + widget.authenticateUser(AuthMethodTypes.Fingerprint, true); + } + }, + label: TranslationBase.of(context).verifyFingerprint, + ); + break; + case AuthMethodTypes.FaceID: + return MethodTypeCard( + assetPath: 'assets/images/verification_faceid_icon.png', + onTap: () async { + if (await widget.model + .checkIfBiometricAvailable(BiometricType.face)) { + widget.authenticateUser(AuthMethodTypes.FaceID, true); + } + }, + label: TranslationBase.of(context).verifyFaceID, + ); + break; + + default: + return MethodTypeCard( + assetPath: 'assets/images/login/more_icon.png', + onTap: widget.onShowMore, + label: TranslationBase.of(context).moreVerification, + ); + } + } +} From 2e71706cabfde4279ca44ff774f9001194a5a374 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 10 May 2021 15:07:03 +0300 Subject: [PATCH 16/28] 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); } From 6815e4781454dfaa15b282beb8d63c131ef17739 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 10 May 2021 16:03:07 +0300 Subject: [PATCH 17/28] remove doctor profile view model --- lib/core/service/authentication_service.dart | 15 +---- .../viewModel/authentication_view_model.dart | 9 +-- .../viewModel/doctor_profile_view_model.dart | 67 ------------------- lib/core/viewModel/project_view_model.dart | 22 ++---- lib/main.dart | 4 -- lib/root_page.dart | 1 - .../auth/verification_methods_screen.dart | 3 - lib/screens/home/home_screen.dart | 45 +++++-------- .../out_patient/out_patient_screen.dart | 8 +-- .../patient_search_result_screen.dart | 6 +- .../patient_search/patient_search_screen.dart | 8 +-- .../profile/note/progress_note_screen.dart | 14 ++-- .../referral/my-referral-detail-screen.dart | 6 +- .../referral/my-referral-patient-screen.dart | 4 -- .../assessment/add_assessment_details.dart | 1 - .../profile/profile-welcome-widget.dart | 6 +- lib/widgets/shared/app_drawer_widget.dart | 10 +-- lib/widgets/shared/app_loader_widget.dart | 27 +------- 18 files changed, 52 insertions(+), 204 deletions(-) delete mode 100644 lib/core/viewModel/doctor_profile_view_model.dart diff --git a/lib/core/service/authentication_service.dart b/lib/core/service/authentication_service.dart index ffa22f33..f033d4f7 100644 --- a/lib/core/service/authentication_service.dart +++ b/lib/core/service/authentication_service.dart @@ -1,19 +1,16 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/model/auth/activation_Code_req_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; import 'package:doctor_app_flutter/core/model/auth/check_activation_code_for_doctor_app_response_model.dart'; +import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; import 'package:doctor_app_flutter/core/model/auth/imei_details.dart'; import 'package:doctor_app_flutter/core/model/auth/insert_imei_model.dart'; import 'package:doctor_app_flutter/core/model/auth/new_login_information_response_model.dart'; import 'package:doctor_app_flutter/core/model/auth/send_activation_code_for_doctor_app_response_model.dart'; import 'package:doctor_app_flutter/core/service/base/base_service.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/activation_code_for_verification_screen_model.dart'; -import 'package:doctor_app_flutter/core/model/auth/check_activation_code_request_model.dart'; -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:provider/provider.dart'; class AuthenticationService extends BaseService { List _imeiDetails = []; @@ -115,15 +112,7 @@ class AuthenticationService extends BaseService { try { await baseAppClient.post(CHECK_ACTIVATION_CODE_FOR_DOCTOR_APP, onSuccess: (dynamic response, int statusCode) { - // TODO improve the logic here - Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.clear(); _checkActivationCodeForDoctorAppRes = CheckActivationCodeForDoctorAppResponseModel.fromJson(response); - Provider.of(AppGlobal.CONTEX, listen: false).selectedClinicName = - ClinicModel.fromJson(response['List_DoctorsClinic'][0]).clinicName; - - response['List_DoctorsClinic'].forEach((v) { - Provider.of(AppGlobal.CONTEX, listen: false).doctorsClinicList.add(new ClinicModel.fromJson(v)); - }); }, onFailure: (String error, int statusCode) { hasError = true; super.error = error; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index c35c4e12..c552e40e 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -29,9 +29,6 @@ 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'; -import 'package:provider/provider.dart'; - -import 'doctor_profile_view_model.dart'; enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED, UNVERIFIED } @@ -72,6 +69,7 @@ class AuthenticationViewModel extends BaseViewModel { AuthenticationViewModel({bool checkDeviceInfo = false}) { getDeviceInfoFromFirebase(); + getDoctorProfile(); } Future selectDeviceImei(imei) async { @@ -287,9 +285,6 @@ class AuthenticationViewModel extends BaseViewModel { localSetDoctorProfile(DoctorProfileModel profile) { super.setDoctorProfile(profile); - //TODO: Remove it when we remove Doctor Profile View Model and start to use profile form base view model - Provider.of(AppGlobal.CONTEX, listen: false) - .setDoctorProfile(profile); } Future getDoctorProfileBasedOnClinic(ClinicModel clinicInfo) async { @@ -358,7 +353,7 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Busy); _firebaseMessaging.getToken().then((String token) async { - if (DEVICE_TOKEN == "") { + if (DEVICE_TOKEN == "" && !isLogin) { DEVICE_TOKEN = token; await _authService.selectDeviceImei(DEVICE_TOKEN); diff --git a/lib/core/viewModel/doctor_profile_view_model.dart b/lib/core/viewModel/doctor_profile_view_model.dart deleted file mode 100644 index 6210951e..00000000 --- a/lib/core/viewModel/doctor_profile_view_model.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:doctor_app_flutter/client/base_app_client.dart'; -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/core/service/authentication_service.dart'; -import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; -import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; -import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; - -import '../../locator.dart'; - - -class DoctorProfileViewModel extends BaseViewModel { - List doctorsClinicList = []; - AuthenticationService _authService = locator(); - - - String selectedClinicName; - bool isLogin = false; - bool isLoading = true; - DoctorProfileModel doctorProfile; - BaseAppClient baseAppClient = BaseAppClient(); - setDoctorProfile(DoctorProfileModel profileModel) { - doctorProfile = profileModel; - notifyListeners(); - } - - DoctorProfileViewModel() { - getUserProfile(); - } - - getUserProfile() async { - Map profile = await sharedPref.getObj(DOCTOR_PROFILE); - if (profile != null) { - doctorProfile = new DoctorProfileModel.fromJson(profile); - isLoading = false; - isLogin = true; - } else { - isLoading = false; - isLogin = false; - } - notifyListeners(); - } - - Future getDocProfiles(docInfo, - {bool allowChangeProfile = true}) async { - try { - dynamic localRes; - await baseAppClient.post(GET_DOC_PROFILES, - onSuccess: (dynamic response, int statusCode) { - localRes = response; - if (allowChangeProfile) { - doctorProfile = - DoctorProfileModel.fromJson(response['DoctorProfileList'][0]); - selectedClinicName = - response['DoctorProfileList'][0]['ClinicDescription']; - } - }, onFailure: (String error, int statusCode) { - throw error; - }, body: docInfo); - notifyListeners(); - return Future.value(localRes); - } catch (error) { - print(error); - throw error; - } - } -} diff --git a/lib/core/viewModel/project_view_model.dart b/lib/core/viewModel/project_view_model.dart index 0bf0c844..494e3b10 100644 --- a/lib/core/viewModel/project_view_model.dart +++ b/lib/core/viewModel/project_view_model.dart @@ -4,15 +4,15 @@ import 'package:connectivity/connectivity.dart'; import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; 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/util/dr_app_shared_pref.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/cupertino.dart'; import 'package:provider/provider.dart'; +import 'authentication_view_model.dart'; + Helpers helpers = Helpers(); class ProjectViewModel with ChangeNotifier { @@ -116,19 +116,9 @@ class ProjectViewModel with ChangeNotifier { void getProfile() async { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); DoctorProfileModel doctorProfile = new DoctorProfileModel.fromJson(profile); - ProfileReqModel docInfo = new ProfileReqModel( - doctorID: doctorProfile.doctorID, - clinicID: doctorProfile.clinicID, - license: true, - projectID: doctorProfile.projectID, - ); - - Provider.of(AppGlobal.CONTEX, listen: false) - .getDocProfiles(docInfo.toJson()) - .then((res) async { - sharedPref.setObj(DOCTOR_PROFILE, res['DoctorProfileList'][0]); - }).catchError((err) { - print(err); - }); + ClinicModel clinicModel = ClinicModel(doctorID:doctorProfile.doctorID,clinicID: doctorProfile.clinicID, projectID: doctorProfile.projectID,); + + await Provider.of(AppGlobal.CONTEX, listen: false) + .getDoctorProfileBasedOnClinic(clinicModel); } } diff --git a/lib/main.dart b/lib/main.dart index b7acdd80..a95378e5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,8 +12,6 @@ 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'; void main() async { @@ -35,8 +33,6 @@ class MyApp extends StatelessWidget { providers: [ ChangeNotifierProvider( create: (context) => AuthenticationViewModel()), - ChangeNotifierProvider( - create: (context) => DoctorProfileViewModel()), ChangeNotifierProvider( create: (context) => ProjectViewModel(), ), diff --git a/lib/root_page.dart b/lib/root_page.dart index 6040b160..5c14288e 100644 --- a/lib/root_page.dart +++ b/lib/root_page.dart @@ -14,7 +14,6 @@ class RootPage extends StatelessWidget { @override Widget build(BuildContext context) { AuthenticationViewModel authenticationViewModel = Provider.of(context); - // ignore: missing_return Widget buildRoot() { switch (authenticationViewModel.stutas) { case APP_STATUS.LOADING: diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 40749b84..9ff1f86c 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -4,7 +4,6 @@ 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/util/date-utils.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; @@ -42,14 +41,12 @@ class _VerificationMethodsScreenState extends State { ProjectViewModel projectsProvider; bool isMoreOption = false; bool onlySMSBox = false; - DoctorProfileViewModel doctorProfileViewModel; AuthMethodTypes fingerPrintBefore; AuthMethodTypes selectedOption; AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { - doctorProfileViewModel = Provider.of(context); projectsProvider = Provider.of(context); authenticationViewModel = Provider.of(context); diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index d48e6417..6fa38a43 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -2,26 +2,21 @@ import 'package:charts_flutter/flutter.dart' as charts; 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/patient_type.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; +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/patient/patient_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/medicine/medicine_search_screen.dart'; -import 'package:doctor_app_flutter/screens/patients/DischargedPatientPage.dart'; import 'package:doctor_app_flutter/screens/patients/PatientsInPatientScreen.dart'; -import 'package:doctor_app_flutter/screens/patients/ReferralDischargedPatientPage.dart'; import 'package:doctor_app_flutter/screens/patients/out_patient/out_patient_screen.dart'; import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_screen.dart'; -import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_result_screen.dart'; 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_shared_pref.dart'; @@ -35,6 +30,7 @@ import 'package:doctor_app_flutter/widgets/dashboard/swiper_rounded_pagination.d import 'package:doctor_app_flutter/widgets/patients/profile/profile-welcome-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/loader/gif_loader_dialog_utils.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; @@ -43,7 +39,6 @@ import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:provider/provider.dart'; import 'package:sticky_headers/sticky_headers/widget.dart'; -import '../../locator.dart'; import '../../widgets/shared/app_texts_widget.dart'; import '../../widgets/shared/rounded_container_widget.dart'; import 'home_page_card.dart'; @@ -63,7 +58,6 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); - DoctorProfileViewModel authProvider; bool isLoading = false; ProjectViewModel projectsProvider; var _isInit = true; @@ -111,7 +105,6 @@ class _HomeScreenState extends State { @override Widget build(BuildContext context) { myContext = context; - authProvider = Provider.of(context); projectsProvider = Provider.of(context); FocusScopeNode currentFocus = FocusScope.of(context); @@ -584,7 +577,7 @@ class _HomeScreenState extends State { PatientSearchRequestModel( from: date, to: date, - doctorID: authProvider + doctorID: authenticationViewModel .doctorProfile .doctorID)), )); @@ -811,24 +804,16 @@ class _HomeScreenState extends State { } changeClinic(clinicId, BuildContext context, model) async { - // Navigator.pop(context); - changeIsLoading(true); - Map profile = await sharedPref.getObj(DOCTOR_PROFILE); - DoctorProfileModel doctorProfile = new DoctorProfileModel.fromJson(profile); - ProfileReqModel docInfo = new ProfileReqModel( - doctorID: doctorProfile.doctorID, - clinicID: clinicId, - license: true, - projectID: doctorProfile.projectID, - tokenID: '', - languageID: 2); - authProvider.getDocProfiles(docInfo.toJson()).then((res) async { - changeIsLoading(false); - sharedPref.setObj(DOCTOR_PROFILE, res['DoctorProfileList'][0]); - }).catchError((err) { - changeIsLoading(false); - Helpers.showErrorToast(err); - }); + GifLoaderDialogUtils.showMyDialog(context); + DoctorProfileModel doctorProfile = authenticationViewModel.doctorProfile; + + ClinicModel clinic = ClinicModel(clinicID:clinicId, doctorID: doctorProfile.doctorID,projectID: doctorProfile.projectID, ); + await authenticationViewModel.getDoctorProfileBasedOnClinic(clinic); + if(authenticationViewModel.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(authenticationViewModel.error); + + } + GifLoaderDialogUtils.hideDialog(context); } changeIsLoading(bool val) { diff --git a/lib/screens/patients/out_patient/out_patient_screen.dart b/lib/screens/patients/out_patient/out_patient_screen.dart index c6549568..77324ea5 100644 --- a/lib/screens/patients/out_patient/out_patient_screen.dart +++ b/lib/screens/patients/out_patient/out_patient_screen.dart @@ -4,7 +4,7 @@ import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/patient_model.dart'; @@ -60,9 +60,9 @@ class OutPatientsScreen extends StatefulWidget { class _OutPatientsScreenState extends State { int clinicId; - DoctorProfileViewModel authProvider; + AuthenticationViewModel authenticationViewModel; - List _times = []; //['All', 'Today', 'Tomorrow', 'Next Week']; + List _times = []; int _activeLocation = 1; String patientType; @@ -79,7 +79,7 @@ class _OutPatientsScreenState extends State { @override Widget build(BuildContext context) { - authProvider = Provider.of(context); + authenticationViewModel = Provider.of(context); _times = [ TranslationBase .of(context) diff --git a/lib/screens/patients/patient_search/patient_search_result_screen.dart b/lib/screens/patients/patient_search/patient_search_result_screen.dart index 05de14db..9e53ab19 100644 --- a/lib/screens/patients/patient_search/patient_search_result_screen.dart +++ b/lib/screens/patients/patient_search/patient_search_result_screen.dart @@ -2,7 +2,7 @@ import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/patient_model.dart'; @@ -48,7 +48,7 @@ class PatientsSearchResultScreen extends StatefulWidget { class _PatientsSearchResultScreenState extends State { int clinicId; - DoctorProfileViewModel authProvider; + AuthenticationViewModel authenticationViewModel; String patientType; @@ -64,7 +64,7 @@ class _PatientsSearchResultScreenState @override Widget build(BuildContext context) { - authProvider = Provider.of(context); + authenticationViewModel = Provider.of(context); return BaseView( onModelReady: (model) async { if(!widget.isSearchWithKeyInfo && widget.selectedPatientType == PatientType.OutPatient) { diff --git a/lib/screens/patients/patient_search/patient_search_screen.dart b/lib/screens/patients/patient_search/patient_search_screen.dart index 192a37c9..682d28c3 100644 --- a/lib/screens/patients/patient_search/patient_search_screen.dart +++ b/lib/screens/patients/patient_search/patient_search_screen.dart @@ -2,7 +2,7 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/patient_type.dart'; import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart'; import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/patients/patient_search/patient_search_result_screen.dart'; import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; @@ -29,11 +29,11 @@ class _PatientSearchScreenState extends State { TextEditingController middleNameInfoController = TextEditingController(); TextEditingController lastNameFileInfoController = TextEditingController(); PatientType selectedPatientType = PatientType.inPatient; - DoctorProfileViewModel authProvider; + AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { - authProvider =Provider.of(context); + authenticationViewModel = Provider.of(context); return BaseView( onModelReady: (model) async {}, builder: (_, model, w) => AppScaffold( @@ -147,7 +147,7 @@ class _PatientSearchScreenState extends State { isFormSubmitted = true; }); PatientSearchRequestModel patientSearchRequestModel = - PatientSearchRequestModel(doctorID: authProvider.doctorProfile.doctorID); + PatientSearchRequestModel(doctorID: authenticationViewModel.doctorProfile.doctorID); if (showOther) { patientSearchRequestModel.firstName = firstNameInfoController.text.trim().isEmpty?"0":firstNameInfoController.text.trim(); patientSearchRequestModel.middleName = middleNameInfoController.text.trim().isEmpty?"0":middleNameInfoController.text.trim(); diff --git a/lib/screens/patients/profile/note/progress_note_screen.dart b/lib/screens/patients/profile/note/progress_note_screen.dart index 38b4edad..fdc9a3ce 100644 --- a/lib/screens/patients/profile/note/progress_note_screen.dart +++ b/lib/screens/patients/profile/note/progress_note_screen.dart @@ -1,6 +1,6 @@ import 'package:doctor_app_flutter/core/model/note/note_model.dart'; import 'package:doctor_app_flutter/core/model/note/update_note_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; @@ -39,10 +39,8 @@ class ProgressNoteScreen extends StatefulWidget { class _ProgressNoteState extends State { List notesList; var filteredNotesList; - final _controller = TextEditingController(); - var _isInit = true; bool isDischargedPatient = false; - DoctorProfileViewModel authProvider; + AuthenticationViewModel authenticationViewModel; ProjectViewModel projectViewModel; getProgressNoteList(BuildContext context, PatientViewModel model, @@ -71,7 +69,7 @@ class _ProgressNoteState extends State { @override Widget build(BuildContext context) { - authProvider = Provider.of(context); + authenticationViewModel = Provider.of(context); projectViewModel = Provider.of(context); final routeArgs = ModalRoute .of(context) @@ -141,7 +139,7 @@ class _ProgressNoteState extends State { bgColor: model.patientProgressNoteList[index] .status == 1 && - authProvider.doctorProfile.doctorID != + authenticationViewModel.doctorProfile.doctorID != model .patientProgressNoteList[ index] @@ -167,7 +165,7 @@ class _ProgressNoteState extends State { index] .status == 1 && - authProvider + authenticationViewModel .doctorProfile.doctorID != model .patientProgressNoteList[ @@ -213,7 +211,7 @@ class _ProgressNoteState extends State { index] .status != 4 && - authProvider + authenticationViewModel .doctorProfile.doctorID == model .patientProgressNoteList[ diff --git a/lib/screens/patients/profile/referral/my-referral-detail-screen.dart b/lib/screens/patients/profile/referral/my-referral-detail-screen.dart index 8eea6c34..0a690307 100644 --- a/lib/screens/patients/profile/referral/my-referral-detail-screen.dart +++ b/lib/screens/patients/profile/referral/my-referral-detail-screen.dart @@ -1,6 +1,5 @@ import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart'; import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/models/patient/my_referral/PendingReferral.dart'; @@ -15,16 +14,13 @@ 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:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; -import 'package:provider/provider.dart'; +// ignore: must_be_immutable class MyReferralDetailScreen extends StatelessWidget { PendingReferral pendingReferral; @override Widget build(BuildContext context) { - final gridHeight = (MediaQuery.of(context).size.width * 0.3) * 1.8; - - DoctorProfileViewModel authProvider = Provider.of(context); final routeArgs = ModalRoute.of(context).settings.arguments as Map; pendingReferral = routeArgs['referral']; diff --git a/lib/screens/patients/profile/referral/my-referral-patient-screen.dart b/lib/screens/patients/profile/referral/my-referral-patient-screen.dart index 1482db74..fe6fd2db 100644 --- a/lib/screens/patients/profile/referral/my-referral-patient-screen.dart +++ b/lib/screens/patients/profile/referral/my-referral-patient-screen.dart @@ -1,4 +1,3 @@ -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; @@ -7,15 +6,12 @@ import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:provider/provider.dart'; import '../../../../routes.dart'; class MyReferralPatientScreen extends StatelessWidget { - // previous design page is: MyReferralPatient @override Widget build(BuildContext context) { - DoctorProfileViewModel authProvider = Provider.of(context); return BaseView( onModelReady: (model) => model.getPendingReferralPatients(), diff --git a/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart b/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart index 57e2e53f..a30842f8 100644 --- a/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart +++ b/lib/screens/patients/profile/soap_update/assessment/add_assessment_details.dart @@ -3,7 +3,6 @@ import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/SOAP_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/models/SOAP/PatchAssessmentReqModel.dart'; import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; diff --git a/lib/widgets/patients/profile/profile-welcome-widget.dart b/lib/widgets/patients/profile/profile-welcome-widget.dart index 577d94bd..4d76fe41 100644 --- a/lib/widgets/patients/profile/profile-welcome-widget.dart +++ b/lib/widgets/patients/profile/profile-welcome-widget.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -11,7 +11,7 @@ class ProfileWelcomeWidget extends StatelessWidget { @override Widget build(BuildContext context) { - DoctorProfileViewModel authProvider = Provider.of(context); + AuthenticationViewModel authenticationViewModel = Provider.of(context); return Container( height: height, @@ -55,7 +55,7 @@ class ProfileWelcomeWidget extends StatelessWidget { child: ClipRRect( borderRadius: BorderRadius.circular(20), child: Image.network( - authProvider.doctorProfile.doctorImageURL, + authenticationViewModel.doctorProfile.doctorImageURL, fit: BoxFit.fill, width: 75, height: 75, diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index 5ca6bf84..a69b1370 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -1,4 +1,4 @@ -import 'package:doctor_app_flutter/core/viewModel/doctor_profile_view_model.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/icons_app/doctor_app_icons.dart'; import 'package:doctor_app_flutter/screens/reschedule-leaves/add-rescheduleleave.dart'; @@ -28,7 +28,7 @@ class _AppDrawerState extends State { @override Widget build(BuildContext context) { - DoctorProfileViewModel authProvider = Provider.of(context); + AuthenticationViewModel authenticationViewModel = Provider.of(context); projectsProvider = Provider.of(context); return RoundedContainer( child: Container( @@ -69,7 +69,7 @@ class _AppDrawerState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, ), SizedBox(height: 5), - if (authProvider.doctorProfile != null) + if (authenticationViewModel.doctorProfile != null) InkWell( onTap: () { // TODO: return it back when its needed @@ -85,7 +85,7 @@ class _AppDrawerState extends State { padding: EdgeInsets.only(top: 10), child: AppText( TranslationBase.of(context).dr + - authProvider.doctorProfile?.doctorName, + authenticationViewModel.doctorProfile?.doctorName, fontWeight: FontWeight.bold, color: Color(0xFF2E303A), fontFamily: 'Poppins', @@ -95,7 +95,7 @@ class _AppDrawerState extends State { Padding( padding: EdgeInsets.only(top: 0), child: AppText( - authProvider.doctorProfile?.clinicDescription, + authenticationViewModel.doctorProfile?.clinicDescription, fontWeight: FontWeight.w600, color: Color(0xFF2E303A), fontSize: 15, diff --git a/lib/widgets/shared/app_loader_widget.dart b/lib/widgets/shared/app_loader_widget.dart index 7b1f1718..ef614209 100644 --- a/lib/widgets/shared/app_loader_widget.dart +++ b/lib/widgets/shared/app_loader_widget.dart @@ -3,13 +3,6 @@ import 'package:progress_hud_v2/progress_hud.dart'; import 'loader/gif_loader_container.dart'; -/* - *@author: Elham Rababah - *@Date:19/4/2020 - *@param: - *@return: Positioned - *@desc: AppLoaderWidget to create loader - */ class AppLoaderWidget extends StatefulWidget { AppLoaderWidget({Key key, this.title, this.containerColor}) : super(key: key); @@ -21,25 +14,7 @@ class AppLoaderWidget extends StatefulWidget { } class _AppLoaderWidgetState extends State { - ProgressHUD _progressHUD; - @override - void initState() { - super.initState(); -/* - *@author: Elham Rababah - *@Date:19/4/2020 - *@param: - *@return: - *@desc: create loader the desing - */ - _progressHUD = new ProgressHUD( - backgroundColor: widget.containerColor == null ? Colors.black12 : widget.containerColor, - color: Colors.black, - // containerColor: Colors.blue, - borderRadius: 5.0, - // text: 'Loading...', - ); - } + @override Widget build(BuildContext context) { From 0adcfecccea04002eb9c6a298ceff698ad6db1ce Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 16 May 2021 11:22:28 +0300 Subject: [PATCH 18/28] fix auth bug --- lib/config/config.dart | 2 +- .../viewModel/authentication_view_model.dart | 17 ++------ .../auth/verification_methods_screen.dart | 6 +-- lib/screens/home/home_screen.dart | 2 +- lib/widgets/auth/sms-popup.dart | 40 ++--------------- .../profile/profile-welcome-widget.dart | 43 ++----------------- pubspec.lock | 6 +-- 7 files changed, 17 insertions(+), 99 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index ec8efe26..382e84b2 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -337,7 +337,7 @@ const TRANSACTION_NO = 0; const LANGUAGE_ID = 2; const STAMP = '2020-04-27T12:17:17.721Z'; const IP_ADDRESS = '9.9.9.9'; -const VERSION_ID = 6.0; +const VERSION_ID = 6.1; const CHANNEL = 9; const SESSION_ID = 'BlUSkYymTt'; const IS_LOGIN_FOR_DOCTOR_APP = true; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index c552e40e..77f76abb 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -17,6 +17,7 @@ import 'package:doctor_app_flutter/core/model/hospitals/get_hospitals_response_m import 'package:doctor_app_flutter/core/service/authentication_service.dart'; import 'package:doctor_app_flutter/core/service/hospitals/hospitals_service.dart'; import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; @@ -29,6 +30,7 @@ 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'; +import 'package:provider/provider.dart'; enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED, UNVERIFIED } @@ -237,19 +239,6 @@ class AuthenticationViewModel extends BaseViewModel { } } - getInitUserInfo()async{ - setState(ViewState.Busy); - var localLoggedUser = await sharedPref.getObj(LOGGED_IN_USER); - if(localLoggedUser!= null) { - loggedUser = NewLoginInformationModel.fromJson(localLoggedUser); - } - var lastLogin = await sharedPref.getObj(LAST_LOGIN_USER); - if (lastLogin != null) { - user = GetIMEIDetailsModel.fromJson(lastLogin); - } - setState(ViewState.Idle); - } - setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); @@ -353,7 +342,7 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Busy); _firebaseMessaging.getToken().then((String token) async { - if (DEVICE_TOKEN == "" && !isLogin) { + if (DEVICE_TOKEN == "" && !ProjectViewModel().isLogin) { DEVICE_TOKEN = token; await _authService.selectDeviceImei(DEVICE_TOKEN); diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 9ff1f86c..afd5604c 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -8,6 +8,7 @@ import 'package:doctor_app_flutter/core/viewModel/project_view_model.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'; +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'; @@ -429,7 +430,6 @@ class _VerificationMethodsScreenState extends State { } startSMSService(AuthMethodTypes type) { - // TODO improve this logic new SMSOTP( context, type, @@ -438,9 +438,7 @@ class _VerificationMethodsScreenState extends State { showDialog( context: context, builder: (BuildContext context) { - return Center( - child: CircularProgressIndicator(), - ); + return AppLoaderWidget(); }); this.checkActivationCode(value: value); diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index 6fa38a43..72ffc5c5 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -229,7 +229,7 @@ class _HomeScreenState extends State { ), ], ), - isClilic: true, + isClinic: true, height: 50, ), ]) diff --git a/lib/widgets/auth/sms-popup.dart b/lib/widgets/auth/sms-popup.dart index 6cbeab49..532f9cc1 100644 --- a/lib/widgets/auth/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/core/enum/auth_method_types.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; @@ -20,10 +21,6 @@ class SMSOTP { Future timer; - static BuildContext _context; - - static bool _loading; - SMSOTP( this.context, this.type, @@ -285,8 +282,6 @@ class SMSOTP { InputDecoration buildInputDecoration(BuildContext context) { return InputDecoration( counterText: " ", - // ts/images/password_icon.png - // contentPadding: EdgeInsets.only(top: 20, bottom: 20), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(10)), borderSide: BorderSide(color: Colors.grey[300]), @@ -306,6 +301,7 @@ class SMSOTP { ); } + // ignore: missing_return String validateCodeDigit(value) { if (value.isEmpty) { return ' '; @@ -317,7 +313,6 @@ class SMSOTP { } checkValue() { - //print(verifyAccountFormValue); if (verifyAccountForm.currentState.validate()) { onSuccess(digit1.text.toString() + digit2.text.toString() + @@ -343,6 +338,7 @@ class SMSOTP { startTimer(setState) { this.remainingTime--; + print(isClosed); setState(() { displayTime = this.getSecondsAsDigitalClock(this.remainingTime); }); @@ -355,34 +351,4 @@ class SMSOTP { } }); } - - static void showLoadingDialog(BuildContext context, bool _loading) async { - _context = context; - - if (_loading == false) { - Navigator.of(context).pop(); - return; - } - _loading = true; - await showDialog( - context: _context, - barrierDismissible: false, - builder: (BuildContext context) { - return SimpleDialog( - elevation: 0.0, - backgroundColor: Colors.transparent, - children: [ - Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation(Colors.black), - ), - ) - ], - ); - }); - } - - static void hideSMSBox(context) { - Navigator.pop(context); - } } diff --git a/lib/widgets/patients/profile/profile-welcome-widget.dart b/lib/widgets/patients/profile/profile-welcome-widget.dart index 4d76fe41..53228bc2 100644 --- a/lib/widgets/patients/profile/profile-welcome-widget.dart +++ b/lib/widgets/patients/profile/profile-welcome-widget.dart @@ -5,9 +5,9 @@ import 'package:provider/provider.dart'; class ProfileWelcomeWidget extends StatelessWidget { final Widget clinicWidget; final double height; - final bool isClilic; + final bool isClinic; ProfileWelcomeWidget(this.clinicWidget, - {this.height = 150, this.isClilic = false}); + {this.height = 150, this.isClinic = false}); @override Widget build(BuildContext context) { @@ -23,33 +23,11 @@ class ProfileWelcomeWidget extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.start, children: [ - this.isClilic == true ? clinicWidget : SizedBox(), - // Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisAlignment: MainAxisAlignment.start, - // children: [ - // Row( - // children: [ - // AppText( - // TranslationBase.of(context).welcome, - // fontSize: SizeConfig.textMultiplier * 1.7, - // color: Colors.black, - // ) - // ], - // ), - // Row( - // mainAxisAlignment: MainAxisAlignment.end, - // children: [ - // AppText( - // // TranslationBase.of(context).dr + - // ' ${authProvider.doctorProfile.doctorName}', - // fontWeight: FontWeight.bold, - // fontSize: SizeConfig.textMultiplier * 2.5, - // color: Colors.black, - // ), + this.isClinic == true ? clinicWidget : SizedBox(), SizedBox( width: 20, ), + if(authenticationViewModel.doctorProfile!=null) CircleAvatar( // radius: (52) child: ClipRRect( @@ -63,23 +41,10 @@ class ProfileWelcomeWidget extends StatelessWidget { ), backgroundColor: Colors.transparent, ), - // ], - // ), SizedBox( height: 20, ), - /// ], - // ), - // Expanded( - // child: Column( - // mainAxisAlignment: MainAxisAlignment.start, - // crossAxisAlignment: CrossAxisAlignment.end, - // children: [ - - // ], - // ), - // ), ], )), ); diff --git a/pubspec.lock b/pubspec.lock index 1a572a0a..825db695 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -615,7 +615,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.4" + version: "1.3.0-nullsafety.3" mime: dependency: transitive description: @@ -907,7 +907,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.2" + version: "1.10.0-nullsafety.1" sticky_headers: dependency: "direct main" description: @@ -1098,5 +1098,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.10.0 <=2.11.0-213.1.beta" + dart: ">=2.10.0 <2.11.0" flutter: ">=1.22.0 <2.0.0" From 1eeaaa48cae31f4af542af367688ac95ea2c447c Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 16 May 2021 11:23:05 +0300 Subject: [PATCH 19/28] remove comment --- lib/widgets/auth/sms-popup.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/widgets/auth/sms-popup.dart b/lib/widgets/auth/sms-popup.dart index 532f9cc1..5f073eca 100644 --- a/lib/widgets/auth/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -9,7 +9,6 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -//TODO Elham check it class SMSOTP { final AuthMethodTypes type; final mobileNo; From c9e7fb98835a81fcf7fadb58d69553ff9c6016b6 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 16 May 2021 11:26:26 +0300 Subject: [PATCH 20/28] small fix --- lib/widgets/auth/sms-popup.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/widgets/auth/sms-popup.dart b/lib/widgets/auth/sms-popup.dart index 5f073eca..cf16a0f1 100644 --- a/lib/widgets/auth/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -18,8 +18,6 @@ class SMSOTP { int remainingTime = 600; - Future timer; - SMSOTP( this.context, this.type, @@ -337,12 +335,11 @@ class SMSOTP { startTimer(setState) { this.remainingTime--; - print(isClosed); setState(() { displayTime = this.getSecondsAsDigitalClock(this.remainingTime); }); - timer = Future.delayed(Duration(seconds: 1), () { + Future.delayed(Duration(seconds: 1), () { if (this.remainingTime > 0) { if (isClosed == false) startTimer(setState); } else { From e0be4ec1bead8d88d742f45849666d0fcffe6ca9 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 16 May 2021 11:48:16 +0300 Subject: [PATCH 21/28] move logout function from helper to authentication view model --- lib/client/base_app_client.dart | 3 ++- lib/config/config.dart | 3 --- .../viewModel/authentication_view_model.dart | 26 ++++++++++++++----- lib/root_page.dart | 2 +- lib/util/helpers.dart | 14 ---------- lib/widgets/shared/app_drawer_widget.dart | 2 +- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index d6a72ab6..d79f0338 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -3,6 +3,7 @@ import 'dart:io' show Platform; import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; @@ -97,7 +98,7 @@ class BaseAppClient { if (body['OTP_SendType'] != null) { onFailure(getError(parsed), statusCode); } else if (!isAllowAny) { - await Helpers.logout(); + await AuthenticationViewModel().logout(); Helpers.showErrorToast('Your session expired Please login again'); } if (isAllowAny) { diff --git a/lib/config/config.dart b/lib/config/config.dart index 382e84b2..852e7bab 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -326,9 +326,6 @@ var SERVICES_PATIANT_HEADER_AR = [ "المريض المحول مني", "المريض الواصل" ]; -//****************** - -// Colors ////// by : ibrahim var DEVICE_TOKEN = ""; const PRIMARY_COLOR = 0xff515B5D; diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 77f76abb..6022dceb 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -23,10 +23,13 @@ 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/screens/auth/login_screen.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/transitions/fade_page.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:local_auth/auth_strings.dart'; import 'package:local_auth/local_auth.dart'; @@ -355,10 +358,6 @@ class AuthenticationViewModel extends BaseViewModel { 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); } @@ -369,7 +368,7 @@ class AuthenticationViewModel extends BaseViewModel { } - APP_STATUS get stutas { + APP_STATUS get status { if (state == ViewState.Busy) { return APP_STATUS.LOADING; } else { @@ -383,4 +382,19 @@ class AuthenticationViewModel extends BaseViewModel { } } + + logout() async { + DEVICE_TOKEN = ""; + String lang = await sharedPref.getString(APP_Language); + await Helpers.clearSharedPref(); + sharedPref.setString(APP_Language, lang); + ProjectViewModel().isLogin = false; + Navigator.pushAndRemoveUntil( + AppGlobal.CONTEX, + FadePage( + page: LoginScreen(), + ), + (r) => false); + } + } diff --git a/lib/root_page.dart b/lib/root_page.dart index 5c14288e..35a3fa44 100644 --- a/lib/root_page.dart +++ b/lib/root_page.dart @@ -15,7 +15,7 @@ class RootPage extends StatelessWidget { Widget build(BuildContext context) { AuthenticationViewModel authenticationViewModel = Provider.of(context); Widget buildRoot() { - switch (authenticationViewModel.stutas) { + switch (authenticationViewModel.status) { case APP_STATUS.LOADING: return Scaffold( body: AppLoaderWidget(), diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index eb702d8d..0f8f5183 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -144,20 +144,6 @@ class Helpers { await sharedPref.clear(); } - static logout() async { - DEVICE_TOKEN = ""; - String lang = await sharedPref.getString(APP_Language); - await clearSharedPref(); - sharedPref.setString(APP_Language, lang); - ProjectViewModel().isLogin = false; - Navigator.pushAndRemoveUntil( - AppGlobal.CONTEX, - FadePage( - page: LoginScreen(), - ), - (r) => false); - } - navigateToUpdatePage(String message, String androidLink, iosLink) { Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index a69b1370..db328462 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -172,7 +172,7 @@ class _AppDrawerState extends State { ), onTap: () async { Navigator.pop(context); - await Helpers.logout(); + await AuthenticationViewModel().logout(); projectsProvider.isLogin = false; }, ), From 0d8684481db5c51a7f3165ec7c11171ef2baff80 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 16 May 2021 14:03:21 +0300 Subject: [PATCH 22/28] fix sms error and some design issue --- .../viewModel/authentication_view_model.dart | 30 +++++++++++++++---- .../auth/verification_methods_screen.dart | 16 ++++++++-- lib/widgets/auth/method_type_card.dart | 5 ++-- lib/widgets/auth/sms-popup.dart | 8 +++-- .../auth/verification_methods_list.dart | 1 + 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 6022dceb..d6afa270 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -23,6 +23,7 @@ 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/root_page.dart'; import 'package:doctor_app_flutter/screens/auth/login_screen.dart'; import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; @@ -77,6 +78,7 @@ class AuthenticationViewModel extends BaseViewModel { getDoctorProfile(); } + /// select Device IMEI Future selectDeviceImei(imei) async { setState(ViewState.Busy); await _authService.selectDeviceImei(imei); @@ -87,6 +89,7 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + /// Insert Device IMEI Future insertDeviceImei() async { var loggedIn = await sharedPref.getObj(LOGGED_IN_USER); var user = await sharedPref.getObj(LAST_LOGIN_USER); @@ -125,6 +128,8 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + + /// first step login Future login(UserModel userInfo) async { setState(ViewState.BusyLocal); await _authService.login(userInfo); @@ -141,6 +146,7 @@ class AuthenticationViewModel extends BaseViewModel { } } + /// send activation code for for msg methods Future sendActivationCodeVerificationScreen( AuthMethodTypes authMethodType) async { setState(ViewState.BusyLocal); ActivationCodeForVerificationScreenModel activationCodeModel = @@ -162,6 +168,7 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + /// send activation code for silent login Future sendActivationCodeForDoctorApp({AuthMethodTypes authMethodType, String password }) async { setState(ViewState.BusyLocal); int projectID = await sharedPref.getInt(PROJECT_ID); @@ -180,6 +187,8 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + + /// check activation Future checkActivationCodeForDoctorApp({String activationCode}) async { setState(ViewState.BusyLocal); CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = @@ -204,7 +213,7 @@ class AuthenticationViewModel extends BaseViewModel { } } - + /// get list of Hospitals Future getHospitalsList(memberID) async { GetHospitalsRequestModel getHospitalsRequestModel =GetHospitalsRequestModel(); getHospitalsRequestModel.memberID = memberID; @@ -216,6 +225,8 @@ class AuthenticationViewModel extends BaseViewModel { setState(ViewState.Idle); } + + /// get type name based on id. getType(type, context) { switch (type) { case 1: @@ -242,7 +253,8 @@ class AuthenticationViewModel extends BaseViewModel { } } - setDataAfterSendActivationSuccsess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { + /// add some logic in case of send activation code is success + setDataAfterSendActivationSuccess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); sharedPref.setString(VIDA_AUTH_TOKEN_ID, @@ -257,6 +269,7 @@ class AuthenticationViewModel extends BaseViewModel { sharedPref.setObj(key, value); } + /// ask user to add his biometric showIOSAuthMessages() async { const iosStrings = const IOSAuthMessages( cancelButton: 'cancel', @@ -275,10 +288,12 @@ class AuthenticationViewModel extends BaseViewModel { } } + /// add profile to base view model super class localSetDoctorProfile(DoctorProfileModel profile) { super.setDoctorProfile(profile); } + /// get doctor profile based on clinic model Future getDoctorProfileBasedOnClinic(ClinicModel clinicInfo) async { ProfileReqModel docInfo = new ProfileReqModel( doctorID: clinicInfo.doctorID, @@ -297,6 +312,7 @@ class AuthenticationViewModel extends BaseViewModel { } } + /// add some logic in case of check activation code is success onCheckActivationCodeSuccess() async { sharedPref.setString( TOKEN, @@ -317,6 +333,7 @@ class AuthenticationViewModel extends BaseViewModel { } } + /// check specific biometric if it available or not Future checkIfBiometricAvailable(BiometricType biometricType) async { bool isAvailable = false; await _getAvailableBiometrics(); @@ -328,6 +345,7 @@ class AuthenticationViewModel extends BaseViewModel { return isAvailable; } + /// get all available biometric on the device for local Auth service Future _getAvailableBiometrics() async { try { _availableBiometrics = await auth.getAvailableBiometrics(); @@ -336,7 +354,7 @@ class AuthenticationViewModel extends BaseViewModel { } } - + /// call firebase service to check if the user already login in before or not getDeviceInfoFromFirebase() async { _firebaseMessaging.setAutoInitEnabled(true); if (Platform.isIOS) { @@ -367,7 +385,7 @@ class AuthenticationViewModel extends BaseViewModel { }); } - + /// determine the status of the app APP_STATUS get status { if (state == ViewState.Busy) { return APP_STATUS.LOADING; @@ -382,7 +400,7 @@ class AuthenticationViewModel extends BaseViewModel { } } - + /// logout function logout() async { DEVICE_TOKEN = ""; String lang = await sharedPref.getString(APP_Language); @@ -392,7 +410,7 @@ class AuthenticationViewModel extends BaseViewModel { Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( - page: LoginScreen(), + page: RootPage(), ), (r) => false); } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index afd5604c..1e61d553 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -1,5 +1,6 @@ import 'dart:io' show Platform; +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'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; @@ -20,10 +21,12 @@ import 'package:provider/provider.dart'; import '../../config/size_config.dart'; import '../../landing_page.dart'; +import '../../root_page.dart'; import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../util/helpers.dart'; import '../../widgets/auth/verification_methods_list.dart'; +import 'login_screen.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = Helpers(); @@ -53,6 +56,7 @@ class _VerificationMethodsScreenState extends State { return AppScaffold( isShowAppBar: false, + backgroundColor: Theme.of(context).scaffoldBackgroundColor, // baseViewModel: model, body: SingleChildScrollView( child: Center( @@ -336,7 +340,13 @@ class _VerificationMethodsScreenState extends State { .useAnotherAccount, color: Colors.red[700], onPressed: () { - Navigator.of(context).pushNamed(LOGIN); + projectsProvider.isLogin = true; + Navigator.pushAndRemoveUntil( + AppGlobal.CONTEX, + FadePage( + page: RootPage(), + ), + (r) => false); }, ), @@ -360,7 +370,7 @@ class _VerificationMethodsScreenState extends State { Helpers.showErrorToast(authenticationViewModel.error); GifLoaderDialogUtils.hideDialog(context); } else { - authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeForDoctorAppRes); + authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeForDoctorAppRes); sharedPref.setString(PASSWORD, widget.password); GifLoaderDialogUtils.hideDialog(context); this.startSMSService(authMethodType); @@ -382,7 +392,7 @@ class _VerificationMethodsScreenState extends State { GifLoaderDialogUtils.hideDialog(context); Helpers.showErrorToast(authenticationViewModel.error); } else { - authenticationViewModel.setDataAfterSendActivationSuccsess(authenticationViewModel.activationCodeVerificationScreenRes); + authenticationViewModel.setDataAfterSendActivationSuccess(authenticationViewModel.activationCodeVerificationScreenRes); if (authMethodType == AuthMethodTypes.SMS || authMethodType == AuthMethodTypes.WhatsApp) { GifLoaderDialogUtils.hideDialog(context); diff --git a/lib/widgets/auth/method_type_card.dart b/lib/widgets/auth/method_type_card.dart index 45190d2c..d991020c 100644 --- a/lib/widgets/auth/method_type_card.dart +++ b/lib/widgets/auth/method_type_card.dart @@ -6,11 +6,12 @@ class MethodTypeCard extends StatelessWidget { Key key, this.assetPath, this.onTap, - this.label, + this.label, this.height = 20, }) : super(key: key); final String assetPath; final Function onTap; final String label; + final double height; @override Widget build(BuildContext context) { @@ -38,7 +39,7 @@ class MethodTypeCard extends StatelessWidget { ], ), SizedBox( - height: 20, + height:height , ), AppText( label, diff --git a/lib/widgets/auth/sms-popup.dart b/lib/widgets/auth/sms-popup.dart index cf16a0f1..ed926545 100644 --- a/lib/widgets/auth/sms-popup.dart +++ b/lib/widgets/auth/sms-popup.dart @@ -309,12 +309,14 @@ class SMSOTP { } } - checkValue() { + checkValue() async { if (verifyAccountForm.currentState.validate()) { onSuccess(digit1.text.toString() + digit2.text.toString() + digit3.text.toString() + digit4.text.toString()); + this.isClosed = true; + } } @@ -341,7 +343,9 @@ class SMSOTP { Future.delayed(Duration(seconds: 1), () { if (this.remainingTime > 0) { - if (isClosed == false) startTimer(setState); + if (isClosed == false) { + startTimer(setState); + } } else { Navigator.pop(context); } diff --git a/lib/widgets/auth/verification_methods_list.dart b/lib/widgets/auth/verification_methods_list.dart index de867cde..b6efe748 100644 --- a/lib/widgets/auth/verification_methods_list.dart +++ b/lib/widgets/auth/verification_methods_list.dart @@ -81,6 +81,7 @@ class _VerificationMethodsListState extends State { assetPath: 'assets/images/login/more_icon.png', onTap: widget.onShowMore, label: TranslationBase.of(context).moreVerification, + height: 0, ); } } From a9bd02a908ddb42af134532e8cc433d645c00a34 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Sun, 16 May 2021 16:08:35 +0300 Subject: [PATCH 23/28] first step from user another account --- lib/screens/auth/verification_methods_screen.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 1e61d553..c03d5946 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -341,12 +341,15 @@ class _VerificationMethodsScreenState extends State { color: Colors.red[700], onPressed: () { projectsProvider.isLogin = true; + authenticationViewModel.unverified = false; + authenticationViewModel.isLogin = false; Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( page: RootPage(), ), (r) => false); + // Navigator.of(context).pushNamed(LOGIN); }, ), From 6933b6577f8a0ef88107a36b01fe6a7f6a8421c0 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 17 May 2021 11:54:38 +0300 Subject: [PATCH 24/28] add session time out. --- lib/client/base_app_client.dart | 10 +++++++++- lib/core/viewModel/authentication_view_model.dart | 11 +++++++++-- lib/screens/auth/verification_methods_screen.dart | 2 ++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index d79f0338..3aac5e92 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -22,6 +22,8 @@ class BaseAppClient { Function(String error, int statusCode) onFailure, bool isAllowAny = false}) async { String url = BASE_URL + endPoint; + + bool callLog= true; try { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); String token = await sharedPref.getString(TOKEN); @@ -88,6 +90,12 @@ class BaseAppClient { if (statusCode < 200 || statusCode >= 400) { onFailure(Helpers.generateContactAdminMsg(), statusCode); } else { + if(callLog){ + callLog = false; + await AuthenticationViewModel().logout(isSessionTimeout: true); + + } + var parsed = json.decode(response.body.toString()); if (parsed['ErrorType'] == 4) { helpers.navigateToUpdatePage(parsed['ErrorEndUserMessage'], @@ -98,7 +106,7 @@ class BaseAppClient { if (body['OTP_SendType'] != null) { onFailure(getError(parsed), statusCode); } else if (!isAllowAny) { - await AuthenticationViewModel().logout(); + await AuthenticationViewModel().logout(isSessionTimeout: true); Helpers.showErrorToast('Your session expired Please login again'); } if (isAllowAny) { diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index d6afa270..3b8cf02f 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -74,7 +74,7 @@ class AuthenticationViewModel extends BaseViewModel { bool unverified = false; AuthenticationViewModel({bool checkDeviceInfo = false}) { - getDeviceInfoFromFirebase(); + getDeviceInfoFromFirebase(); getDoctorProfile(); } @@ -401,12 +401,14 @@ class AuthenticationViewModel extends BaseViewModel { } /// logout function - logout() async { + logout({bool isSessionTimeout = false}) async { DEVICE_TOKEN = ""; String lang = await sharedPref.getString(APP_Language); await Helpers.clearSharedPref(); sharedPref.setString(APP_Language, lang); ProjectViewModel().isLogin = false; + if(isSessionTimeout) + await getDeviceInfoFromFirebase(); Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( @@ -415,4 +417,9 @@ class AuthenticationViewModel extends BaseViewModel { (r) => false); } + deleteUser(){ + user = null; + notifyListeners(); + } + } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index c03d5946..5aa626be 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -343,6 +343,8 @@ class _VerificationMethodsScreenState extends State { projectsProvider.isLogin = true; authenticationViewModel.unverified = false; authenticationViewModel.isLogin = false; + authenticationViewModel.deleteUser(); + Navigator.pushAndRemoveUntil( AppGlobal.CONTEX, FadePage( From 1187c3b605b7fc61af7abe7b931ca780a8458d54 Mon Sep 17 00:00:00 2001 From: Mohammad Aljammal Date: Mon, 17 May 2021 12:28:21 +0300 Subject: [PATCH 25/28] fix authentication provider --- ios/Podfile.lock | 2 +- lib/client/base_app_client.dart | 9 +---- .../viewModel/authentication_view_model.dart | 38 +++++++++---------- lib/widgets/shared/app_drawer_widget.dart | 2 +- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2f4607e0..878a1850 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -322,4 +322,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 -COCOAPODS: 1.10.0.rc.1 +COCOAPODS: 1.10.1 diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart index 3aac5e92..68a84820 100644 --- a/lib/client/base_app_client.dart +++ b/lib/client/base_app_client.dart @@ -10,6 +10,7 @@ import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart'; import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; +import 'package:provider/provider.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); Helpers helpers = new Helpers(); @@ -90,12 +91,6 @@ class BaseAppClient { if (statusCode < 200 || statusCode >= 400) { onFailure(Helpers.generateContactAdminMsg(), statusCode); } else { - if(callLog){ - callLog = false; - await AuthenticationViewModel().logout(isSessionTimeout: true); - - } - var parsed = json.decode(response.body.toString()); if (parsed['ErrorType'] == 4) { helpers.navigateToUpdatePage(parsed['ErrorEndUserMessage'], @@ -106,7 +101,7 @@ class BaseAppClient { if (body['OTP_SendType'] != null) { onFailure(getError(parsed), statusCode); } else if (!isAllowAny) { - await AuthenticationViewModel().logout(isSessionTimeout: true); + await Provider.of(AppGlobal.CONTEX, listen: false).logout(isSessionTimeout: true); Helpers.showErrorToast('Your session expired Please login again'); } if (isAllowAny) { diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 3b8cf02f..8e9c3541 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -361,28 +361,26 @@ class AuthenticationViewModel extends BaseViewModel { _firebaseMessaging.requestNotificationPermissions(); } setState(ViewState.Busy); - - _firebaseMessaging.getToken().then((String token) async { - if (DEVICE_TOKEN == "" && !ProjectViewModel().isLogin) { - 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; - } - setState(ViewState.Idle); - } + var token = await _firebaseMessaging.getToken(); + if (DEVICE_TOKEN == "" && !ProjectViewModel().isLogin) { + 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; + } setState(ViewState.Idle); } - }); + } else { + setState(ViewState.Idle); + } } /// determine the status of the app @@ -407,6 +405,7 @@ class AuthenticationViewModel extends BaseViewModel { await Helpers.clearSharedPref(); sharedPref.setString(APP_Language, lang); ProjectViewModel().isLogin = false; + deleteUser(); if(isSessionTimeout) await getDeviceInfoFromFirebase(); Navigator.pushAndRemoveUntil( @@ -419,6 +418,7 @@ class AuthenticationViewModel extends BaseViewModel { deleteUser(){ user = null; + unverified = false; notifyListeners(); } diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index db328462..ee7f0276 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -172,7 +172,7 @@ class _AppDrawerState extends State { ), onTap: () async { Navigator.pop(context); - await AuthenticationViewModel().logout(); + await authenticationViewModel.logout(); projectsProvider.isLogin = false; }, ), From 515955663af98f14ca49dca8763406f459cb9d86 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 17 May 2021 16:26:37 +0300 Subject: [PATCH 26/28] add verification --- lib/config/localized_values.dart | 9 +- .../viewModel/authentication_view_model.dart | 10 +- lib/core/viewModel/project_view_model.dart | 1 - lib/screens/auth/login_screen.dart | 56 +++-- .../auth/verification_methods_screen.dart | 237 +++++++++++------- lib/util/translations_delegate_base.dart | 2 + lib/widgets/auth/method_type_card.dart | 12 +- .../auth/verification_methods_list.dart | 16 +- lib/widgets/shared/app_drawer_widget.dart | 1 - 9 files changed, 211 insertions(+), 133 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index d09d33f4..16be8d8e 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -576,10 +576,11 @@ const Map> localizedValues = { "ar": "الرجاء اختيار احدى الخيارات التالية للتحقق من البيانات" }, "register-user": {"en": "Register", "ar": "تسجيل"}, - "verify-with-fingerprint": {"en": "Verify through Fingerprint", "ar": "بصمة"}, - "verify-with-faceid": {"en": "Verify through Face ID", "ar": "معرف الوجه"}, - "verify-with-sms": {"en": "Verify through SMS", "ar": "الرسائل القصيرة"}, - "verify-with-whatsapp": {"en": "Verify through WhatsApp", "ar": " الواتس اب"}, + "verify-with-fingerprint": {"en": "Fingerprint", "ar": "بصمة"}, + "verify-with-faceid": {"en": "Face ID", "ar": "معرف الوجه"}, + "verify-with-sms": {"en": " SMS", "ar": "الرسائل القصيرة"}, + "verify-with-whatsapp": {"en": "WhatsApp", "ar": " الواتس اب"}, + "verify-with": {"en": "Verify through ", "ar": " الواتس اب"}, "last-login": { "en": "Last login details:", "ar": "تفاصيل تسجيل الدخول الأخير:" diff --git a/lib/core/viewModel/authentication_view_model.dart b/lib/core/viewModel/authentication_view_model.dart index 8e9c3541..223b303b 100644 --- a/lib/core/viewModel/authentication_view_model.dart +++ b/lib/core/viewModel/authentication_view_model.dart @@ -188,7 +188,7 @@ class AuthenticationViewModel extends BaseViewModel { } - /// check activation + /// check activation code for sms and whats app Future checkActivationCodeForDoctorApp({String activationCode}) async { setState(ViewState.BusyLocal); CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = @@ -253,7 +253,7 @@ class AuthenticationViewModel extends BaseViewModel { } } - /// add some logic in case of send activation code is success + /// add  token to shared preferences in case of send activation code is success setDataAfterSendActivationSuccess(SendActivationCodeForDoctorAppResponseModel sendActivationCodeForDoctorAppResponseModel) { print("VerificationCode : " + sendActivationCodeForDoctorAppResponseModel.verificationCode); @@ -362,7 +362,7 @@ class AuthenticationViewModel extends BaseViewModel { } setState(ViewState.Busy); var token = await _firebaseMessaging.getToken(); - if (DEVICE_TOKEN == "" && !ProjectViewModel().isLogin) { + if (DEVICE_TOKEN == "") { DEVICE_TOKEN = token; await _authService.selectDeviceImei(DEVICE_TOKEN); @@ -404,7 +404,6 @@ class AuthenticationViewModel extends BaseViewModel { String lang = await sharedPref.getString(APP_Language); await Helpers.clearSharedPref(); sharedPref.setString(APP_Language, lang); - ProjectViewModel().isLogin = false; deleteUser(); if(isSessionTimeout) await getDeviceInfoFromFirebase(); @@ -419,7 +418,8 @@ class AuthenticationViewModel extends BaseViewModel { deleteUser(){ user = null; unverified = false; - notifyListeners(); + isLogin = false; + notifyListeners(); } } diff --git a/lib/core/viewModel/project_view_model.dart b/lib/core/viewModel/project_view_model.dart index 494e3b10..f464df0e 100644 --- a/lib/core/viewModel/project_view_model.dart +++ b/lib/core/viewModel/project_view_model.dart @@ -24,7 +24,6 @@ class ProjectViewModel with ChangeNotifier { List doctorClinicsList = []; bool isLoading = false; bool isError = false; - bool isLogin = false; String error = ''; BaseAppClient baseAppClient = BaseAppClient(); diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 7fbf47af..b8d5cca3 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -401,30 +401,6 @@ class _LoginScreenState extends State { ])), ]), ), - 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); - }, - )), - ], - ) ], ), ) @@ -433,6 +409,38 @@ class _LoginScreenState extends State { ])) ]), ), + bottomSheet: Container( + + height: 90, + width: double.infinity, + child: Center( + child: FractionallySizedBox( + widthFactor: 0.9, + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + AppButton( + title: TranslationBase + .of(context) + .login, + color: Color(0xFFD02127), + disabled: authenticationViewModel.userInfo + .userID == null || + authenticationViewModel.userInfo + .password == + null, + fontWeight: FontWeight + .bold, + onPressed: () { + login(context); + }, + ), + + SizedBox(height: 25,) + ], + ), + ), + ),), ); } diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 5aa626be..35d8366d 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -67,13 +67,24 @@ class _VerificationMethodsScreenState extends State { width: SizeConfig.realScreenWidth, child: Column( crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, + // mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + SizedBox( + height: 80, + ), + InkWell( + onTap: (){ + Navigator.of(context).pop(); + }, + child: Icon(Icons.arrow_back_ios,color: Color(0xFF2B353E),) + + ), Container( + child: Column( children: [ SizedBox( - height: 100, + height: 20, ), authenticationViewModel.user != null && isMoreOption == false ? Column( @@ -81,92 +92,144 @@ class _VerificationMethodsScreenState extends State { MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.start, children: [ + AppText( - TranslationBase.of(context).welcomeBack), + TranslationBase.of(context).welcomeBack, + fontSize:12, + fontWeight: FontWeight.w700, + color: Color(0xFF2B353E), + ), AppText( Helpers.capitalize(authenticationViewModel.user.doctorName), - fontSize: SizeConfig.textMultiplier * 3.5, + fontSize: 24, + color: Color(0xFF2B353E), fontWeight: FontWeight.bold, ), SizedBox( height: 20, ), AppText( - TranslationBase.of(context).accountInfo, - fontSize: SizeConfig.textMultiplier * 2.5, + TranslationBase.of(context).accountInfo , + fontSize: 16, + color: Color(0xFF2E303A), fontWeight: FontWeight.w600, ), SizedBox( height: 20, ), - Card( + Container( + padding: EdgeInsets.all(15), + decoration: BoxDecoration( 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, - ), - )) + borderRadius: BorderRadius.all( + Radius.circular(10), + ), + border: Border.all( + color: HexColor('#707070'), + width: 0.1), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + children: [ + + Text( + TranslationBase.of(context) + .lastLoginAt, + overflow: + TextOverflow.ellipsis, + style: TextStyle( + fontFamily: 'Poppins', + fontSize: 16, + color: Color(0xFF2E303A), + fontWeight: FontWeight.w700,), + + ), + Row( + children: [ + AppText( + TranslationBase + .of(context) + .verifyWith, + fontSize: 14, + color: Color(0xFF575757), + fontWeight: FontWeight.w600, + ), + AppText( + authenticationViewModel.getType( + authenticationViewModel.user + .logInTypeID, + context), + fontSize: 14, + color: Color(0xFF2B353E), + + fontWeight: FontWeight.w700, + ), + ], + ) + ], + crossAxisAlignment: CrossAxisAlignment.start,), + Column(children: [ + 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: 13, + color: Color(0xFF2E303A), + fontWeight: FontWeight.w700, + ), + 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, + fontWeight: FontWeight.w600, + color: Color(0xFF575757), + ) ], - )), + crossAxisAlignment: CrossAxisAlignment.start, + + ) + ], + ), + ), + SizedBox( + height: 20, + ), + Row( + children: [ + AppText( + "Please Verify", + fontSize: 16, + color: Color(0xFF2B353E), + + fontWeight: FontWeight.w700, + ), + ], + ) ], ) : Column( @@ -175,13 +238,17 @@ class _VerificationMethodsScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ this.onlySMSBox == false - ? AppText( + ? Container( + margin: EdgeInsets.only(bottom: 20, top: 30), + child: AppText( TranslationBase.of(context) - .verifyLoginWith, - fontSize: - SizeConfig.textMultiplier * 3.5, + .verifyLoginWith, + fontSize: 18, + color: Color(0xFF2E303A), + fontWeight: FontWeight.bold, textAlign: TextAlign.left, - ) + ), + ) : AppText( TranslationBase.of(context) .verifyFingerprint2, @@ -317,15 +384,6 @@ class _VerificationMethodsScreenState extends State { ), ), 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( @@ -338,11 +396,8 @@ class _VerificationMethodsScreenState extends State { title: TranslationBase .of(context) .useAnotherAccount, - color: Colors.red[700], + color: Color(0xFFD02127), onPressed: () { - projectsProvider.isLogin = true; - authenticationViewModel.unverified = false; - authenticationViewModel.isLogin = false; authenticationViewModel.deleteUser(); Navigator.pushAndRemoveUntil( @@ -499,8 +554,6 @@ class _VerificationMethodsScreenState extends State { if (authenticationViewModel.state == ViewState.ErrorLocal) { Helpers.showErrorToast(authenticationViewModel.error); } else { - projectsProvider.isLogin = true; - Navigator.pushAndRemoveUntil( context, FadePage( diff --git a/lib/util/translations_delegate_base.dart b/lib/util/translations_delegate_base.dart index ba69e104..77230e2a 100644 --- a/lib/util/translations_delegate_base.dart +++ b/lib/util/translations_delegate_base.dart @@ -940,6 +940,8 @@ class TranslationBase { String get verifySMS => localizedValues['verify-with-sms'][locale.languageCode]; + String get verifyWith => + localizedValues['verify-with'][locale.languageCode]; String get verifyWhatsApp => localizedValues['verify-with-whatsapp'][locale.languageCode]; diff --git a/lib/widgets/auth/method_type_card.dart b/lib/widgets/auth/method_type_card.dart index d991020c..6d091756 100644 --- a/lib/widgets/auth/method_type_card.dart +++ b/lib/widgets/auth/method_type_card.dart @@ -1,5 +1,6 @@ import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/material.dart'; +import 'package:hexcolor/hexcolor.dart'; class MethodTypeCard extends StatelessWidget { const MethodTypeCard({ @@ -20,9 +21,15 @@ class MethodTypeCard extends StatelessWidget { child: Container( margin: EdgeInsets.all(10), decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), color: Colors.white, + borderRadius: BorderRadius.all( + Radius.circular(10), + ), + border: Border.all( + color: HexColor('#707070'), + width: 0.1), ), + height: 170, child: Padding( padding: EdgeInsets.fromLTRB(20, 15, 20, 15), child: Column( @@ -44,7 +51,8 @@ class MethodTypeCard extends StatelessWidget { AppText( label, fontSize: 14, - fontWeight: FontWeight.w600, + color: Color(0xFF2E303A), + fontWeight: FontWeight.bold, ) ], ), diff --git a/lib/widgets/auth/verification_methods_list.dart b/lib/widgets/auth/verification_methods_list.dart index b6efe748..27dbe8bf 100644 --- a/lib/widgets/auth/verification_methods_list.dart +++ b/lib/widgets/auth/verification_methods_list.dart @@ -40,14 +40,18 @@ class _VerificationMethodsListState extends State { assetPath: 'assets/images/verify-whtsapp.png', onTap: () => {widget.authenticateUser(AuthMethodTypes.WhatsApp, true)}, - label: TranslationBase.of(context).verifyWhatsApp, + label: TranslationBase + .of(context) + .verifyWith+ TranslationBase.of(context).verifyWhatsApp, ); break; case AuthMethodTypes.SMS: return MethodTypeCard( assetPath: "assets/images/verify-sms.png", onTap: () => {widget.authenticateUser(AuthMethodTypes.SMS, true)}, - label: TranslationBase.of(context).verifySMS, + label:TranslationBase + .of(context) + .verifyWith+ TranslationBase.of(context).verifySMS, ); break; case AuthMethodTypes.Fingerprint: @@ -60,7 +64,9 @@ class _VerificationMethodsListState extends State { widget.authenticateUser(AuthMethodTypes.Fingerprint, true); } }, - label: TranslationBase.of(context).verifyFingerprint, + label: TranslationBase + .of(context) + .verifyWith+TranslationBase.of(context).verifyFingerprint, ); break; case AuthMethodTypes.FaceID: @@ -72,7 +78,9 @@ class _VerificationMethodsListState extends State { widget.authenticateUser(AuthMethodTypes.FaceID, true); } }, - label: TranslationBase.of(context).verifyFaceID, + label: TranslationBase + .of(context) + .verifyWith+TranslationBase.of(context).verifyFaceID, ); break; diff --git a/lib/widgets/shared/app_drawer_widget.dart b/lib/widgets/shared/app_drawer_widget.dart index ee7f0276..e350e39d 100644 --- a/lib/widgets/shared/app_drawer_widget.dart +++ b/lib/widgets/shared/app_drawer_widget.dart @@ -173,7 +173,6 @@ class _AppDrawerState extends State { onTap: () async { Navigator.pop(context); await authenticationViewModel.logout(); - projectsProvider.isLogin = false; }, ), ], From 14a3ca86954c5dcc40f03f38c5fb4b856c2ac769 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 17 May 2021 17:22:50 +0300 Subject: [PATCH 27/28] fix login screen design --- lib/screens/auth/login_screen.dart | 339 ++++-------------- .../auth/verification_methods_screen.dart | 2 +- lib/util/helpers.dart | 2 +- .../text_fields/app-textfield-custom.dart | 3 + 4 files changed, 74 insertions(+), 272 deletions(-) diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index b8d5cca3..84517932 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -8,6 +8,7 @@ import 'package:doctor_app_flutter/util/translations_delegate_base.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-textfield-custom.dart'; import 'package:doctor_app_flutter/widgets/shared/text_fields/app_text_form_field.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -23,10 +24,13 @@ class LoginScreen extends StatefulWidget { class _LoginScreenState extends State { String platformImei; + bool allowCallApi = true; //TODO change AppTextFormField to AppTextFormFieldCustom final loginFormKey = GlobalKey(); var projectIdController = TextEditingController(); + var userIdController = TextEditingController(); + var passwordController = TextEditingController(); List projectsList = []; FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); @@ -86,8 +90,9 @@ class _LoginScreenState extends State { .of(context) .drSulaimanAlHabib, style: TextStyle( + color:Color(0xFF2B353E), fontWeight: FontWeight - .w800, + .bold, fontSize: SizeConfig .isMobile ? 24 @@ -107,9 +112,8 @@ class _LoginScreenState extends State { .realScreenWidth * 0.030, fontWeight: FontWeight - .w800, - color: HexColor( - '#B8382C')), + .w600, + color: Color(0xFFD02127)), ), ]), ], @@ -132,273 +136,69 @@ class _LoginScreenState extends State { 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(() { - 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) - .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); - }, - ) - ])), + AppTextFieldCustom( + hintText: TranslationBase.of(context).enterId, + hasBorder: true, + controller: userIdController, + onChanged: (value){ + if (value != null) + setState(() { + authenticationViewModel.userInfo + .userID = + value + .trim(); + }); + }, + ), + buildSizedBox(), + AppTextFieldCustom( + hintText: TranslationBase.of(context).enterPassword, + hasBorder: true, + isSecure: true, + controller: passwordController, + onChanged: (value){ + if (value != null) + setState(() { + authenticationViewModel.userInfo + .password = + value + .trim(); + }); + if(allowCallApi) { + this.getProjects( + authenticationViewModel.userInfo + .userID); + setState(() { + allowCallApi = false; + }); + } + }, + onClick: (){ + + }, + ), 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), - ), - ) - ])), + AppTextFieldCustom( + hintText: TranslationBase.of(context).selectYourProject, + hasBorder: true, + controller: projectIdController, + isTextFieldHasSuffix: true, + enabled: false, + onClick: (){ + Helpers + .showCupertinoPicker( + context, + projectsList, + 'facilityName', + onSelectProject, + authenticationViewModel); + }, + + + ), + buildSizedBox() ]), ), ], @@ -424,13 +224,12 @@ class _LoginScreenState extends State { .of(context) .login, color: Color(0xFFD02127), + fontWeight: FontWeight.w700, disabled: authenticationViewModel.userInfo .userID == null || authenticationViewModel.userInfo .password == null, - fontWeight: FontWeight - .bold, onPressed: () { login(context); }, diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 35d8366d..4edb0f44 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -396,7 +396,7 @@ class _VerificationMethodsScreenState extends State { title: TranslationBase .of(context) .useAnotherAccount, - color: Color(0xFFD02127), + color: Color(0xFFD02127),fontWeight: FontWeight.w700, onPressed: () { authenticationViewModel.deleteUser(); diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 0f8f5183..53f81ef2 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -55,7 +55,7 @@ class Helpers { ), onPressed: () { Navigator.pop(context); - onSelectFun(cupertinoPickerIndex, model); + onSelectFun(cupertinoPickerIndex); }, ) ], diff --git a/lib/widgets/shared/text_fields/app-textfield-custom.dart b/lib/widgets/shared/text_fields/app-textfield-custom.dart index ded2568d..7e13f411 100644 --- a/lib/widgets/shared/text_fields/app-textfield-custom.dart +++ b/lib/widgets/shared/text_fields/app-textfield-custom.dart @@ -26,6 +26,7 @@ class AppTextFieldCustom extends StatefulWidget { final Function(String) onChanged; final String validationError; final bool isPrscription; + final bool isSecure; AppTextFieldCustom({ this.height = 0, @@ -45,6 +46,7 @@ class AppTextFieldCustom extends StatefulWidget { this.onChanged, this.validationError, this.isPrscription = false, + this.isSecure = false, }); @override @@ -132,6 +134,7 @@ class _AppTextFieldCustomState extends State { widget.onChanged(value); } }, + obscureText: widget.isSecure ), ) : AppText( From 164a7fd2fc2d80118d6ea91daaace35600addb12 Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Mon, 17 May 2021 17:49:02 +0300 Subject: [PATCH 28/28] fix merge issues --- ios/Podfile.lock | 2 +- lib/core/viewModel/dashboard_view_model.dart | 25 ++++++++----------- lib/locator.dart | 8 ------ .../auth/verification_methods_screen.dart | 16 ++++++------ lib/screens/home/home_screen.dart | 7 +++--- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 878a1850..2f4607e0 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -322,4 +322,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 649616dc336b3659ac6b2b25159d8e488e042b69 -COCOAPODS: 1.10.1 +COCOAPODS: 1.10.0.rc.1 diff --git a/lib/core/viewModel/dashboard_view_model.dart b/lib/core/viewModel/dashboard_view_model.dart index 7d458fc7..f37a8feb 100644 --- a/lib/core/viewModel/dashboard_view_model.dart +++ b/lib/core/viewModel/dashboard_view_model.dart @@ -1,12 +1,14 @@ 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/viewstate.dart'; -import 'package:doctor_app_flutter/core/service/home/dasboard_service.dart';import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart'; +import 'package:doctor_app_flutter/core/service/home/dasboard_service.dart'; import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; +import 'package:doctor_app_flutter/models/doctor/clinic_model.dart'; import 'package:doctor_app_flutter/models/doctor/profile_req_Model.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import '../../locator.dart'; +import 'authentication_view_model.dart'; import 'base_view_model.dart'; class DashboardViewModel extends BaseViewModel { @@ -17,7 +19,7 @@ class DashboardViewModel extends BaseViewModel { List get dashboardItemsList => _dashboardService.dashboardItemsList; - Future setFirebaseNotification(ProjectViewModel projectsProvider, AuthViewModel authProvider) async{ + Future setFirebaseNotification(ProjectViewModel projectsProvider, AuthenticationViewModel authProvider) async{ setState(ViewState.Busy); await projectsProvider.getDoctorClinicsList(); @@ -33,9 +35,7 @@ class DashboardViewModel extends BaseViewModel { _firebaseMessaging.getToken().then((String token) async { if (token != '') { DEVICE_TOKEN = token; - var request = await sharedPref.getObj(DOCTOR_PROFILE); - authProvider.insertDeviceImei(request).then((value) { - }); + authProvider.insertDeviceImei(); } }); } @@ -50,7 +50,7 @@ class DashboardViewModel extends BaseViewModel { setState(ViewState.Idle); } - Future changeClinic(int clinicId, AuthViewModel authProvider) async { + Future changeClinic(int clinicId, AuthenticationViewModel authProvider) async { setState(ViewState.BusyLocal); await getDoctorProfile(); ProfileReqModel docInfo = new ProfileReqModel( @@ -60,14 +60,11 @@ class DashboardViewModel extends BaseViewModel { projectID: doctorProfile.projectID, tokenID: '', languageID: 2); - - await authProvider.getDocProfiles(docInfo.toJson()).then((res) async { - sharedPref.setObj(DOCTOR_PROFILE, res['DoctorProfileList'][0]); - setState(ViewState.Idle); - }).catchError((err) { - error = err; - setState(ViewState.ErrorLocal); - }); + ClinicModel clinicModel = ClinicModel(doctorID:doctorProfile.doctorID,clinicID: doctorProfile.clinicID, projectID: doctorProfile.projectID,); + await authProvider.getDoctorProfileBasedOnClinic(clinicModel); + if(authProvider.state == ViewState.ErrorLocal) { + error = authProvider.error; + } } getPatientCount(DashboardModel inPatientCount) { diff --git a/lib/locator.dart b/lib/locator.dart index a2c77373..4cb18514 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -1,13 +1,6 @@ import 'package:doctor_app_flutter/core/service/authentication_service.dart'; -import 'package:doctor_app_flutter/core/service/dasboard_service.dart'; -import 'package:doctor_app_flutter/core/service/medical_file_service.dart'; -import 'package:doctor_app_flutter/core/service/patient_service.dart'; -import 'package:doctor_app_flutter/core/service/prescription_service.dart'; -import 'package:doctor_app_flutter/core/service/procedure_service.dart'; -import 'package:doctor_app_flutter/core/service/sickleave_service.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/hospitals_view_model.dart'; -import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/medical_file_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; @@ -15,7 +8,6 @@ import 'package:doctor_app_flutter/core/viewModel/procedure_View_model.dart'; import 'package:doctor_app_flutter/core/viewModel/sick_leave_view_model.dart'; import 'package:get_it/get_it.dart'; -import 'core/service/home/auth_service.dart'; import 'core/service/home/dasboard_service.dart'; import 'core/service/patient/DischargedPatientService.dart'; import 'core/service/patient/patient_service.dart'; diff --git a/lib/screens/auth/verification_methods_screen.dart b/lib/screens/auth/verification_methods_screen.dart index 4edb0f44..0ec7f5ee 100644 --- a/lib/screens/auth/verification_methods_screen.dart +++ b/lib/screens/auth/verification_methods_screen.dart @@ -174,14 +174,14 @@ class _VerificationMethodsScreenState extends State { AppText( authenticationViewModel.user.editedOn != null - ? DateUtils.getDayMonthYearDateFormatted( - DateUtils.convertStringToDate( + ? AppDateUtils.getDayMonthYearDateFormatted( + AppDateUtils.convertStringToDate( authenticationViewModel.user .editedOn)) : authenticationViewModel.user.createdOn != null - ? DateUtils.getDayMonthYearDateFormatted( - DateUtils.convertStringToDate(authenticationViewModel.user + ? AppDateUtils.getDayMonthYearDateFormatted( + AppDateUtils.convertStringToDate(authenticationViewModel.user .createdOn)) : '--', textAlign: @@ -193,14 +193,14 @@ class _VerificationMethodsScreenState extends State { AppText( authenticationViewModel.user.editedOn != null - ? DateUtils.getHour( - DateUtils.convertStringToDate( + ? AppDateUtils.getHour( + AppDateUtils.convertStringToDate( authenticationViewModel.user .editedOn)) : authenticationViewModel.user.createdOn != null - ? DateUtils.getHour( - DateUtils.convertStringToDate(authenticationViewModel.user + ? AppDateUtils.getHour( + AppDateUtils.convertStringToDate(authenticationViewModel.user .createdOn)) : '--', textAlign: diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart index b7125e21..2827a421 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/home_screen.dart @@ -44,7 +44,6 @@ class HomeScreen extends StatefulWidget { } class _HomeScreenState extends State { - final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); bool isLoading = false; ProjectViewModel projectsProvider; var _isInit = true; @@ -53,11 +52,11 @@ class _HomeScreenState extends State { bool isInpatient = false; int sliderActiveIndex = 0; var clinicId; + AuthenticationViewModel authenticationViewModel; @override Widget build(BuildContext context) { ProjectViewModel projectsProvider = Provider.of(context); - AuthViewModel authProvider = Provider.of(context); authenticationViewModel = Provider.of(context); FocusScopeNode currentFocus = FocusScope.of(context); @@ -67,7 +66,7 @@ class _HomeScreenState extends State { return BaseView( onModelReady: (model) async { - await model.setFirebaseNotification(projectsProvider, authProvider); + await model.setFirebaseNotification(projectsProvider, authenticationViewModel); await model.getDashboard(); }, builder: (_, model, w) => AppScaffold( @@ -178,7 +177,7 @@ class _HomeScreenState extends State { GifLoaderDialogUtils.showMyDialog( context); await model.changeClinic( - newValue, authProvider); + newValue, authenticationViewModel); GifLoaderDialogUtils.hideDialog( context); if (model.state ==