Code refractoring

This commit is contained in:
Benjamin Ramhorst 2022-02-14 17:03:32 +00:00
parent 6464161b34
commit c929242804
3 changed files with 13 additions and 32 deletions

View file

@ -4,9 +4,8 @@ import 'package:http/http.dart' as http;
import 'package:leg_barkr_app/model/latitude_longitude.dart'; import 'package:leg_barkr_app/model/latitude_longitude.dart';
import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints; import 'package:leg_barkr_app/utils/endpoints.dart' as Endpoints;
class MapService{ class MapService{
Future<LatitudeLongitude> getLastLocation(deviceId) async { Future<LatitudeLongitude> getPetLastLocation(deviceId) async {
final response = await http.get( final response = await http.get(
Uri.parse(Endpoints.getLastLocation), Uri.parse(Endpoints.getLastLocation),
headers: <String, String>{ headers: <String, String>{
@ -14,7 +13,6 @@ class MapService{
'deviceid': deviceId, 'deviceid': deviceId,
}, },
); );
print(response.body);
return LatitudeLongitude.fromJson(jsonDecode(response.body)); return LatitudeLongitude.fromJson(jsonDecode(response.body));
} }

View file

@ -1,7 +0,0 @@
import 'package:flutter/material.dart';
class Resources {
static final Color primaryColour = Colors.green;
static final Color primaryAccentColour = Colors.greenAccent;
}

View file

@ -15,32 +15,22 @@ class _MapPageState extends State<MapPage> {
Future<void> _onMapCreated(GoogleMapController controller) async { Future<void> _onMapCreated(GoogleMapController controller) async {
_mapController = controller; _mapController = controller;
final lastLocation = await MapService().getLastLocation("132-567-001"); // change this. final lastLocation = await MapService().getPetLastLocation("132-567-001"); // change this.
final myLocation = await MapService().getMyLocation(); final myLocation = await MapService().getMyLocation();
print(myLocation.latitude);
setState(() { setState(() {
_markers.clear(); _markers.clear();
if (lastLocation.latitude!=-1.0 && lastLocation.latitude!=-1.0){
final petMarker = Marker( final petMarker = Marker(
markerId: MarkerId("pet_location"), markerId: MarkerId("pet_location"),
position: LatLng(lastLocation.latitude, lastLocation.longitude), position: LatLng(lastLocation.latitude, lastLocation.longitude),
infoWindow: InfoWindow( infoWindow: InfoWindow(title: "Pet location"));
title: "Pet location",
),
);
_markers["pet_location"] = petMarker;
}
if (myLocation.latitude!=-1.0 && myLocation.longitude!=-1.0){
final myMarker = Marker( final myMarker = Marker(
markerId: MarkerId("my_location"), markerId: MarkerId("my_location"),
position: LatLng(myLocation.latitude, myLocation.longitude), position: LatLng(myLocation.latitude, myLocation.longitude),
infoWindow: InfoWindow( infoWindow: InfoWindow(title: "My location"));
title: "My location",
), _markers["pet_location"] = petMarker;
);
_markers["my_location"] = myMarker; _markers["my_location"] = myMarker;
}
_mapController.animateCamera(CameraUpdate.newLatLng(LatLng(myLocation.latitude, myLocation.longitude))); _mapController.animateCamera(CameraUpdate.newLatLng(LatLng(myLocation.latitude, myLocation.longitude)));
}); });
} }