This commit is contained in:
Felipe
2023-11-14 17:20:12 -05:00
parent 26780112d8
commit a4f631497d
3 changed files with 725 additions and 1332 deletions
+59 -27
View File
@@ -47,7 +47,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
Completer<GoogleMapController>();
static const LatLng _pGooglePlex = LatLng(7.080486, -73.087447);
static const LatLng _pApplePark = LatLng(7.074710, -73.090807);
LatLng? _currentP;
Map<PolylineId, Polyline> polylines = {};
@@ -90,15 +89,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
_getAppVersion();
getLocationUpdates().then(
(_) => {
getPolylinePoints().then(
(coordinates) => {
generatePolyLineFromPoints(coordinates),
},
),
},
);
getLocationUpdates();
if (settings == null) {
SettingModel.getSettings().then(
@@ -210,16 +201,6 @@ class _ServiceScreenState extends State<ServiceScreen> {
icon: BitmapDescriptor.defaultMarker,
position: _currentP!,
),
// const Marker(
// markerId: MarkerId("_sourceLocation"),
// icon: BitmapDescriptor.defaultMarker,
// position: _pGooglePlex,
// ),
// const Marker(
// markerId: MarkerId("_destionationLocation"),
// icon: BitmapDescriptor.defaultMarker,
// position: _pApplePark,
// ),
},
polylines: Set<Polyline>.of(polylines.values),
onCameraIdle: () {
@@ -269,6 +250,17 @@ class _ServiceScreenState extends State<ServiceScreen> {
},
),
),
const Positioned(
bottom: 25,
right: 0,
left: 0,
top: 0,
child: Icon(
Icons.location_on,
size: 40,
color: Color(0xFFFF0000),
),
),
Positioned(
top: 10,
right: 20,
@@ -347,6 +339,31 @@ class _ServiceScreenState extends State<ServiceScreen> {
controller: _profesionalController,
readOnly: true,
onTap: () async {
if (_currentP == null) {
try {
Position position = await _determinePosition();
if (mounted) {
setState(() {
_currentP = LatLng(
position.latitude,
position.longitude,
);
});
_animateCameraToPosition(_currentP!);
}
} catch (e) {
WarningSnackbar.show(
title: 'Ubicación desactivada',
message:
'Por favor activa la ubicacion de tu telefono para solicitar un servicio.',
);
}
return;
}
final dynamic datos = await Navigator.push(
context,
CupertinoPageRoute(
@@ -386,15 +403,29 @@ class _ServiceScreenState extends State<ServiceScreen> {
_locacionController.text =
profesional.realAddress;
LatLng professionalCoordinates = LatLng(
professionalLatitude!,
professionalLongitude!);
if (professionalLatitude != null &&
professionalLatitude != 0 &&
professionalLongitude != null &&
professionalLongitude != 0) {
_animateCameraToPosition(LatLng(
professionalLatitude!,
professionalLongitude!,
));
_animateCameraToPosition(
LatLng(professionalLatitude!,
professionalLongitude!),
);
getPolylinePoints(
_currentP!, professionalCoordinates)
.then(
(coordinates) => {
generatePolyLineFromPoints(coordinates),
},
);
}
} else {
polylines.clear();
}
});
}
@@ -655,13 +686,14 @@ class _ServiceScreenState extends State<ServiceScreen> {
});
}
Future<List<LatLng>> getPolylinePoints() async {
Future<List<LatLng>> getPolylinePoints(
LatLng originP, LatLng destinationP) async {
List<LatLng> polylineCoordinates = [];
PolylinePoints polylinePoints = PolylinePoints();
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
GOOGLE_MAPS_API_KEY,
PointLatLng(_pGooglePlex.latitude, _pGooglePlex.longitude),
PointLatLng(_pApplePark.latitude, _pApplePark.longitude),
PointLatLng(originP.latitude, originP.longitude),
PointLatLng(destinationP.latitude, destinationP.longitude),
travelMode: TravelMode.driving,
);
if (result.points.isNotEmpty) {