From 948f4fc6b81c07d09659bd2589185d02527d0a35 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 14 Sep 2021 17:24:09 +0300 Subject: [PATCH] CMC Add address fixes --- .../AlHabibMedicalService/cmc_service.dart | 2 +- .../customer_addresses_service.dart | 8 ++-- lib/core/service/base_service.dart | 2 +- .../PharmacyAddressesViewModel.dart | 11 ----- .../NewCMC/new_cmc_step_tow_page.dart | 43 +++++++++++-------- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/lib/core/service/AlHabibMedicalService/cmc_service.dart b/lib/core/service/AlHabibMedicalService/cmc_service.dart index 11c306dc..012e4d90 100644 --- a/lib/core/service/AlHabibMedicalService/cmc_service.dart +++ b/lib/core/service/AlHabibMedicalService/cmc_service.dart @@ -23,7 +23,7 @@ class CMCService extends BaseService { bool isOrderUpdated; Future getCMCAllServices() async { - GetCMCServicesRequestModel getCMCServicesRequestModel = new GetCMCServicesRequestModel(genderID: user.gender, identificationNo: user.patientIdentificationNo); + GetCMCServicesRequestModel getCMCServicesRequestModel = new GetCMCServicesRequestModel(genderID: authenticatedUserObject.user.gender, identificationNo: authenticatedUserObject.user.patientIdentificationNo); hasError = false; await baseAppClient.post(HHC_GET_ALL_CMC_SERVICES, onSuccess: (dynamic response, int statusCode) { cmcAllServicesList.clear(); diff --git a/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart b/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart index ea5d03ca..8f54150c 100644 --- a/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart +++ b/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart @@ -20,15 +20,15 @@ class CustomerAddressesService extends BaseService { addNewAddressRequestModel.customer.roleIds = [3]; addNewAddressRequestModel.customer.addresses[0].email = customerInfo.email; addNewAddressRequestModel.customer.addresses[0].phoneNumber = customerInfo.mobileNumber; - addNewAddressRequestModel.customer.addresses[0].firstName = user.firstName; - addNewAddressRequestModel.customer.addresses[0].lastName = user.lastName; + addNewAddressRequestModel.customer.addresses[0].firstName = authenticatedUserObject.user.firstName; + addNewAddressRequestModel.customer.addresses[0].lastName = authenticatedUserObject.user.lastName; addNewAddressRequestModel.customer.addresses[0].countryId = 69; var f = DateFormat('E, d MMM yyyy HH:mm:ss'); var date = f.format(DateTime.now().toUtc()) + " GMT"; addNewAddressRequestModel.customer.addresses[0].createdOnUtc = date; hasError = false; - await baseAppClient.post(ADD_CUSTOMER_ADDRESS, + await baseAppClient.postPharmacy(ADD_CUSTOMER_ADDRESS, onSuccess: (dynamic response, int statusCode) { addressesList.clear(); response["customers"][0]["addresses"].forEach((data) { @@ -62,7 +62,7 @@ class CustomerAddressesService extends BaseService { Future getCustomerInfo() async { Map queryParams = { - 'FileNumber':'${user.patientID}' + 'FileNumber':'${authenticatedUserObject.user.patientID}' }; hasError = false; diff --git a/lib/core/service/base_service.dart b/lib/core/service/base_service.dart index fdb80604..c2d31cf1 100644 --- a/lib/core/service/base_service.dart +++ b/lib/core/service/base_service.dart @@ -10,7 +10,7 @@ class BaseService { String error; bool hasError = false; BaseAppClient baseAppClient = BaseAppClient(); - AuthenticatedUser user; + AuthenticatedUser user = new AuthenticatedUser(); AuthenticatedUserObject authenticatedUserObject = locator(); diff --git a/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart b/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart index 485c92fb..b4d24733 100644 --- a/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart @@ -34,17 +34,6 @@ class PharmacyAddressesViewModel extends BaseViewModel { } } -/* Future getCountries(String countryName) async { - setState(ViewState.Busy); - await _pharmacyAddressService.getCountries(countryName); - if (_pharmacyAddressService.hasError) { - error = _pharmacyAddressService.error; - // setState(ViewState.Error); - } else { - // setState(ViewState.Idle); - } - }*/ - Future addEditAddress(PickResult value, Addresses editedAddress) async { setState(ViewState.Busy); diff --git a/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/new_cmc_step_tow_page.dart b/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/new_cmc_step_tow_page.dart index 316a9ab9..4525d89b 100644 --- a/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/new_cmc_step_tow_page.dart +++ b/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/new_cmc_step_tow_page.dart @@ -1,19 +1,18 @@ import 'dart:async'; -import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/ComprehensiveMedicalCheckup/cmc_insert_pres_order_request_model.dart'; import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart'; import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/cmc_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/location_util.dart'; -import 'package:diplomaticquarterapp/uitl/utils_new.dart'; -import 'package:diplomaticquarterapp/widgets/dialogs/select_location_dialog.dart'; -import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/uitl/utils_new.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; -import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/dialogs/select_location_dialog.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/cupertino.dart'; @@ -45,6 +44,7 @@ class _NewCMCStepTowPageState extends State { double longitude = 0; AddressInfo _selectedAddress; bool showCurrentLocation = false; + AppSharedPreferences sharedPref = AppSharedPreferences(); Completer _controller = Completer(); GoogleMapController googleMapController; @@ -56,21 +56,25 @@ class _NewCMCStepTowPageState extends State { LatLng currentPostion; void _getUserLocation() async { - if (await Permission.contacts.request().isGranted) { - // Either the permission was already granted before or the user just granted it. - var position = await GeolocatorPlatform.instance.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); - - currentPostion = LatLng(position.latitude, position.longitude); + if (await this.sharedPref.getDouble(USER_LAT) != null && await this.sharedPref.getDouble(USER_LONG) != null) { + var lat = await this.sharedPref.getDouble(USER_LAT); + var long = await this.sharedPref.getDouble(USER_LONG); + currentPostion = LatLng(lat, long); setMap(); } else { - requestPermissions().then((value) async { - if (value[Permission.location].isGranted) { - var position = await GeolocatorPlatform.instance.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); - - currentPostion = LatLng(position.latitude, position.longitude); - setMap(); - } - }); + if (await Permission.location.request().isGranted) { + var position = await GeolocatorPlatform.instance.getCurrentPosition(desiredAccuracy: LocationAccuracy.low); + currentPostion = LatLng(position.latitude, position.longitude); + setMap(); + } else { + requestPermissions().then((value) async { + if (value[Permission.location].isGranted) { + var position = await GeolocatorPlatform.instance.getCurrentPosition(desiredAccuracy: LocationAccuracy.low); + currentPostion = LatLng(position.latitude, position.longitude); + setMap(); + } + }); + } } } @@ -90,7 +94,7 @@ class _NewCMCStepTowPageState extends State { CameraUpdate.newCameraPosition( CameraPosition( target: currentPostion, - zoom: 20, + zoom: 16, ), ), ); @@ -122,6 +126,7 @@ class _NewCMCStepTowPageState extends State { latitude = double.parse(latLongArr[0]); longitude = double.parse(latLongArr[1]); + currentPostion = LatLng(latitude, longitude); setMap(); } }