You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/core/service/hospital_service.dart

46 lines
1.4 KiB
Dart

import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
4 years ago
import 'package:geolocator/geolocator.dart';
class HospitalService extends BaseService {
List<HospitalsModel> _hospitals = List();
List<HospitalsModel> get hospitals => _hospitals;
4 years ago
double _latitude;
double _longitude;
_getCurrentLocation() async {
await Geolocator.getLastKnownPosition().then((value) {
4 years ago
_latitude = value.latitude;
_longitude = value.longitude;
}).catchError((e) {
_longitude = 0;
_latitude = 0;
});
}
Future getHospitals({bool isResBasedOnLoc = true}) async {
if(isResBasedOnLoc)
4 years ago
await _getCurrentLocation();
Map<String, dynamic> body = Map();
body['Latitude'] = isResBasedOnLoc?_latitude:0;
body['Longitude'] = isResBasedOnLoc?_longitude:0;
body['IsOnlineCheckIn'] = isResBasedOnLoc;
4 years ago
body['PatientOutSA'] = 0;
4 years ago
await baseAppClient.post(GET_PROJECT,
onSuccess: (dynamic response, int statusCode) {
4 years ago
_hospitals.clear();
response['ListProject'].forEach((hospital) {
_hospitals.add(HospitalsModel.fromJson(hospital));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
4 years ago
}, body: body);
}
4 years ago
}