3/21/1
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:math' show cos;
|
||||
import 'package:SEFER/constant/table_names.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -49,10 +51,10 @@ class MapDriverController extends GetxController {
|
||||
late String duration;
|
||||
late String totalCost;
|
||||
late String distance;
|
||||
late String name;
|
||||
late String email;
|
||||
late String passengerName;
|
||||
late String passengerEmail;
|
||||
late String totalPassenger;
|
||||
late String phone;
|
||||
late String passengerPhone;
|
||||
late String rideId;
|
||||
late String isHaveSteps;
|
||||
late String paymentAmount;
|
||||
@@ -72,6 +74,7 @@ class MapDriverController extends GetxController {
|
||||
bool isdriverWaitTimeEnd = false;
|
||||
bool isRideFinished = false;
|
||||
bool isRideStarted = false;
|
||||
bool isPriceWindow = false;
|
||||
double passengerInfoWindow = Get.height * .39;
|
||||
double driverEndPage = 100;
|
||||
double progress = 0;
|
||||
@@ -177,29 +180,29 @@ class MapDriverController extends GetxController {
|
||||
}
|
||||
|
||||
void startTimerToShowPassengerInfoWindowFromDriver() async {
|
||||
for (int i = 0;
|
||||
i <= progressTimerToShowPassengerInfoWindowFromDriver;
|
||||
i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (canelString != 'Cancel') {
|
||||
cancelCheckRidefromPassenger();
|
||||
progress = i / progressTimerToShowPassengerInfoWindowFromDriver;
|
||||
remainingTimeToShowPassengerInfoWindowFromDriver =
|
||||
progressTimerToShowPassengerInfoWindowFromDriver - i;
|
||||
// for (int i = 0;
|
||||
// i <= progressTimerToShowPassengerInfoWindowFromDriver;
|
||||
// i++) {
|
||||
// await Future.delayed(const Duration(seconds: 1));
|
||||
// if (canelString != 'Cancel') {
|
||||
// cancelCheckRidefromPassenger();
|
||||
// progress = i / progressTimerToShowPassengerInfoWindowFromDriver;
|
||||
// remainingTimeToShowPassengerInfoWindowFromDriver =
|
||||
// progressTimerToShowPassengerInfoWindowFromDriver - i;
|
||||
|
||||
if (remainingTimeToShowPassengerInfoWindowFromDriver == 0) {
|
||||
isPassengerInfoWindow = true;
|
||||
print(isPassengerInfoWindow);
|
||||
update();
|
||||
startTimerToShowDriverToPassengerDuration();
|
||||
}
|
||||
print(isPassengerInfoWindow);
|
||||
print(remainingTimeToShowPassengerInfoWindowFromDriver);
|
||||
update();
|
||||
} else {
|
||||
Get.off(HomeCaptain());
|
||||
}
|
||||
}
|
||||
// if (remainingTimeToShowPassengerInfoWindowFromDriver == 0) {
|
||||
isPassengerInfoWindow = true;
|
||||
// print(isPassengerInfoWindow);
|
||||
update();
|
||||
startTimerToShowDriverToPassengerDuration();
|
||||
// }
|
||||
// print(isPassengerInfoWindow);
|
||||
// print(remainingTimeToShowPassengerInfoWindowFromDriver);
|
||||
// update();
|
||||
// } else {
|
||||
// Get.off(HomeCaptain());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
String stringRemainingTimeToPassenger = '';
|
||||
@@ -312,6 +315,16 @@ class MapDriverController extends GetxController {
|
||||
|
||||
Position? currentPosition;
|
||||
|
||||
calculateDistanceAndTimeSPEEDOMETER() async {
|
||||
/* todo
|
||||
save to sql
|
||||
calculate distance and duration
|
||||
get from sql
|
||||
update ui for totla results
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void startRideFromDriver() async {
|
||||
double _distance =
|
||||
await calculateDistanseBetweenDriverAndPassengerLocation();
|
||||
@@ -371,14 +384,34 @@ class MapDriverController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
calcualateDistsanceInMetet(LatLng prev, LatLng current) async {
|
||||
double distance2 = Geolocator.distanceBetween(
|
||||
prev.latitude,
|
||||
prev.longitude,
|
||||
current.latitude,
|
||||
current.longitude,
|
||||
);
|
||||
return distance2;
|
||||
}
|
||||
|
||||
double speedoMeter = 0;
|
||||
void updateLocation() async {
|
||||
StreamSubscription<Position>? locationSubscription;
|
||||
|
||||
try {
|
||||
LatLng? latestPosition; // Initialize outside the loop
|
||||
for (var i = 0; i < remainingTimeTimerRideBegin; i++) {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
locationSubscription =
|
||||
Geolocator.getPositionStream().listen((Position position) {
|
||||
latestPosition = position as LatLng?; // Update latest position
|
||||
|
||||
// Calculate distance using the latest position
|
||||
double distance = calcualateDistsanceInMetet(
|
||||
currentPosition as LatLng, latestPosition!);
|
||||
speedoMeter = distance + speedoMeter;
|
||||
print('distance is $distance');
|
||||
print('SpedoMeter is $speedoMeter');
|
||||
currentPosition = position;
|
||||
// Update camera position on the map
|
||||
mapController!.animateCamera(
|
||||
@@ -466,6 +499,7 @@ class MapDriverController extends GetxController {
|
||||
// if (distanceToDestination < 50) {
|
||||
isRideFinished = true;
|
||||
isRideStarted = false;
|
||||
isPriceWindow = false;
|
||||
|
||||
box.write(BoxName.statusDriverLocation, 'off');
|
||||
// changeRideToBeginToPassenger();
|
||||
@@ -500,11 +534,7 @@ class MapDriverController extends GetxController {
|
||||
box.read(BoxName.tokenDriver),
|
||||
],
|
||||
);
|
||||
Get.to(() => RatePassenger(), arguments: {
|
||||
'rideId': rideId,
|
||||
'passengerId': passengerId,
|
||||
'driverId': driverId
|
||||
});
|
||||
|
||||
// } else {
|
||||
// Get.defaultDialog(
|
||||
// title: 'You don\'t arrive destenation yet .'.tr,
|
||||
@@ -516,7 +546,7 @@ class MapDriverController extends GetxController {
|
||||
// }));
|
||||
// }
|
||||
// add wallet from passenger from driver
|
||||
|
||||
Get.to(() => RatePassenger());
|
||||
// Get.back();
|
||||
}
|
||||
|
||||
@@ -576,19 +606,76 @@ class MapDriverController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void updateMarker() {
|
||||
double calculateDistanceBetweenLocations(LatLng start, LatLng end) {
|
||||
double startLat = start.latitude * math.pi / 180;
|
||||
double startLon = start.longitude * math.pi / 180;
|
||||
double endLat = end.latitude * math.pi / 180;
|
||||
double endLon = end.longitude * math.pi / 180;
|
||||
|
||||
double dLat = endLat - startLat;
|
||||
double dLon = endLon - startLon;
|
||||
|
||||
double a = math.pow(math.sin(dLat / 2), 2) +
|
||||
math.cos(startLat) * math.cos(endLat) * math.pow(math.sin(dLon / 2), 2);
|
||||
double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));
|
||||
double distance = 6371000 * c; // Distance in meters
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
double calculateAngleBetweenLocations(LatLng start, LatLng end) {
|
||||
double startLat = start.latitude * math.pi / 180;
|
||||
double startLon = start.longitude * math.pi / 180;
|
||||
double endLat = end.latitude * math.pi / 180;
|
||||
double endLon = end.longitude * math.pi / 180;
|
||||
|
||||
double dLon = endLon - startLon;
|
||||
|
||||
double y = math.sin(dLon) * cos(endLat);
|
||||
double x = cos(startLat) * math.sin(endLat) -
|
||||
math.sin(startLat) * cos(endLat) * cos(dLon);
|
||||
|
||||
double angle = math.atan2(y, x);
|
||||
double angleDegrees = angle * 180 / math.pi;
|
||||
|
||||
return angleDegrees;
|
||||
}
|
||||
|
||||
double recentDistanceToDash = 0;
|
||||
double recentAngelToMarker = 0;
|
||||
void updateMarker() async {
|
||||
// Remove the existing marker with the ID `MyLocation`.
|
||||
markers.remove(MarkerId('MyLocation'.tr));
|
||||
markers.remove(MarkerId('MyLocation'));
|
||||
|
||||
// Add a new marker with the ID `MyLocation` at the current location of the user.
|
||||
LocationController locationController = Get.find<LocationController>();
|
||||
myLocation = locationController.myLocation;
|
||||
final previousLocationOfDrivers = await sql.getCustomQuery(
|
||||
'Select * from ${TableName.carLocations} where order_id =$rideId Order by created_at DESC limit 1');
|
||||
|
||||
//get from sql
|
||||
if (previousLocationOfDrivers.isNotEmpty) {
|
||||
var lat = double.parse(previousLocationOfDrivers[0]['lat']);
|
||||
var lng = double.parse(previousLocationOfDrivers[0]['lng']);
|
||||
LatLng prev = LatLng(lat, lng);
|
||||
recentAngelToMarker = calculateAngleBetweenLocations(prev, myLocation);
|
||||
recentDistanceToDash =
|
||||
calculateDistanceBetweenLocations(prev, myLocation);
|
||||
}
|
||||
sql.insertData({
|
||||
'order_id': rideId,
|
||||
'created_at': DateTime.now().microsecondsSinceEpoch.toString(),
|
||||
'lat': myLocation.latitude.toString(),
|
||||
'lng': myLocation.longitude.toString(),
|
||||
}, TableName.rideLocation);
|
||||
|
||||
markers.add(
|
||||
Marker(
|
||||
markerId: MarkerId('MyLocation'.tr),
|
||||
position: locationController.myLocation,
|
||||
draggable: true,
|
||||
icon: carIcon,
|
||||
rotation: recentAngelToMarker,
|
||||
// infoWindow: const InfoWindow(
|
||||
// title: 'Time',
|
||||
// ),
|
||||
@@ -795,10 +882,10 @@ class MapDriverController extends GetxController {
|
||||
passengerId = Get.arguments['passengerId'];
|
||||
driverId = Get.arguments['driverId'];
|
||||
distance = Get.arguments['Distance'];
|
||||
name = Get.arguments['name'];
|
||||
email = Get.arguments['email'];
|
||||
passengerName = Get.arguments['name'];
|
||||
passengerEmail = Get.arguments['email'];
|
||||
totalPassenger = Get.arguments['totalPassenger'];
|
||||
phone = Get.arguments['phone'];
|
||||
passengerPhone = Get.arguments['phone'];
|
||||
walletChecked = Get.arguments['WalletChecked'];
|
||||
tokenPassenger = Get.arguments['tokenPassenger'];
|
||||
direction = Get.arguments['direction'];
|
||||
|
||||
Reference in New Issue
Block a user