second step from location fixes

merge-update-with-lab-changes
Elham Rababah 5 years ago
parent 7aa7af6de7
commit ed56476d81

@ -16,9 +16,10 @@ class HomeHealthCareService extends BaseService {
List<GetHHCAllPresOrdersResponseModel> hhcAllPresOrdersList = List();
List<GetOrderDetailByOrderIDResponseModel> hhcAllOrderDetail = List();
List<AddressInfo> addressesList = List();
bool isOrderUpdated;
CustomerInfo customerInfo;
Future getHHCAllServices(
HHCGetAllServicesRequestModel hHCGetAllServicesRequestModel) async {
hasError = false;
@ -91,4 +92,166 @@ class HomeHealthCareService extends BaseService {
super.error = error;
}, body: order.toJson());
}
Future getCustomerAddresses() async {
Map<String, String> queryParams = {
'fields':'addresses'
};
hasError = false;
await baseAppClient.get("https://mdlaboratories.com/exacartapi/api/Customers/${customerInfo.customerId}",
onSuccess: (dynamic response, int statusCode) {
addressesList.clear();
response["customers"][0]["addresses"].forEach((data) {
addressesList
.add(AddressInfo.fromJson(data));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, queryParams: queryParams, isExternal: true);
}
Future getCustomerInfo() async {
Map<String, String> queryParams = {
'FileNumber':'${user.patientID}'
};
hasError = false;
await baseAppClient.get("https://mdlaboratories.com/exacartapi/api/VerifyCustomer",
onSuccess: (dynamic response, int statusCode) {
customerInfo= CustomerInfo.fromJson(response);
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, queryParams: queryParams, isExternal: true);
}
}
class CustomerInfo {
bool isRegistered;
String userName;
Null password;
String email;
Null errorMessage;
String mobileNumber;
int customerId;
CustomerInfo(
{this.isRegistered,
this.userName,
this.password,
this.email,
this.errorMessage,
this.mobileNumber,
this.customerId});
CustomerInfo.fromJson(Map<String, dynamic> json) {
isRegistered = json['IsRegistered'];
userName = json['UserName'];
password = json['Password'];
email = json['Email'];
errorMessage = json['ErrorMessage'];
mobileNumber = json['MobileNumber'];
customerId = json['CustomerId'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['IsRegistered'] = this.isRegistered;
data['UserName'] = this.userName;
data['Password'] = this.password;
data['Email'] = this.email;
data['ErrorMessage'] = this.errorMessage;
data['MobileNumber'] = this.mobileNumber;
data['CustomerId'] = this.customerId;
return data;
}
}
class AddressInfo {
String id;
String firstName;
String lastName;
String email;
Null company;
int countryId;
String country;
Null stateProvinceId;
String city;
String address1;
String address2;
String zipPostalCode;
String phoneNumber;
Null faxNumber;
String customerAttributes;
String createdOnUtc;
Null province;
String latLong;
AddressInfo(
{this.id,
this.firstName,
this.lastName,
this.email,
this.company,
this.countryId,
this.country,
this.stateProvinceId,
this.city,
this.address1,
this.address2,
this.zipPostalCode,
this.phoneNumber,
this.faxNumber,
this.customerAttributes,
this.createdOnUtc,
this.province,
this.latLong});
AddressInfo.fromJson(Map<String, dynamic> json) {
id = json['id'];
firstName = json['first_name'];
lastName = json['last_name'];
email = json['email'];
company = json['company'];
countryId = json['country_id'];
country = json['country'];
stateProvinceId = json['state_province_id'];
city = json['city'];
address1 = json['address1'];
address2 = json['address2'];
zipPostalCode = json['zip_postal_code'];
phoneNumber = json['phone_number'];
faxNumber = json['fax_number'];
customerAttributes = json['customer_attributes'];
createdOnUtc = json['created_on_utc'];
province = json['province'];
latLong = json['lat_long'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['first_name'] = this.firstName;
data['last_name'] = this.lastName;
data['email'] = this.email;
data['company'] = this.company;
data['country_id'] = this.countryId;
data['country'] = this.country;
data['state_province_id'] = this.stateProvinceId;
data['city'] = this.city;
data['address1'] = this.address1;
data['address2'] = this.address2;
data['zip_postal_code'] = this.zipPostalCode;
data['phone_number'] = this.phoneNumber;
data['fax_number'] = this.faxNumber;
data['customer_attributes'] = this.customerAttributes;
data['created_on_utc'] = this.createdOnUtc;
data['province'] = this.province;
data['lat_long'] = this.latLong;
return data;
}
}

@ -166,8 +166,14 @@ class BaseAppClient {
get(String endPoint,
{Function(dynamic response, int statusCode) onSuccess,
Function(String error, int statusCode) onFailure,
Map<String, String> queryParams}) async {
String url = BASE_URL + endPoint;
Map<String, String> queryParams,
bool isExternal = false}) async {
String url;
if (isExternal) {
url = endPoint;
} else {
url = BASE_URL + endPoint;
}
if (queryParams != null) {
String queryString = Uri(queryParameters: queryParams).query;
url += '?' + queryString;
@ -176,9 +182,11 @@ class BaseAppClient {
print("URL : $url");
if (await Utils.checkConnection()) {
final response = await http.get(url.trim(), headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
final response = await http.get(
url.trim(),
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},);
final int statusCode = response.statusCode;
print("statusCode :$statusCode");

@ -20,6 +20,10 @@ class HomeHealthCareViewModel extends BaseViewModel {
List<HHCGetAllServicesResponseModel> get hhcAllServicesList =>
_homeHealthCareService.hhcAllServicesList;
List<AddressInfo> get addressesList =>
_homeHealthCareService.addressesList;
List<GetHHCAllPresOrdersResponseModel> get hhcAllPresOrders =>
_homeHealthCareService.hhcAllPresOrdersList;
@ -93,5 +97,29 @@ class HomeHealthCareViewModel extends BaseViewModel {
}
Future getCustomerAddresses() async {
setState(ViewState.Busy);
await _homeHealthCareService.getCustomerAddresses(
);
if (_homeHealthCareService.hasError) {
error = _homeHealthCareService.error;
setState(ViewState.ErrorLocal);
} else {
setState(ViewState.Idle);
}
}
Future getCustomerInfo() async {
setState(ViewState.Busy);
await _homeHealthCareService.getCustomerInfo(
);
if (_homeHealthCareService.hasError) {
error = _homeHealthCareService.error;
setState(ViewState.ErrorLocal);
} else {
await getCustomerAddresses();
}
}
}

@ -0,0 +1,140 @@
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/get_all_cities_response_model.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/home_health_care_service.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// ignore: must_be_immutable
class SelectLocationDialog extends StatefulWidget {
final List<AddressInfo> addresses;
final Function(AddressInfo) onValueSelected;
AddressInfo selectedAddress;
SelectLocationDialog(
{Key key, this.addresses, this.onValueSelected, this.selectedAddress});
@override
_SelectLocationDialogState createState() => _SelectLocationDialogState();
}
class _SelectLocationDialogState extends State<SelectLocationDialog> {
@override
void initState() {
super.initState();
widget.selectedAddress = widget.selectedAddress ?? widget.addresses[0];
}
@override
Widget build(BuildContext context) {
return SimpleDialog(
title: Texts("sdsdsd"),
children: [
Column(
children: [
Container(
height: 150,
child: SingleChildScrollView(
child: Column(
children: [
Divider(),
...List.generate(
widget.addresses.length,
(index) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 2,
),
Row(
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () {
setState(() {
widget.selectedAddress = widget.addresses[index];
});
},
child: ListTile(
title: Text(widget.addresses[index].address1),
leading: Radio(
value: widget.addresses[index],
groupValue: widget.selectedAddress,
activeColor: Colors.red[800],
onChanged: (value) {
setState(() {
widget.selectedAddress = value;
});
},
),
),
),
)
],
),
SizedBox(
height: 5.0,
),
],
),
),
SizedBox(
height: 5.0,
),
],
),
),
),
Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
flex: 1,
child: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Center(
child: Texts(
TranslationBase.of(context).cancel.toUpperCase(),
color: Colors.red,
),
),
),
),
),
),
Container(
width: 1,
height: 30,
color: Colors.grey[500],
),
Expanded(
flex: 1,
child: InkWell(
onTap: () {
widget.onValueSelected(widget.selectedAddress);
Navigator.pop(context);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Texts(
TranslationBase.of(context).ok,
fontWeight: FontWeight.w400,
)),
),
),
),
],
)
],
)
],
);
}
}

@ -0,0 +1,108 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_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/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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 LocationPage extends StatefulWidget {
final Function(PickResult) onPick;
final double latitude;
final double longitude;
const LocationPage(
{Key key,
this.onPick,
this.latitude,
this.longitude,
})
: super(key: key);
@override
_LocationPageState createState() =>
_LocationPageState();
}
class _LocationPageState
extends State<LocationPage> {
double latitude = 0;
double longitude = 0;
@override
void initState() {
latitude = widget.latitude;
longitude = widget.longitude;
super.initState();
}
@override
Widget build(BuildContext context) {
ProjectViewModel projectViewModel = Provider.of(context);
return AppScaffold(
isShowDecPage: false,
isShowAppBar: true,
body: PlacePicker(
apiKey: GOOGLE_API_KEY,
enableMyLocationButton: true,
automaticallyImplyAppBarLeading: false,
autocompleteOnTrailingWhitespace: true,
selectInitialPosition: true,
autocompleteLanguage: projectViewModel.currentLanguage,
enableMapTypeButton: true,
searchForInitialValue: false,
onPlacePicked: (PickResult result) {
print(result.adrAddress);
},
selectedPlaceWidgetBuilder:
(_, selectedPlace, state, isSearchBarFocused) {
print("state: $state, isSearchBarFocused: $isSearchBarFocused");
return isSearchBarFocused
? Container()
: FloatingCard(
bottomPosition: 0.0,
leftPosition: 0.0,
rightPosition: 0.0,
width: 500,
borderRadius: BorderRadius.circular(12.0),
child: state == SearchingState.Searching
? Center(child: CircularProgressIndicator())
: Container(
margin: EdgeInsets.all(12),
child: Column(
children: [
SecondaryButton(
color: Colors.grey[800],
textColor: Colors.white,
onTap: () {
print(selectedPlace);
// setState(() {
// widget.patientERInsertPresOrderRequestModel
// .latitude =
// selectedPlace.geometry.location.lat;
// widget.patientERInsertPresOrderRequestModel
// .longitude =
// selectedPlace.geometry.location.lng;
// });
},
label: " Add New Address ",
),
],
),
),
);
},
initialPosition: LatLng(latitude, longitude),
useCurrentLocation: false,
),
);
}
}

@ -138,9 +138,11 @@ class _NewHomeHealthCareStepOnePageState extends State<NewHomeHealthCareStepOneP
.widget
.patientERInsertPresOrderRequestModel
.patientERHHCInsertServicesList
.length == 0,
.length == 0 || widget.model.state == ViewState.BusyLocal,
color: Colors.grey[800],
onTap: (){
loading:widget.model.state == ViewState.BusyLocal,
onTap: () async{
await widget.model.getCustomerInfo();
widget.changePageViewIndex(1);
},
textColor: Theme.of(context).backgroundColor),

@ -1,17 +1,20 @@
import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_request_model.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/home_health_care_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/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/HomeHealthCare/Dialog/select_location_dialog.dart';
import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/close_back.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_place_picker/google_maps_place_picker.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';
import 'location_page.dart';
class NewHomeHealthCareStepTowPage extends StatefulWidget {
final Function(PickResult) onPick;
final double latitude;
@ -40,73 +43,159 @@ class _NewHomeHealthCareStepTowPageState
extends State<NewHomeHealthCareStepTowPage> {
double latitude = 0;
double longitude = 0;
AddressInfo _selectedAddress;
@override
void initState() {
print(widget.model.addressesList);
if (widget.patientERInsertPresOrderRequestModel.latitude == null) {
latitude = widget.latitude;
longitude = widget.longitude;
setLatitudeAndLongitude();
} else {
latitude = widget.patientERInsertPresOrderRequestModel.latitude;
longitude = widget.patientERInsertPresOrderRequestModel.longitude;
}
super.initState();
}
setLatitudeAndLongitude({bool isSetState = false, String latLong}) {
if (latLong == null)
latLong = widget.model.addressesList[widget.model.addressesList
.length - 1].latLong;
List latLongArr = latLong.split(',');
latitude = double.parse(latLongArr[0]);
longitude = double.parse(latLongArr[1]);
}
@override
Widget build(BuildContext context) {
ProjectViewModel projectViewModel = Provider.of(context);
return AppScaffold(
isShowDecPage: false,
body: PlacePicker(
apiKey: GOOGLE_API_KEY,
enableMyLocationButton: true,
automaticallyImplyAppBarLeading: false,
autocompleteOnTrailingWhitespace: true,
selectInitialPosition: true,
autocompleteLanguage: projectViewModel.currentLanguage,
enableMapTypeButton: true,
onPlacePicked: (PickResult result) {
print(result.adrAddress);
widget.changePageViewIndex(3);
},
selectedPlaceWidgetBuilder:
(_, selectedPlace, state, isSearchBarFocused) {
print("state: $state, isSearchBarFocused: $isSearchBarFocused");
return isSearchBarFocused
? Container()
: FloatingCard(
bottomPosition: 0.0,
leftPosition: 0.0,
rightPosition: 0.0,
width: 500,
borderRadius: BorderRadius.circular(12.0),
child: state == SearchingState.Searching
? Center(child: CircularProgressIndicator())
: Container(
margin: EdgeInsets.all(12),
child: SecondaryButton(
color: Colors.grey[800],
textColor: Colors.white,
onTap: () {
setState(() {
widget.patientERInsertPresOrderRequestModel
.latitude =
selectedPlace.geometry.location.lat;
widget.patientERInsertPresOrderRequestModel
.longitude =
selectedPlace.geometry.location.lng;
});
widget.changePageViewIndex(3);
},
label: TranslationBase.of(context).next,
),
),
);
body: Stack(
children: [
PlacePicker(
apiKey: GOOGLE_API_KEY,
enableMyLocationButton: true,
automaticallyImplyAppBarLeading: false,
autocompleteOnTrailingWhitespace: true,
selectInitialPosition: true,
autocompleteLanguage: projectViewModel.currentLanguage,
enableMapTypeButton: true,
searchForInitialValue: false,
onPlacePicked: (PickResult result) {
print(result.adrAddress);
widget.changePageViewIndex(3);
},
selectedPlaceWidgetBuilder:
(_, selectedPlace, state, isSearchBarFocused) {
print("state: $state, isSearchBarFocused: $isSearchBarFocused");
return isSearchBarFocused
? Container()
: FloatingCard(
bottomPosition: 0.0,
leftPosition: 0.0,
rightPosition: 0.0,
width: 500,
borderRadius: BorderRadius.circular(12.0),
child: state == SearchingState.Searching
? Center(child: CircularProgressIndicator())
: Container(
margin: EdgeInsets.all(12),
child: Column(
children: [
SecondaryButton(
color: Colors.grey[800],
textColor: Colors.white,
onTap: () {
Navigator.pushReplacement(
context, MaterialPageRoute(
builder: (BuildContext context) =>
LocationPage(latitude: latitude,
longitude: longitude,)));
},
label: " Add New Address ",
),
SizedBox(height: 10,),
SecondaryButton(
color: Colors.red[800],
textColor: Colors.white,
onTap: () {
setState(() {
widget.patientERInsertPresOrderRequestModel
.latitude =
selectedPlace.geometry.location.lat;
widget.patientERInsertPresOrderRequestModel
.longitude =
selectedPlace.geometry.location.lng;
});
widget.changePageViewIndex(3);
},
label: " Continue ",
),
],
),
),
);
},
initialPosition: LatLng(latitude, longitude),
useCurrentLocation: false,
),
Container(
child: InkWell(
onTap: () =>
confirmSelectLocationDialog(widget.model.addressesList),
child: Container(
padding: EdgeInsets.all(10),
width: double.infinity,
// height: 65,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(child: Texts(getAddressName(), fontSize: 14,),),
Icon(Icons.arrow_drop_down)
],
),
),
),
height: 56, width: double.infinity, color: Theme
.of(context)
.scaffoldBackgroundColor,
)
],
),
);
}
void confirmSelectLocationDialog(List<AddressInfo> addresses) {
showDialog(
context: context,
child: SelectLocationDialog(
addresses: addresses,
selectedAddress: _selectedAddress
,
onValueSelected: (value) {
setLatitudeAndLongitude(latLong: value.latLong);
setState(() {
_selectedAddress = value;
});
},
initialPosition: LatLng(latitude, longitude),
useCurrentLocation: true,
),
);
}
String getAddressName() {
if (_selectedAddress != null)
return _selectedAddress.address1;
else
return "Select Address" /*TranslationBase.of(context).selectHospital*/;
}
}

Loading…
Cancel
Save