From d866d8b9de2cd8023add689e284433d041b24a27 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Thu, 2 Jul 2020 12:30:53 +0300 Subject: [PATCH 1/2] get clinic list --- lib/config/config.dart | 24 +++++++++++------ lib/providers/auth_provider.dart | 9 +++++-- lib/providers/project_provider.dart | 41 ++++++++++++++++++++++++----- lib/screens/dashboard_screen.dart | 15 ++++++++--- lib/widgets/auth/login_form.dart | 2 +- 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 261fcd46..153e5d3a 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -35,23 +35,31 @@ const START_LIVECARE_CALL = 'LiveCareApi/DoctorApp/CallPatient'; const LIVE_CARE_STATISTICS_FOR_CERTAIN_DOCTOR_URL = "Lists.svc/REST/DashBoard_GetLiveCareDoctorsStatsticsForCertainDoctor"; -const GET_PRESCRIPTION_REPORT = 'Services/Patients.svc/REST/GetPrescriptionReport'; +const GET_PRESCRIPTION_REPORT = + 'Services/Patients.svc/REST/GetPrescriptionReport'; -const GT_MY_PATIENT_QUESTION = 'Services/DoctorApplication.svc/REST/GtMyPatientsQuestions'; +const GT_MY_PATIENT_QUESTION = + 'Services/DoctorApplication.svc/REST/GtMyPatientsQuestions'; const GET_PATIENT = 'Services/DoctorApplication.svc/REST/'; -const GET_PRESCRIPTION_REPORT_FOR_IN_PATIENT= 'Services/DoctorApplication.svc/REST/GetPrescriptionReportForInPatient'; +const GET_PRESCRIPTION_REPORT_FOR_IN_PATIENT = + 'Services/DoctorApplication.svc/REST/GetPrescriptionReportForInPatient'; -const GET_MY_REFERRAL_PATIENT = 'Services/DoctorApplication.svc/REST/GtMyReferralPatient'; +const GET_MY_REFERRAL_PATIENT = + 'Services/DoctorApplication.svc/REST/GtMyReferralPatient'; -const ADD_REFERRED_DOCTOR_REMARKS= 'Services/DoctorApplication.svc/REST/AddReferredDoctorRemarks'; +const ADD_REFERRED_DOCTOR_REMARKS = + 'Services/DoctorApplication.svc/REST/AddReferredDoctorRemarks'; -const GET_MY_REFERRED_PATIENT = 'Services/DoctorApplication.svc/REST/GtMyReferredPatient'; +const GET_MY_REFERRED_PATIENT = + 'Services/DoctorApplication.svc/REST/GtMyReferredPatient'; -const GET_DOCTOR_WORKING_HOURS_TABLE = 'Services/Doctors.svc/REST/GetDoctorWorkingHoursTable'; +const GET_DOCTOR_WORKING_HOURS_TABLE = + 'Services/Doctors.svc/REST/GetDoctorWorkingHoursTable'; -const GET_PATIENT_LAB_RESULTS= 'Services/DoctorApplication.svc/REST/GetPatientLabResults'; +const GET_PATIENT_LAB_RESULTS = + 'Services/DoctorApplication.svc/REST/GetPatientLabResults'; var selectedPatientType = 1; diff --git a/lib/providers/auth_provider.dart b/lib/providers/auth_provider.dart index 61a61530..a66c6192 100644 --- a/lib/providers/auth_provider.dart +++ b/lib/providers/auth_provider.dart @@ -18,6 +18,10 @@ const SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE = const MEMBER_CHECK_ACTIVATION_CODE_NEW = 'Services/Sentry.svc/REST/MemberCheckActivationCode_New'; const GET_DOC_PROFILES = 'Services/Doctors.svc/REST/GetDocProfiles'; + +const GET_CLINICS_FOR_DOCTOR = + 'Services/DoctorApplication.svc/REST/GetClinicsForDoctor'; + DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } @@ -166,11 +170,12 @@ class AuthProvider with ChangeNotifier { onSuccess: (dynamic response, int statusCode) { localRes = response; //ClinicDescription - selectedClinicName = response['DoctorProfileList'][0]['ClinicDescription']; + selectedClinicName = + response['DoctorProfileList'][0]['ClinicDescription']; }, onFailure: (String error, int statusCode) { throw error; }, body: docInfo); - notifyListeners(); + notifyListeners(); return Future.value(localRes); } catch (error) { print(error); diff --git a/lib/providers/project_provider.dart b/lib/providers/project_provider.dart index 4de2251f..f3abc26c 100644 --- a/lib/providers/project_provider.dart +++ b/lib/providers/project_provider.dart @@ -1,8 +1,10 @@ import 'dart:async'; 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/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/providers/auth_provider.dart'; @@ -10,6 +12,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:provider/provider.dart'; + Helpers helpers = Helpers(); class ProjectProvider with ChangeNotifier { @@ -18,12 +21,15 @@ class ProjectProvider with ChangeNotifier { String currentLanguage = 'ar'; bool _isArabic = false; bool isInternetConnection = true; + List clinicList = []; + bool isLoading = false; + bool isError = false; + String error = ''; Locale get appLocal => _appLocale; bool get isArabic => _isArabic; StreamSubscription subscription; - // AuthProvider authProvider = AuthProvider(); ProjectProvider() { loadSharedPrefLanguage(); @@ -66,7 +72,7 @@ class ProjectProvider with ChangeNotifier { currentLanguage = 'en'; sharedPref.setString(APP_Language, 'en'); } - getProfile(); + getProfile(); notifyListeners(); } @@ -76,7 +82,29 @@ class ProjectProvider with ChangeNotifier { super.dispose(); } - void getProfile()async{ + Future getClinicNames() async { + try { + dynamic localRes; + + await BaseAppClient.post(GET_CLINICS_FOR_DOCTOR, + onSuccess: (dynamic response, int statusCode) { + clinicList = []; + response['List_DoctorsClinic'].forEach((v) { + clinicList.add(new ClinicModel.fromJson(v)); + }); + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }, body: {}); + + return Future.value(localRes); + } catch (error) { + print(error); + throw error; + } + } + + void getProfile() async { Map profile = await sharedPref.getObj(DOCTOR_PROFILE); DoctorProfileModel doctorProfile = new DoctorProfileModel.fromJson(profile); ProfileReqModel docInfo = new ProfileReqModel( @@ -87,13 +115,12 @@ class ProjectProvider with ChangeNotifier { tokenID: '', languageID: 2); - Provider.of(AppGlobal.CONTEX,listen: false) - .getDocProfiles(docInfo.toJson()).then((res) async { + Provider.of(AppGlobal.CONTEX, listen: false) + .getDocProfiles(docInfo.toJson()) + .then((res) async { sharedPref.setObj(DOCTOR_PROFILE, res['DoctorProfileList'][0]); }).catchError((err) { print(err); }); } - - } diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart index 037b344d..3542f624 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screens/dashboard_screen.dart @@ -49,13 +49,22 @@ class _DashboardScreenState extends State { AuthProvider authProvider; bool isLoading = false; ProjectProvider projectsProvider; + var _isInit = true; + + void didChangeDependencies() { + super.didChangeDependencies(); + if (_isInit) { + projectsProvider = Provider.of(context); + projectsProvider.getClinicNames(); + } + _isInit = false; + } @override Widget build(BuildContext context) { hospitalProvider = Provider.of(context); authProvider = Provider.of(context); projectsProvider = Provider.of(context); - print(authProvider.doctorsClinicList); FocusScopeNode currentFocus = FocusScope.of(context); if (!currentFocus.hasPrimaryFocus) { currentFocus.unfocus(); @@ -90,7 +99,7 @@ class _DashboardScreenState extends State { onTap: () { showCupertinoPicker( context: context, - actionList: authProvider.doctorsClinicList); + actionList: projectsProvider.clinicList); }, child: Container( margin: @@ -542,6 +551,7 @@ class _DashboardScreenState extends State { changeIsLoading(true); Map profile = await sharedPref.getObj(DOCTOR_PROFILE); DoctorProfileModel doctorProfile = new DoctorProfileModel.fromJson(profile); + ProfileReqModel docInfo = new ProfileReqModel( doctorID: doctorProfile.doctorID, clinicID: clinicId, @@ -549,7 +559,6 @@ class _DashboardScreenState extends State { projectID: doctorProfile.projectID, tokenID: '', languageID: 2); - // authProvider.getDocProfiles(docInfo) authProvider.getDocProfiles(docInfo.toJson()).then((res) async { changeIsLoading(false); diff --git a/lib/widgets/auth/login_form.dart b/lib/widgets/auth/login_form.dart index 033f445c..078cf503 100644 --- a/lib/widgets/auth/login_form.dart +++ b/lib/widgets/auth/login_form.dart @@ -301,7 +301,7 @@ class _LoginFormState extends State { platformImei = await ImeiPlugin.getImei(shouldShowRequestPermissionRationale: false); idunique = await ImeiPlugin.getImei(); - } catch(e) { + } catch (e) { platformImei = 'Failed to get platform version.'; } From aa57f4c4d7a644a2a8f801aa4a8316d3c350dbd7 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Sun, 5 Jul 2020 12:04:50 +0300 Subject: [PATCH 2/2] get clinic list after changing the language --- lib/config/localized_values.dart | 4 ++- lib/providers/project_provider.dart | 7 +++- lib/screens/dashboard_screen.dart | 45 ++++++++++++++---------- lib/util/helpers.dart | 5 +-- lib/util/translations_delegate_base.dart | 2 ++ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/lib/config/localized_values.dart b/lib/config/localized_values.dart index 892d54fe..c5332425 100644 --- a/lib/config/localized_values.dart +++ b/lib/config/localized_values.dart @@ -213,5 +213,7 @@ const Map> localizedValues = { }, 'livecare': {'en': 'Live Care', 'ar': 'Live Care'}, 'beingBad': {'en': 'being bad', 'ar': 'سيء'}, - 'beingGreat': {'en': 'being great', 'ar': 'راثع'}, + 'beingGreat': {'en': 'being great', 'ar': 'رائع'}, + 'cancel': {'en': 'CANCEL', 'ar': 'الغاء'}, + 'done': {'en': 'DONE', 'ar': 'تأكيد'}, }; diff --git a/lib/providers/project_provider.dart b/lib/providers/project_provider.dart index f3abc26c..81f50c42 100644 --- a/lib/providers/project_provider.dart +++ b/lib/providers/project_provider.dart @@ -72,10 +72,15 @@ class ProjectProvider with ChangeNotifier { currentLanguage = 'en'; sharedPref.setString(APP_Language, 'en'); } - getProfile(); + callServicesAfterChangeLang(); notifyListeners(); } + callServicesAfterChangeLang() { + getProfile(); + getClinicNames(); + } + @override void dispose() { if (subscription != null) subscription.cancel(); diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart index 3fda04d0..4a1a2f46 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screens/dashboard_screen.dart @@ -61,6 +61,7 @@ class _DashboardScreenState extends State { } _isInit = false; } + BuildContext myContext; GlobalKey _one = GlobalKey(); @@ -101,7 +102,9 @@ class _DashboardScreenState extends State { fontWeight: FontWeight.bold, fontSize: SizeConfig.textMultiplier * 2.5, ), - alignment: Alignment.centerLeft, + alignment: projectsProvider.isArabic + ? Alignment.topRight + : Alignment.topLeft, ), ), Row( @@ -112,6 +115,7 @@ class _DashboardScreenState extends State { InkWell( onTap: () { showCupertinoPicker( + decKey: '', context: context, actionList: projectsProvider.clinicList); }, @@ -310,7 +314,9 @@ class _DashboardScreenState extends State { TranslationBase.of(context).patientServices, fontWeight: FontWeight.bold, ), - alignment: Alignment.centerLeft, + alignment: projectsProvider.isArabic + ? Alignment.topRight + : Alignment.topLeft, ), ), Expanded( @@ -538,19 +544,17 @@ class _DashboardScreenState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ CupertinoButton( - child: Text( - 'Cancel'.toUpperCase(), - // style: TextStyle(context) - ), + child: Text(TranslationBase.of(context).cancel + // style: TextStyle(context) + ), onPressed: () { Navigator.pop(context); }, ), CupertinoButton( - child: Text( - 'Done'.toUpperCase(), - // style: textStyle(context), - ), + child: Text(TranslationBase.of(context).done + // style: textStyle(context), + ), onPressed: () { Navigator.pop(context); // onSelectFun(cupertinoPickerIndex); @@ -564,14 +568,19 @@ class _DashboardScreenState extends State { color: Color(0xfff7f7f7), child: Column( children: actionList - .map((e) => Container( - child: InkWell( - onTap: () => - changeClinic(e.clinicID, context), - child: Text( - e.clinicName, - style: TextStyle(fontSize: 15), - )), + .map((e) => Flexible( + child: Container( + child: InkWell( + onTap: () => + changeClinic(e.clinicID, context), + child: Text( + e.clinicName ?? 'asd', + style: TextStyle( + fontSize: + SizeConfig.textMultiplier * + 1.9), + )), + ), )) .toList(), )) diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 6807edf3..41c0b4f7 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -11,6 +11,7 @@ import '../util/dr_app_toast_msg.dart'; import 'package:connectivity/connectivity.dart'; import 'dr_app_shared_pref.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); @@ -51,7 +52,7 @@ class Helpers { mainAxisAlignment: MainAxisAlignment.end, children: [ CupertinoButton( - child: Text('Cancel'.toUpperCase(), + child: Text(TranslationBase.of(context).cancel, style: textStyle(context)), onPressed: () { Navigator.pop(context); @@ -59,7 +60,7 @@ class Helpers { ), CupertinoButton( child: Text( - 'Done'.toUpperCase(), + TranslationBase.of(context).done, style: textStyle(context), ), onPressed: () { diff --git a/lib/util/translations_delegate_base.dart b/lib/util/translations_delegate_base.dart index ca49936e..ad52edd8 100644 --- a/lib/util/translations_delegate_base.dart +++ b/lib/util/translations_delegate_base.dart @@ -233,6 +233,8 @@ class TranslationBase { String get livecare => localizedValues['livecare'][locale.languageCode]; String get beingBad => localizedValues['beingBad'][locale.languageCode]; String get beingGreat => localizedValues['beingGreat'][locale.languageCode]; + String get cancel => localizedValues['cancel'][locale.languageCode]; + String get done => localizedValues['done'][locale.languageCode]; } class TranslationBaseDelegate extends LocalizationsDelegate {