From a6c665136310963a20930112aaff45e0ff0bf23f Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Sun, 16 Jan 2022 11:51:29 +0300 Subject: [PATCH] Updates & fixes --- lib/config/config.dart | 2 +- .../customer_addresses_service.dart | 12 +- .../add_new_address_Request_Model.dart | 6 +- .../home_health_care_view_model.dart | 1 + .../PharmacyAddressesViewModel.dart | 48 +++--- .../NewCMC/cmc_location_page.dart | 2 +- .../NewHomeHealthCare/location_page.dart | 126 ++++++++++++++- .../new_Home_health_care_step_tow_page.dart | 31 ++-- lib/pages/login/register-info.dart | 84 ---------- .../pharmacyAddresses/AddAddress.dart | 151 +++++++++++++++--- .../pharmacyAddresses/PharmacyAddresses.dart | 4 +- lib/widgets/app_map/google_huawei_map.dart | 5 +- 12 files changed, 309 insertions(+), 163 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index de20e677..811e95fc 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -377,7 +377,7 @@ const UPDATE_COVID_QUESTIONNAIRE = 'Services/Doctors.svc/REST/COVID19_Questionna const CHANNEL = 3; const GENERAL_ID = 'Cs2020@2016\$2958'; const IP_ADDRESS = '10.20.10.20'; -const VERSION_ID = 7.2; +const VERSION_ID = 7.3; const SETUP_ID = '91877'; const LANGUAGE = 2; const PATIENT_OUT_SA = 0; diff --git a/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart b/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart index 2f92fe5e..f3cc5dd7 100644 --- a/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart +++ b/lib/core/service/AlHabibMedicalService/customer_addresses_service.dart @@ -11,11 +11,11 @@ class CustomerAddressesService extends BaseService { CustomerInfo customerInfo = new CustomerInfo(); Future addAddressInfo({AddNewAddressRequestModel addNewAddressRequestModel}) async { - addNewAddressRequestModel.customer.email = customerInfo.email; - addNewAddressRequestModel.customer.id = customerInfo.customerId; + var customerId = await sharedPref.getString(PHARMACY_CUSTOMER_ID); + addNewAddressRequestModel.customer.email = addNewAddressRequestModel.customer.addresses[0].email; + addNewAddressRequestModel.customer.id = customerId; addNewAddressRequestModel.customer.roleIds = [3]; - addNewAddressRequestModel.customer.addresses[0].email = customerInfo.email; - addNewAddressRequestModel.customer.addresses[0].phoneNumber = customerInfo.mobileNumber; + addNewAddressRequestModel.customer.addresses[0].phoneNumber = addNewAddressRequestModel.customer.addresses[0].phoneNumber; addNewAddressRequestModel.customer.addresses[0].firstName = authenticatedUserObject.user.firstName; addNewAddressRequestModel.customer.addresses[0].lastName = authenticatedUserObject.user.lastName; addNewAddressRequestModel.customer.addresses[0].countryId = 69; @@ -30,8 +30,8 @@ class CustomerAddressesService extends BaseService { addressesList.add(AddressInfo.fromJson(data)); }); }, onFailure: (String error, int statusCode) { - hasError = true; - super.error = error; + hasError = false; + // super.error = error; }, body: addNewAddressRequestModel.toJson(), isAllowAny: true); } diff --git a/lib/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart b/lib/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart index 23329a89..0aeb9f60 100644 --- a/lib/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart +++ b/lib/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart @@ -20,7 +20,7 @@ class AddNewAddressRequestModel { class Customer { List addresses; - int id; + String id; String email; List roleIds; @@ -51,7 +51,7 @@ class Customer { } class Addresses { - int id; + String id; String firstName; String lastName; String email; @@ -67,7 +67,7 @@ class Addresses { dynamic faxNumber; String customerAttributes; String createdOnUtc; - Null province; + dynamic province; String latLong; Addresses( diff --git a/lib/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart b/lib/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart index 09b2a73d..41683165 100644 --- a/lib/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart +++ b/lib/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart @@ -1,3 +1,4 @@ +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/enum/OrderService.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/ComprehensiveMedicalCheckup/GetCMCAllOrdersResponseModel.dart'; diff --git a/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart b/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart index 02783f9f..5a098b6f 100644 --- a/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart @@ -4,6 +4,7 @@ import 'package:diplomaticquarterapp/core/model/pharmacies/Country.dart'; import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart'; import 'package:diplomaticquarterapp/services/pharmacy_services/pharmacyAddress_service.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:geocoding/geocoding.dart'; import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import '../../../locator.dart'; @@ -33,7 +34,8 @@ class PharmacyAddressesViewModel extends BaseViewModel { } } - Future addEditAddress(PickResult value, AddressInfo editedAddress) async { + // Future addEditAddress(PickResult value, AddressInfo editedAddress) async { + Future addEditAddress(Placemark selectedPlace, AddressInfo editedAddress, {String latLong}) async { setState(ViewState.Busy); AddressInfo sendingAddress; @@ -48,27 +50,34 @@ class PharmacyAddressesViewModel extends BaseViewModel { } else { sendingAddress = editedAddress; } - value.addressComponents.forEach((element) { - if (element.types.contains("country")) { - sendingAddress.country = element.longName; - } - if (element.types.contains("administrative_area_level_1")) { - sendingAddress.city = element.longName; - } - if (element.types.contains("postal_code")) { - sendingAddress.zipPostalCode = element.longName; - } - if (element.types.contains("administrative_area_level_2")) { - sendingAddress.province = element.longName; - } - }); - sendingAddress.latLong = value.geometry.location.toString(); + + sendingAddress.country = selectedPlace.country; + sendingAddress.city = selectedPlace.locality; + sendingAddress.zipPostalCode = selectedPlace.postalCode; + sendingAddress.province = selectedPlace.locality; + sendingAddress.latLong = latLong; + + // value.addressComponents.forEach((element) { + // if (element.types.contains("country")) { + // sendingAddress.country = element.longName; + // } + // if (element.types.contains("administrative_area_level_1")) { + // sendingAddress.city = element.longName; + // } + // if (element.types.contains("postal_code")) { + // sendingAddress.zipPostalCode = element.longName; + // } + // if (element.types.contains("administrative_area_level_2")) { + // sendingAddress.province = element.longName; + // } + // }); + // sendingAddress.latLong = value.geometry.location.toString(); await _pharmacyAddressService.getCountries(sendingAddress.country); sendingAddress.countryId = country.id; sendingAddress.stateProvinceId = null; - sendingAddress.address1 = value.formattedAddress; - sendingAddress.address2 = ""; + sendingAddress.address1 = selectedPlace.name; + sendingAddress.address2 = selectedPlace.street; sendingAddress.phoneNumber = user.mobileNumber; sendingAddress.faxNumber = user.faxNumber; sendingAddress.customerAttributes = ""; @@ -76,8 +85,7 @@ class PharmacyAddressesViewModel extends BaseViewModel { if (editedAddress == null) { await _pharmacyAddressService.addCustomerAddress(sendingAddress); } else { - await _pharmacyAddressService.editCustomerAddress(sendingAddress).then((value) async { - }); + await _pharmacyAddressService.editCustomerAddress(sendingAddress).then((value) async {}); } if (_pharmacyAddressService.hasError) { diff --git a/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart b/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart index 41fe54b9..a7478371 100644 --- a/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart +++ b/lib/pages/AlHabibMedicalService/ComprehensiveMedicalCheckup/NewCMC/cmc_location_page.dart @@ -108,7 +108,7 @@ class _CMCLocationPageState extends State { customerAttributes: "", city: "", createdOnUtc: "", - id: 0, + id: "0", latLong: selectedPlace.geometry.location.lat.toString() + "," + selectedPlace.geometry.location.lng.toString(), email: "", ) diff --git a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart index ffbf5b18..a3fce7b4 100644 --- a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart +++ b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/location_page.dart @@ -1,16 +1,21 @@ +import 'dart:async'; + import 'package:diplomaticquarterapp/config/config.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/uitl/utils.dart'; +import 'package:diplomaticquarterapp/widgets/app_map/google_huawei_map.dart'; import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:geocoding/geocoding.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import 'package:provider/provider.dart'; @@ -32,6 +37,16 @@ class _LocationPageState extends State { double longitude = 0; bool showCurrentLocation = false; + AppMap appMap; + AppSharedPreferences sharedPref = AppSharedPreferences(); + static CameraPosition _kGooglePlex = CameraPosition( + target: LatLng(37.42796133580664, -122.085749655962), + zoom: 14.4746, + ); + LatLng currentPostion; + Completer mapController = Completer(); + Placemark selectedPlace; + @override void initState() { latitude = widget.latitude; @@ -39,6 +54,23 @@ class _LocationPageState extends State { if (latitude == 0.0 && longitude == 0.0) { showCurrentLocation = true; } + appMap = AppMap( + _kGooglePlex.toMap(), + onCameraMove: (camera) { + _updatePosition(camera); + }, + onMapCreated: () { + currentPostion = LatLng(widget.latitude, widget.longitude); + latitude = widget.latitude; + longitude = widget.longitude; + setMap(); + setState(() {}); + }, + onCameraIdle: () async { + List placemarks = await placemarkFromCoordinates(latitude, longitude); + selectedPlace = placemarks[0]; + }, + ); super.initState(); } @@ -54,7 +86,60 @@ class _LocationPageState extends State { baseViewModel: model, showNewAppBarTitle: true, showNewAppBar: true, - body: PlacePicker( + body: + // Column( + // children: [ + // Expanded( + // child: Stack( + // alignment: Alignment.center, + // children: [ + // if (appMap != null) appMap, + // Container( + // margin: EdgeInsets.only(bottom: 50.0), + // child: Icon( + // Icons.place, + // color: CustomColors.accentColor, + // size: 50, + // ), + // ), + // ], + // ), + // ), + // Container( + // padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14), + // child: DefaultButton(TranslationBase.of(context).addNewAddress, () async { + // AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( + // customer: Customer(addresses: [ + // Addresses( + // address1: selectedPlace.name, + // address2: selectedPlace.street, + // customerAttributes: "", + // city: selectedPlace.locality, + // createdOnUtc: "", + // id: "0", + // faxNumber: "", + // phoneNumber: projectViewModel.user.mobileNumber, + // province: selectedPlace.locality, + // countryId: 69, + // latLong: "$latitude,$longitude", + // country: selectedPlace.country, + // zipPostalCode: selectedPlace.postalCode, + // email: projectViewModel.user.emailAddress) + // ]), + // ); + // await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); + // if (model.state == ViewState.ErrorLocal) { + // Utils.showErrorToast(model.error); + // } else { + // AppToast.showSuccessToast(message: "Address Added Successfully"); + // } + // Navigator.of(context).pop(addNewAddressRequestModel); + // }), + // ), + // ], + // ), + + PlacePicker( apiKey: GOOGLE_API_KEY, enableMyLocationButton: true, automaticallyImplyAppBarLeading: false, @@ -76,7 +161,7 @@ class _LocationPageState extends State { width: 500, borderRadius: BorderRadius.circular(0.0), child: state == SearchingState.Searching - ? SizedBox(height: 43,child: Center(child: CircularProgressIndicator())).insideContainer + ? SizedBox(height: 43, child: Center(child: CircularProgressIndicator())).insideContainer : DefaultButton(TranslationBase.of(context).addNewAddress, () async { AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( customer: Customer(addresses: [ @@ -84,11 +169,22 @@ class _LocationPageState extends State { address1: selectedPlace.formattedAddress, address2: selectedPlace.formattedAddress, customerAttributes: "", - city: "", createdOnUtc: "", - id: 0, - latLong: "${selectedPlace.geometry.location}", - email: "") + id: "0", + faxNumber: "", + phoneNumber: projectViewModel.user.mobileNumber, + countryId: 69, + latLong: "$latitude,$longitude", + email: projectViewModel.user.emailAddress) + // Addresses( + // address1: selectedPlace.formattedAddress, + // address2: selectedPlace.formattedAddress, + // customerAttributes: "", + // city: "", + // createdOnUtc: "", + // id: "0", + // latLong: "${selectedPlace.geometry.location}", + // email: "") ]), ); @@ -111,8 +207,7 @@ class _LocationPageState extends State { AppToast.showSuccessToast(message: "Address Added Successfully"); } Navigator.of(context).pop(addNewAddressRequestModel); - }).insideContainer - ); + }).insideContainer); }, initialPosition: LatLng(latitude, longitude), useCurrentLocation: showCurrentLocation, @@ -120,4 +215,19 @@ class _LocationPageState extends State { ), ); } + + setMap() { + setState(() { + _kGooglePlex = CameraPosition( + target: currentPostion, + zoom: 14.4746, + ); + appMap.moveTo(cameraPostion: _kGooglePlex); + }); + } + + void _updatePosition(CameraPosition _position) { + latitude = _position.target.latitude; + longitude = _position.target.longitude; + } } diff --git a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart index 10418bc2..a872acee 100644 --- a/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart +++ b/lib/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_tow_page.dart @@ -4,26 +4,25 @@ import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_request_model.dart'; import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/home_health_care_view_model.dart'; -import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/HomeHealthCare/NewHomeHealthCare/new_Home_health_care_step_three_page.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/reminder_dialog.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.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/app_map/google_huawei_map.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.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'; import 'package:flutter/material.dart'; +import 'package:geolocator/geolocator.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_place_picker/google_maps_place_picker.dart'; import 'package:permission_handler/permission_handler.dart'; -import 'package:provider/provider.dart'; -import 'package:diplomaticquarterapp/widgets/app_map/google_huawei_map.dart'; + import 'location_page.dart'; -import 'package:geolocator/geolocator.dart'; class NewHomeHealthCareStepTowPage extends StatefulWidget { final Function(PickResult) onPick; @@ -53,6 +52,7 @@ class _NewHomeHealthCareStepTowPageState extends State mapController = Completer(); + @override void initState() { appMap = AppMap( @@ -86,7 +86,7 @@ class _NewHomeHealthCareStepTowPageState extends State { SizedBox(height: 20), ], ) - // Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // mainAxisAlignment: MainAxisAlignment.spaceEvenly, - // children: [ - // AppText(TranslationBase.of(context).nationalID), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.idNumber, - // prefixIcon: Icon(Icons.chrome_reader_mode, color: Colors.red), - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).firstName), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.firstNameEn == '-' ? registerInfo.firstNameAr : registerInfo.firstNameEn, - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).middleName), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.secondNameEn == '-' ? registerInfo.secondNameAr : registerInfo.secondNameEn, - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).lastName), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.lastNameEn == '-' ? registerInfo.lastNameAr : registerInfo.lastNameEn, - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).gender), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.maritalStatusCode == 'U' - // ? 'Unknown' - // : registerInfo.maritalStatusCode == 'M' - // ? 'Male' - // : 'Female', - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).maritalStatus), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.maritalStatus, - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).nationality), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.nationalityCode, - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).mobileNumber), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerd_data.patientMobileNumber.toString(), - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // AppText(TranslationBase.of(context).dob), - // Container( - // margin: EdgeInsets.only(bottom: 10), - // child: TextFields( - // hintText: registerInfo.dateOfBirth, - // padding: EdgeInsets.only(top: 20, bottom: 20, left: 10, right: 10), - // readOnly: true, - // )), - // ], - // ) - : registerInfo != null && widget.page == 2 ? Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart b/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart index 5e55d537..dcc4b299 100644 --- a/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart +++ b/lib/pages/pharmacy/pharmacyAddresses/AddAddress.dart @@ -1,17 +1,27 @@ -import 'package:diplomaticquarterapp/core/model/pharmacies/Addresses.dart'; +import 'dart:async'; + import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart'; +import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart'; import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/PharmacyAddressesViewModel.dart'; +import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; +import 'package:diplomaticquarterapp/theme/colors.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/widgets/app_map/google_huawei_map.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/pickupLocation/PickupLocationFromMap.dart'; import 'package:flutter/material.dart'; +import 'package:geocoding/geocoding.dart'; import 'package:geolocator/geolocator.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_maps_place_picker/google_maps_place_picker.dart'; +import 'package:provider/provider.dart'; class AddAddressPage extends StatefulWidget { final AddressInfo editedAddress; - final Function(PickResult) onPick; + final Function(Placemark, String) onPick; AddAddressPage(this.editedAddress, this.onPick); @@ -22,10 +32,21 @@ class AddAddressPage extends StatefulWidget { class _AddAddressPageState extends State { double _latitude; double _longitude; + AppMap appMap; + AppSharedPreferences sharedPref = AppSharedPreferences(); + LatLng currentPostion; + Completer mapController = Completer(); + Placemark selectedPlace; + + static CameraPosition _kGooglePlex = CameraPosition( + target: LatLng(37.42796133580664, -122.085749655962), + zoom: 14.4746, + ); @override void initState() { super.initState(); + if (widget.editedAddress != null && widget.editedAddress.latLong != null && widget.editedAddress.latLong != "") { List latLng = widget.editedAddress.latLong.split(","); _latitude = double.parse(latLng[0]); @@ -33,13 +54,43 @@ class _AddAddressPageState extends State { } else { _getCurrentLocation(); } + // setState(() {}); + appMap = AppMap( + _kGooglePlex.toMap(), + onCameraMove: (camera) { + _updatePosition(camera); + }, + onMapCreated: () { + currentPostion = LatLng(_latitude, _longitude); + // latitude = widget.latitude; + // longitude = widget.longitude; + setMap(); + setState(() {}); + }, + onCameraIdle: () async { + List placemarks = await placemarkFromCoordinates(_latitude, _longitude); + selectedPlace = placemarks[0]; + print(selectedPlace); + }, + ); + } + + setMap() { setState(() { + _kGooglePlex = CameraPosition( + target: currentPostion, + zoom: 14.4746, + ); + appMap.moveTo(cameraPostion: _kGooglePlex); }); } - - + void _updatePosition(CameraPosition _position) { + _latitude = _position.target.latitude; + _longitude = _position.target.longitude; + print(_position); + } _getCurrentLocation() async { await Geolocator.getLastKnownPosition().then((value) { @@ -48,37 +99,93 @@ class _AddAddressPageState extends State { }).catchError((e) { _longitude = 0; _latitude = 0; - - }); } - @override Widget build(BuildContext context) { final mediaQuery = MediaQuery.of(context); final height = mediaQuery.size.height - 60 - mediaQuery.padding.top; + ProjectViewModel projectViewModel = Provider.of(context); return BaseView( builder: (_, model, wi) => AppScaffold( appBarTitle: TranslationBase.of(context).changeAddress, - isShowAppBar: false, + isShowAppBar: true, isPharmacy: true, backgroundColor: Colors.white, - body: Container( - height: height * 1, - child: PickupLocationFromMap( - latitude: _latitude??0, - longitude: _longitude??0, - isWithAppBar: false, - buttonColor: Color(0xFF5AB145), - buttonLabel: TranslationBase.of(context).save, - onPick: (value) { - widget.onPick(value); - }, - ), + showNewAppBarTitle: true, + showNewAppBar: true, + body: Column( + children: [ + Expanded( + child: Stack( + alignment: Alignment.center, + children: [ + if (appMap != null) appMap, + Container( + margin: EdgeInsets.only(bottom: 50.0), + child: Icon( + Icons.place, + color: CustomColors.accentColor, + size: 50, + ), + ), + ], + ), + ), + Container( + padding: const EdgeInsets.only(left: 20, right: 20, top: 14, bottom: 14), + child: DefaultButton(TranslationBase.of(context).addNewAddress, () async { + // AddNewAddressRequestModel addNewAddressRequestModel = new AddNewAddressRequestModel( + // customer: Customer(addresses: [ + // Addresses( + // address1: selectedPlace.name, + // address2: selectedPlace.street, + // customerAttributes: "", + // city: selectedPlace.locality, + // createdOnUtc: "", + // id: "0", + // faxNumber: "", + // phoneNumber: projectViewModel.user.mobileNumber, + // province: selectedPlace.locality, + // countryId: 69, + // latLong: "$_latitude,$_longitude", + // country: selectedPlace.country, + // zipPostalCode: selectedPlace.postalCode, + // email: projectViewModel.user.emailAddress) + // ]), + // ); + + widget.onPick(selectedPlace, "$_latitude,$_longitude"); + Navigator.of(context).pop(); + + // await model.addAddressInfo(addNewAddressRequestModel: addNewAddressRequestModel); + // if (model.state == ViewState.ErrorLocal) { + // Utils.showErrorToast(model.error); + // } else { + // AppToast.showSuccessToast(message: "Address Added Successfully"); + // } + // Navigator.of(context).pop(addNewAddressRequestModel); + }), + ), + ], ), - ), - ); + + // Container( + // height: height * 1, + // child: PickupLocationFromMap( + // latitude: _latitude ?? 0, + // longitude: _longitude ?? 0, + // isWithAppBar: false, + // buttonColor: Color(0xFF5AB145), + // buttonLabel: TranslationBase.of(context).save, + // onPick: (value) { + // widget.onPick(value); + // }, + // ), + ), + ); + // ); } } diff --git a/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart b/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart index 933824db..3d811514 100644 --- a/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart +++ b/lib/pages/pharmacy/pharmacyAddresses/PharmacyAddresses.dart @@ -39,8 +39,8 @@ class _PharmacyAddressesState extends State { FadePage( page: AddAddressPage( address, - (pickResult) async { - await model.addEditAddress(pickResult, address); + (pickResult, latLong) async { + await model.addEditAddress(pickResult, address, latLong: latLong); }, ), ), diff --git a/lib/widgets/app_map/google_huawei_map.dart b/lib/widgets/app_map/google_huawei_map.dart index ff9efeff..0e9b4936 100644 --- a/lib/widgets/app_map/google_huawei_map.dart +++ b/lib/widgets/app_map/google_huawei_map.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:diplomaticquarterapp/services/pharmacy_services/writeReview_service.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hms_gms_availability/flutter_hms_gms_availability.dart'; @@ -12,8 +13,9 @@ class AppMap extends StatefulWidget { AppMapState _state; Function onMapCreated; + Function onCameraIdle; - AppMap(this.initialCamera, {this.onCameraMove, this.onMapCreated}); + AppMap(this.initialCamera, {this.onCameraMove, this.onMapCreated, this.onCameraIdle}); @override State createState() => _state = AppMapState(); @@ -69,6 +71,7 @@ class AppMapState extends State { _googleMapControllerComp.complete(controller); widget.onMapCreated(); }, + onCameraIdle: widget.onCameraIdle, ); }