From fda75c721dfc845ed6845fb478ce16a67caa5f56 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Mon, 19 Apr 2021 15:25:14 +0300 Subject: [PATCH] bug fixes --- lib/core/service/auth_service.dart | 36 +++- lib/core/viewModel/auth_view_model.dart | 15 +- lib/core/viewModel/imei_view_model.dart | 14 +- lib/landing_page.dart | 3 +- lib/locator.dart | 1 - lib/screens/auth/login_screen.dart | 2 +- lib/widgets/auth/login_form.dart | 233 ++------------------- lib/widgets/auth/verfiy_account.dart | 86 -------- lib/widgets/auth/verification_methods.dart | 43 +--- 9 files changed, 82 insertions(+), 351 deletions(-) diff --git a/lib/core/service/auth_service.dart b/lib/core/service/auth_service.dart index e116ccdd..f009fded 100644 --- a/lib/core/service/auth_service.dart +++ b/lib/core/service/auth_service.dart @@ -2,11 +2,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/service/base/base_service.dart'; import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart'; +import 'package:doctor_app_flutter/models/doctor/user_model.dart'; class AuthService extends BaseService { List _imeiDetails = []; List get dashboardItemsList => _imeiDetails; - + Map _loginInfo = {}; + Map get loginInfo => _loginInfo; Future selectDeviceImei(imei) async { try { // dynamic localRes; @@ -26,4 +28,36 @@ class AuthService extends BaseService { super.error = error; } } + + Future login(UserModel userInfo) async { + hasError = false; + _loginInfo = {}; + try { + await baseAppClient.post(LOGIN_URL, + onSuccess: (dynamic response, int statusCode) { + _loginInfo = response; + }, onFailure: (String error, int statusCode) { + hasError = true; + super.error = error; + }, body: userInfo.toJson()); + } catch (error) { + hasError = true; + 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/viewModel/auth_view_model.dart b/lib/core/viewModel/auth_view_model.dart index 87b89123..dd684673 100644 --- a/lib/core/viewModel/auth_view_model.dart +++ b/lib/core/viewModel/auth_view_model.dart @@ -195,26 +195,19 @@ class AuthViewModel extends BaseViewModel { } } - /* - *@author: Elham Rababah - *@Date:17/5/2020 - *@param: docInfo - *@return:Future - *@desc: getDocProfiles - */ - Future getDocProfiles(docInfo, {bool allowChangeProfile = true}) async { + 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) { + if (allowChangeProfile) { doctorProfile = DoctorProfileModel.fromJson(response['DoctorProfileList'][0]); selectedClinicName = - response['DoctorProfileList'][0]['ClinicDescription']; + response['DoctorProfileList'][0]['ClinicDescription']; } - }, onFailure: (String error, int statusCode) { throw error; }, body: docInfo); diff --git a/lib/core/viewModel/imei_view_model.dart b/lib/core/viewModel/imei_view_model.dart index 29253b1d..16798af5 100644 --- a/lib/core/viewModel/imei_view_model.dart +++ b/lib/core/viewModel/imei_view_model.dart @@ -4,11 +4,12 @@ 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/viewModel/base_view_model.dart'; import 'package:doctor_app_flutter/locator.dart'; +import 'package:doctor_app_flutter/models/doctor/user_model.dart'; class IMEIViewModel extends BaseViewModel { AuthService _authService = locator(); List get imeiDetails => _authService.dashboardItemsList; - + get loginInfo => _authService.loginInfo; Future selectDeviceImei(imei) async { setState(ViewState.Busy); await _authService.selectDeviceImei(imei); @@ -18,4 +19,15 @@ class IMEIViewModel extends BaseViewModel { } else setState(ViewState.Idle); } + + Future login(UserModel userInfo) async { + setState(ViewState.Busy); + await _authService.login(userInfo); + if (_authService.hasError) { + error = _authService.error; + helpers.showErrorToast(error); + setState(ViewState.ErrorLocal); + } else + setState(ViewState.Idle); + } } diff --git a/lib/landing_page.dart b/lib/landing_page.dart index 15975f95..53da4477 100644 --- a/lib/landing_page.dart +++ b/lib/landing_page.dart @@ -51,7 +51,8 @@ class _LandingPageState extends State { leading: Builder( builder: (BuildContext context) { return IconButton( - icon: Icon(DoctorApp.drawer_icon), + icon: Image.asset('assets/images/menu.png', + height: 50, width: 50), iconSize: 15, color: Colors.black, onPressed: () => Scaffold.of(context).openDrawer(), diff --git a/lib/locator.dart b/lib/locator.dart index 1e688d96..d64a8ed3 100644 --- a/lib/locator.dart +++ b/lib/locator.dart @@ -5,7 +5,6 @@ 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/auth_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/dashboard_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'; diff --git a/lib/screens/auth/login_screen.dart b/lib/screens/auth/login_screen.dart index 465ef71e..41941831 100644 --- a/lib/screens/auth/login_screen.dart +++ b/lib/screens/auth/login_screen.dart @@ -122,7 +122,7 @@ class _LoginsreenState extends State { height: 40, ), LoginForm( - changeLoadingStata: changeLoadingStata, + model: model, ), ], ) diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index 9fc50008..ef129e4a 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -1,7 +1,7 @@ -import 'package:doctor_app_flutter/lookups/hospital_lookup.dart'; +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/widgets/shared/app_button.dart'; -import 'package:doctor_app_flutter/widgets/shared/app_loader_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_text_form_field.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; import 'package:flutter/cupertino.dart'; @@ -9,15 +9,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:hexcolor/hexcolor.dart'; -import 'package:imei_plugin/imei_plugin.dart'; import 'package:provider/provider.dart'; - import '../../config/shared_pref_kay.dart'; import '../../config/size_config.dart'; import '../../models/doctor/user_model.dart'; -import '../../core/viewModel/auth_view_model.dart'; import '../../core/viewModel/hospital_view_model.dart'; -import '../../routes.dart'; import '../../util/dr_app_shared_pref.dart'; import '../../util/dr_app_toast_msg.dart'; import '../../util/helpers.dart'; @@ -28,35 +24,22 @@ DrAppToastMsg toastMsg = DrAppToastMsg(); Helpers helpers = Helpers(); class LoginForm extends StatefulWidget with DrAppToastMsg { - LoginForm({this.changeLoadingStata}); + LoginForm({this.model}); - final Function changeLoadingStata; + final IMEIViewModel model; @override _LoginFormState createState() => _LoginFormState(); } -//TODO recreate the all page and apply the MVVM here + class _LoginFormState extends State { final loginFormKey = GlobalKey(); var projectIdController = TextEditingController(); - String _platformImei = 'Unknown'; - String uniqueId = "Unknown"; var projectsList = []; - bool _isInit = true; FocusNode focusPass = FocusNode(); FocusNode focusProject = FocusNode(); HospitalViewModel projectsProv; - var userInfo = UserModel( - userID: '', - password: '', - projectID: 15, - languageID: 2, - iPAdress: "11.11.11.11", - versionID: 1.2, - channel: 9, - sessionID: "i1UJwCTSqt"); - - AuthViewModel authProv; + var userInfo = UserModel(); @override void initState() { super.initState(); @@ -64,9 +47,7 @@ class _LoginFormState extends State { @override Widget build(BuildContext context) { - authProv = Provider.of(context); projectsProv = Provider.of(context); - return Form( key: loginFormKey, child: Column( @@ -108,10 +89,7 @@ class _LoginFormState extends State { borderColor: Colors.white, // keyboardType: TextInputType.number, textInputAction: TextInputAction.next, - // decoration: buildInputDecoration( - // context, - // TranslationBase.of(context).enterId, - // 'assets/images/user_id_icon.png'), + validator: (value) { if (value != null && value.isEmpty) { return TranslationBase.of(context) @@ -128,8 +106,6 @@ class _LoginFormState extends State { onFieldSubmitted: (_) { focusPass.nextFocus(); }, - // onEditingComplete: () {}, - // autofocus: false, ) ])), buildSizedBox(), @@ -156,10 +132,6 @@ class _LoginFormState extends State { obscureText: true, borderColor: Colors.white, textInputAction: TextInputAction.next, - // decoration: buildInputDecoration( - // context, - // TranslationBase.of(context).enterPassword, - // 'assets/images/password_icon.png'), validator: (value) { if (value != null && value.isEmpty) { return TranslationBase.of(context) @@ -211,12 +183,6 @@ class _LoginFormState extends State { 'facilityName', onSelectProject); }, - // showCursor: false, - // //readOnly: true, - // decoration: buildInputDecoration( - // context, - // TranslationBase.of(context).selectYourProject, - // 'assets/images/password_icon.png'), validator: (value) { if (value != null && value.isEmpty) { return TranslationBase.of(context) @@ -244,18 +210,13 @@ class _LoginFormState extends State { fontSize: 14, )), AppTextFormField( - readOnly: true, borderColor: Colors.white, + readOnly: true, + borderColor: Colors.white, prefix: IconButton( icon: Icon(Icons.arrow_drop_down), iconSize: 30, padding: EdgeInsets.only(bottom: 30), ), - - // decoration: buildInputDecoration( - // context, - // TranslationBase.of(context) - // .pleaseEnterYourProject, - // 'assets/images/password_icon.png') ) ])), ]), @@ -268,67 +229,15 @@ class _LoginFormState extends State { title: TranslationBase.of(context).login, color: HexColor('#D02127'), onTap: () { - login(context, authProv, widget.changeLoadingStata); + login(context, this.widget.model); }, )), ], ) - // Row( - // mainAxisAlignment: MainAxisAlignment.end, - // children: [ - // RaisedButton( - // onPressed: () { - // login(context, authProv, widget.changeLoadingStata); - // }, - // textColor: Colors.white, - // elevation: 0.0, - // padding: const EdgeInsets.all(0.0), - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10), - // side: BorderSide(width: 0.5, color: HexColor('#CCCCCC'))), - // child: Container( - // padding: const EdgeInsets.all(10.0), - // height: 50, - // width: SizeConfig.realScreenWidth * 0.35, - // child: ), - // ) - // ], - // ), ], ), ); - } - -/* - *@author: Elham Rababah - *@Date:20/4/2020 - *@param: context, hint, asset - *@return: InputDecoration - *@desc: decorate input feilds - */ - InputDecoration buildInputDecoration(BuildContext context, hint, asset) { - return InputDecoration( - // prefixIcon: Image.asset(asset), - hintText: hint, - hintStyle: TextStyle(fontSize: 2 * SizeConfig.textMultiplier), - fillColor: Colors.white, - 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), - ), - 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), - ), - ); + //)); } SizedBox buildSizedBox() { @@ -337,103 +246,27 @@ class _LoginFormState extends State { ); } - login(context, AuthViewModel authProv, Function changeLoadingStata) { - showLoading(); + login( + context, + model, + ) { if (loginFormKey.currentState.validate()) { loginFormKey.currentState.save(); sharedPref.setInt(PROJECT_ID, userInfo.projectID); - authProv.login(userInfo).then((res) { - //changeLoadingStata(false); - hideLoading(); - if (res['MessageStatus'] == 1) { - // insertDeviceImei(res, authProv); - saveObjToString(LOGGED_IN_USER, res); + model.login(userInfo).then((res) { + if (model.loginInfo['MessageStatus'] == 1) { + saveObjToString(LOGGED_IN_USER, model.loginInfo); sharedPref.remove(LAST_LOGIN_USER); - sharedPref.setString(TOKEN, res['LogInTokenID']); - print("token" + res['LogInTokenID']); - Navigator.of(context).pushReplacement(MaterialPageRoute( - builder: (BuildContext context) => VerificationMethodsScreen( - password: userInfo.password, - ))); - } else { - // handel error - helpers.showErrorToast(res['ErrorEndUserMessage']); - } - }).catchError((err) { - //TODO change the logic here - if(!err.contains('eservices.hmg@drsulaimanalhabib.com') ){ - hideLoading(); - changeLoadingStata(false); - helpers.showErrorToast(err);} - }); - } else { - changeLoadingStata(false); - } - } - - insertDeviceImei(preRes, AuthViewModel authProv) { - if (_platformImei != 'Unknown') { - var imeiInfo = { - "IMEI": _platformImei, - "LogInType": 1, - "DoctorID": preRes['DoctorID'], - "DoctorName": "Test User", - "Gender": 1, - "ClinicID": 3, - "ProjectID": 15, - "DoctorTitle": "Mr.", - "ClinicName": "MED", - "ProjectName": "", - "DoctorImageURL": "UNKNOWN", - "LogInTokenID": preRes['LogInTokenID'], - "VersionID": 5.3 - }; - authProv.insertDeviceImei(imeiInfo).then((res) { - if (res['MessageStatus'] == 1) { - setSharedPref('platformImei', _platformImei); - saveObjToString(LOGGED_IN_USER, preRes); - - Navigator.of(context).pushReplacement(MaterialPageRoute( + sharedPref.setString(TOKEN, model.loginInfo['LogInTokenID']); + Navigator.of(AppGlobal.CONTEX).pushReplacement(MaterialPageRoute( builder: (BuildContext context) => VerificationMethodsScreen( password: userInfo.password, ))); - - // save imei on shared preferance - } else { - // handel error - helpers.showErrorToast(res['ErrorEndUserMessage']); } - }).catchError((err) { - print(err); - helpers.showErrorToast(); }); } } - // Platform messages are asynchronous, so we initialize in an async method. - Future initPlatformState() async { - String platformImei; - String idunique; - // Platform messages may fail, so we use a try/catch PlatformException. - try { - platformImei = - await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: false); - idunique = await ImeiPlugin.getImei(); - } catch (e) { - platformImei = 'Failed to get platform version.'; - } - - // If the widget was removed from the tree while the asynchronous platform - // message was in flight, we want to discard the reply rather than calling - // setState to update our non-existent appearance. - if (!mounted) return; - - setState(() { - _platformImei = platformImei; - uniqueId = idunique; - }); - } - Future setSharedPref(key, value) async { sharedPref.setString(key, value).then((success) { print("sharedPref.setString" + success.toString()); @@ -441,9 +274,7 @@ class _LoginFormState extends State { } getProjectsList(memberID) { - //showLoading(); projectsProv.getProjectsList(memberID).then((res) { - //hideLoading(); if (res['MessageStatus'] == 1) { projectsList = res['ProjectInfo']; setState(() { @@ -452,16 +283,7 @@ class _LoginFormState extends State { }); } else { print(res); - // handel error - // setState(() { - // projectsList = ListProject; - // }); } - }).catchError((err) { - setState(() { - print(err); - }); - print(err); }); } @@ -478,26 +300,11 @@ class _LoginFormState extends State { primaryFocus.unfocus(); } - showLoading() { - showDialog( - context: context, - builder: (BuildContext context) { - return Center( - child: CircularProgressIndicator(), - ); - }); - } - - hideLoading() { - Navigator.pop(context); - } - getProjects(value) { if (value != null && value != '') { if (projectsList.length == 0) { getProjectsList(value); } } - //_isInit = false; } } diff --git a/lib/widgets/auth/verfiy_account.dart b/lib/widgets/auth/verfiy_account.dart index 587c248c..b2ff2ece 100644 --- a/lib/widgets/auth/verfiy_account.dart +++ b/lib/widgets/auth/verfiy_account.dart @@ -239,13 +239,6 @@ class _VerifyAccountState extends State { }); } -/* - *@author: Elham Rababah - *@Date:19/4/2020 - *@param: - *@return: - *@desc: change the style for the input field - */ TextStyle buildTextStyle() { return TextStyle( fontSize: SizeConfig.textMultiplier * 3, @@ -260,16 +253,8 @@ class _VerifyAccountState extends State { return null; } -/* - *@author: Elham Rababah - *@Date:28/4/2020 - *@param: context - *@return:InputDecoration - *@desc: buildInputDecoration - */ InputDecoration buildInputDecoration(BuildContext context) { return InputDecoration( - // ts/images/password_icon.png contentPadding: EdgeInsets.only(top: 30, bottom: 30), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.all(Radius.circular(10)), @@ -290,13 +275,6 @@ class _VerifyAccountState extends State { ); } -/* - *@author: Elham Rababah - *@Date:28/4/2020 - *@param: - *@return: RichText - *@desc: buildText - */ RichText buildText() { String medthodName; switch (model['OTP_SendType']) { @@ -329,13 +307,6 @@ class _VerifyAccountState extends State { ); } -/* - *@author: Elham Rababah - *@Date:15/4/2020 - *@param: authProv - *@return: - *@desc: verify Account func call sendActivationCodeByOtpNotificationType service - */ verifyAccount(AuthViewModel authProv, Function changeLoadingStata) async { if (verifyAccountForm.currentState.validate()) { changeLoadingStata(true); @@ -346,23 +317,6 @@ class _VerifyAccountState extends State { verifyAccountFormValue['digit3'] + verifyAccountFormValue['digit4']; - int projectID = await sharedPref.getInt(PROJECT_ID); - - Map model = { - "activationCode": activationCode, - "DoctorID": _loggedUser['DoctorID'], - "LogInTokenID": _loggedUser['LogInTokenID'], - "ProjectID": projectID, - "LanguageID": 2, - "stamp": "2020-02-26T14:48:27.221Z", - "IPAdress": "11.11.11.11", - "VersionID": 1.2, - "Channel": 9, - "TokenID": "", - "SessionID": "i1UJwCTSqt", - "IsLoginForDoctorApp": true, - "IsSilentLogIN": false - }; CheckActivationCodeRequestModel checkActivationCodeForDoctorApp = new CheckActivationCodeRequestModel( zipCode: _loggedUser['ZipCode'], @@ -396,13 +350,6 @@ class _VerifyAccountState extends State { } } - /* - *@author: Elham Rababah - *@Date:17/5/2020 - *@param: Map profile, Function changeLoadingStata - *@return: - *@desc: loginProcessCompleted - */ loginProcessCompleted( Map profile, Function changeLoadingStata) { var doctor = DoctorProfileModel.fromJson(profile); @@ -412,43 +359,10 @@ class _VerifyAccountState extends State { } getDashboard(doctor, Function changeLoadingStata) { - // authProv.getDashboard(doctor).then((value) { - // print(value); changeLoadingStata(false); - // sharedPref.setObj(DASHBOARD_DATA, value); Navigator.of(context).pushReplacementNamed(HOME); - // }); - } - - Future _asyncSimpleDialog( - BuildContext context, List list, String txtKey, - [String text = '']) async { - return await showDialog( - context: context, - barrierDismissible: true, - builder: (BuildContext context) { - return SimpleDialog( - title: Text(text), - children: list.map((value) { - return SimpleDialogOption( - onPressed: () { - Navigator.pop(context, - value); //here passing the index to be return on item selection - }, - child: Text(value[txtKey]), //item value - ); - }).toList(), - ); - }); } - /* - *@author: Elham Rababah - *@Date:17/5/2020 - *@param: ClinicModel clinicInfo, Function changeLoadingStata - *@return: - *@desc: getDocProfiles - */ getDocProfiles(ClinicModel clinicInfo, Function changeLoadingStata) { ProfileReqModel docInfo = new ProfileReqModel( doctorID: clinicInfo.doctorID, diff --git a/lib/widgets/auth/verification_methods.dart b/lib/widgets/auth/verification_methods.dart index b4d39894..c3c59dde 100644 --- a/lib/widgets/auth/verification_methods.dart +++ b/lib/widgets/auth/verification_methods.dart @@ -177,24 +177,7 @@ class _VerificationMethodsState extends State { user.logInTypeID, context), fontSize: 14, - ) - // Text( - // user.editedOn != null - // ? formatDate(Helpers - // .convertStringToDate( - // user.editedOn)) - // : user.createdOn != null - // ? formatDate(Helpers - // .convertStringToDate(user - // .createdOn)) - // : '--', - // overflow: - // TextOverflow.ellipsis, - // style: TextStyle( - // fontFamily: 'Poppins'), - // textAlign: - // TextAlign.center), - )), + ))), Flexible( flex: 2, child: ListTile( @@ -288,16 +271,6 @@ class _VerificationMethodsState extends State { Expanded( child: getButton(5, authProv)) ]), - // Row( - // mainAxisAlignment: - // MainAxisAlignment.center, - // children: [ - // Expanded( - // child: getButton(1, authProv)), - // Expanded( - // child: getButton(2, authProv)) - // ], - // ) ]) : Column( mainAxisAlignment: MainAxisAlignment.start, @@ -366,13 +339,6 @@ class _VerificationMethodsState extends State { return verificationMethod == 4 || verificationMethod == 3 ? true : false; } -/* - *@author: Elham Rababah - *@Date:15/4/2020 - *@param: oTPSendType - *@return: - *@desc: send Activation Code By Otp Notification Type - */ sendActivationCodeByOtpNotificationType( oTPSendType, AuthViewModel authProv) async { // TODO : build enum for verfication method @@ -860,7 +826,12 @@ class _VerificationMethodsState extends State { sharedPref.setObj(DOCTOR_PROFILE, profile); projectsProvider.isLogin = true; - Navigator.pushAndRemoveUntil(context, FadePage(page: LandingPage(),), (r) => false); + Navigator.pushAndRemoveUntil( + context, + FadePage( + page: LandingPage(), + ), + (r) => false); } getDocProfiles(ClinicModel clinicInfo, authProv) {