diff --git a/lib/constant/links.dart b/lib/constant/links.dart index 5a00b91..043a0b6 100644 --- a/lib/constant/links.dart +++ b/lib/constant/links.dart @@ -127,7 +127,7 @@ class AppLink { // ===================================== static String addRateToPassenger = "$ride/rate/add.php"; static String addRateToDriver = "$ride/rate/addRateToDriver.php"; - static String getDriveRrate = "$ride/rate/getDriveRrate.php"; + static String getDriverRate = "$ride/rate/getDriveRrate.php"; ////////////////emails ============// static String sendEmailToPassengerForTripDetails = diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart index 6a74b7e..0c4a722 100644 --- a/lib/controller/firebase/firbase_messge.dart +++ b/lib/controller/firebase/firbase_messge.dart @@ -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; // var myPoints = jsonDecode(points) as List; driverToken = myList[14].toString(); + Get.find().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, ); diff --git a/lib/controller/functions/location_controller.dart b/lib/controller/functions/location_controller.dart index 636353d..c675b8d 100644 --- a/lib/controller/functions/location_controller.dart +++ b/lib/controller/functions/location_controller.dart @@ -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().rideId == null) { + if (Get.find().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().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; + } } diff --git a/lib/controller/home/captin/home_captain_controller.dart b/lib/controller/home/captin/home_captain_controller.dart index db089ac..9baa504 100644 --- a/lib/controller/home/captin/home_captain_controller.dart +++ b/lib/controller/home/captin/home_captain_controller.dart @@ -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); diff --git a/lib/views/home/Captin/home_captain/drawer_captain.dart b/lib/views/home/Captin/home_captain/drawer_captain.dart index 694e187..e03676c 100644 --- a/lib/views/home/Captin/home_captain/drawer_captain.dart +++ b/lib/views/home/Captin/home_captain/drawer_captain.dart @@ -61,7 +61,7 @@ class DrawerCaptain extends StatelessWidget { Column( children: [ Text( - Get.find().rating, + Get.find().rating.toString(), style: AppStyle.number.copyWith(color: Colors.amber), ), Container(