This commit is contained in:
Hamza Aleghwairyeen
2024-03-27 14:50:52 +03:00
parent eb67f93e71
commit ed63445fc5
5 changed files with 48 additions and 18 deletions

View File

@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:SEFER/controller/home/captin/map_driver_controller.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -127,6 +128,7 @@ class FirebaseMessagesController extends GetxController {
var myList = jsonDecode(myListString) as List<dynamic>;
// var myPoints = jsonDecode(points) as List<dynamic>;
driverToken = myList[14].toString();
Get.find<MapDriverController>().rideId = 'rideId';
update();
// print('driverToken==============$driverToken');
Get.to(() => OrderRequestPage(), arguments: {
@@ -223,8 +225,10 @@ class FirebaseMessagesController extends GetxController {
Get.offAll(const MapPagePassenger());
} else if (message.notification!.title! == 'Order Applied') {
Get.snackbar(
"The order has been accepted by another driver.".tr, // Corrected grammar
"Be more mindful next time to avoid dropping orders.".tr, // Improved sentence structure
"The order has been accepted by another driver."
.tr, // Corrected grammar
"Be more mindful next time to avoid dropping orders."
.tr, // Improved sentence structure
backgroundColor: AppColor.yellowColor,
snackPosition: SnackPosition.BOTTOM,
);

View File

@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:SEFER/constant/table_names.dart';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
@@ -19,9 +20,9 @@ class LocationController extends GetxController {
bool isLoading = false;
late double heading = 0;
late double accuracy = 0;
LatLng? previousLocation;
late double previousTime = 0;
late double latitude;
late double totalDistance;
late double totalDistance = 0;
late double longitude;
late DateTime time;
late double speed = 0;
@@ -63,9 +64,10 @@ class LocationController extends GetxController {
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': speed.toString(),
'distance': totalDistance == 0 ? '0' : totalDistance.toString(),
'status': box.read(BoxName.statusDriverLocation).toString()
});
if (Get.find<MapDriverController>().rideId == null) {
if (Get.find<HomeCaptainController>().rideId == '0') {
await sql.insertData({
'driver_id': box.read(BoxName.driverID),
'latitude': myLocation.latitude.toString(),
@@ -133,20 +135,43 @@ class LocationController extends GetxController {
(_locationData.latitude != null && _locationData.longitude != null
? LatLng(_locationData.latitude!, _locationData.longitude!)
: null)!;
speed = _locationData.speed!;
heading = _locationData.heading!;
// Calculate the distance between the current location and the previous location
if (previousLocation != null) {
// double distance = myLocation.distanceBetween(previousLocation);
// totalDistance += distance;
}
if (Get.find<HomeCaptainController>().rideId == 'rideId') {
if (previousTime > 0) {
double distance = calculateDistanceInKmPerHour(
previousTime, _locationData.time, speed);
print('distance $distance');
totalDistance += distance;
}
print('totalDistance: $totalDistance');
previousLocation = myLocation;
previousTime = _locationData.time!;
}
// Print location details
// print('myLocation: ${myLocation}');
// print('Accuracy: ${_locationData.accuracy}');
// print('Latitude: ${_locationData.latitude}');
// print('Longitude: ${_locationData.longitude}');
// print('Time: ${_locationData.time}');
print('myLocation: ${myLocation}');
print('Accuracy: ${_locationData.accuracy}');
print('Latitude: ${_locationData.latitude}');
print('Longitude: ${_locationData.longitude}');
print('Time: ${_locationData.time}');
print('speed: ${_locationData.speed}');
print('Heading: ${_locationData.heading}');
// isLoading = false;
update();
}
double calculateDistanceInKmPerHour(
double? startTime, double? endTime, double speedInMetersPerSecond) {
// Calculate the time difference in hours
double timeDifferenceInHours = (endTime! - startTime!) / 1000 / 3600;
// Convert speed to kilometers per hour
double speedInKmPerHour = speedInMetersPerSecond * 3.6;
// Calculate the distance in kilometers
double distanceInKilometers = speedInKmPerHour * timeDifferenceInHours;
return distanceInKilometers;
}
}

View File

@@ -28,6 +28,7 @@ class HomeCaptainController extends GetxController {
bool isCallOn = false;
String totalMoneyToday = '0';
String rating = '0';
String rideId = '0';
String countRideToday = '0';
String totalMoneyInSEFER = '0';
String totalDurationToday = '0';
@@ -244,7 +245,7 @@ class HomeCaptainController extends GetxController {
getDriverRate() async {
var res = await CRUD().get(
link: AppLink.getDriveRrate,
link: AppLink.getDriverRate,
payload: {'driver_id': box.read(BoxName.driverID).toString()});
data = jsonDecode(res);