This commit is contained in:
Hamza-Ayed
2024-03-21 02:09:52 +03:00
parent ad062d9ad7
commit 045f7e20f0
46 changed files with 2767 additions and 877 deletions

View File

@@ -58,7 +58,7 @@ class HomeCaptainController extends GetxController {
isActive = !isActive;
if (isActive) {
if (double.parse(totalPoints) > -500) {
if (double.parse(totalPoints) > -300) {
locationController.startLocationUpdates();
activeStartTime = DateTime.now();
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
@@ -105,7 +105,7 @@ class HomeCaptainController extends GetxController {
await sql.getCustomQuery(customQuery);
countRefuse = results[0]['count'].toString();
update();
if (int.parse(countRefuse) > 3 || double.parse(totalPoints) <= -500) {
if (int.parse(countRefuse) > 3 || double.parse(totalPoints) <= -300) {
print('total point is $totalPoints');
locationController.stopLocationUpdates();
activeStartTime = null;
@@ -202,8 +202,8 @@ class HomeCaptainController extends GetxController {
getAllPayment();
startPeriodicExecution();
onMapCreated(mapHomeCaptaiController);
getRefusedOrderByCaptain();
totalPoints = Get.find<CaptainWalletController>().totalPoints;
getRefusedOrderByCaptain();
// LocationController().getLocation();
super.onInit();
}

View File

@@ -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'];

View File

@@ -12,8 +12,11 @@ import '../../functions/location_controller.dart';
class OrderRequestController extends GetxController {
double progress = 0;
int duration = 20;
double progressSpeed = 0;
int duration = 10;
int durationSpeed = 20;
int remainingTime = 0;
int remainingTimeSpeed = 0;
String countRefuse = '0';
bool applied = false;
final locationController = Get.put(LocationController());
@@ -81,19 +84,43 @@ class OrderRequestController extends GetxController {
if (applied == false) {
print('applied=========================');
print(applied);
refuseOrder(driverID, orderID);
refuseOrder(orderID);
}
}
}
void refuseOrder(String driverID, orderID) async {
void startTimerSpeed(String driverID, orderID) async {
for (int i = 0; i <= durationSpeed; i++) {
await Future.delayed(const Duration(seconds: 1));
progressSpeed = i / durationSpeed;
remainingTimeSpeed = durationSpeed - i;
update();
}
if (remainingTimeSpeed == 0) {
if (applied == false) {
print('applied=========================');
print(applied);
Get.back();
// refuseOrder(box.read(BoxName.driverID), orderID);
}
}
}
void refuseOrder(orderID) async {
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
//TODO need review
'driver_id': box.read(BoxName.driverID).toString(),
'driver_id': box.read(BoxName.driverID),
// box.read(BoxName.driverID).toString(),
'order_id': orderID,
'status': 'Refused'
});
await CRUD().post(link: AppLink.updateRides, payload: {
'id': orderID,
'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
Get.back();
// applied = true;
sql.insertData({

View File

@@ -64,7 +64,7 @@ GetBuilder<HomeCaptainController> callPage() {
Column(
children: [
Text(callController.status),
Text(Get.find<MapDriverController>().name.toString()),
Text(Get.find<MapDriverController>().passengerName.toString()),
],
),
GestureDetector(

View File

@@ -25,19 +25,19 @@ class ConnectWidget extends StatelessWidget {
builder: (homeCaptainController) => int.parse(
orderRequestController.countRefuse) >
3 ||
double.parse(captainWalletController.totalPoints) < -500
double.parse(captainWalletController.totalPoints) < -300
? CupertinoButton(
onPressed: () {
Get.defaultDialog(
// backgroundColor: CupertinoColors.destructiveRed,
barrierDismissible: false,
title: double.parse(captainWalletController.totalPoints) <
-500
-300
? 'You dont have Points'.tr
: 'You Are Stopped For this Day !'.tr,
titleStyle: AppStyle.title,
content: Text(
double.parse(captainWalletController.totalPoints) < -500
double.parse(captainWalletController.totalPoints) < -300
? 'You must be recharge your Account'.tr
: 'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
.tr,
@@ -45,7 +45,7 @@ class ConnectWidget extends StatelessWidget {
),
confirm:
double.parse(captainWalletController.totalPoints) <
-500
-300
? MyElevatedButton(
title: 'Recharge my Account'.tr,
onPressed: () {

View File

@@ -3,9 +3,11 @@ import 'package:flutter_font_icons/flutter_font_icons.dart';
import 'package:get/get.dart';
import 'package:SEFER/controller/home/captin/home_captain_controller.dart';
import 'package:SEFER/controller/home/captin/widget/zones_controller.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../../../../constant/colors.dart';
import '../../../../views/Rate/ride_calculate_driver.dart';
import '../../../functions/location_controller.dart';
GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
return GetBuilder<HomeCaptainController>(
@@ -78,6 +80,27 @@ GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
const SizedBox(
height: 5,
),
AnimatedContainer(
duration: const Duration(microseconds: 200),
width: controller.widthMapTypeAndTraffic,
decoration: BoxDecoration(
color: AppColor.secondaryColor,
border: Border.all(),
borderRadius: BorderRadius.circular(15)),
child: IconButton(
onPressed: () {
controller.mapHomeCaptaiController
.animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
)));
},
icon: const Icon(
Icons.location_on,
size: 29,
),
),
),
AnimatedContainer(
duration: const Duration(microseconds: 200),
width: controller.widthMapTypeAndTraffic,