This commit is contained in:
Hamza-Ayed
2024-12-01 10:17:23 +02:00
parent 5aeb3cf685
commit 0129162309
34 changed files with 1317 additions and 875 deletions

View File

@@ -1,12 +1,14 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
import 'package:get/get.dart';
import 'package:SEFER/constant/links.dart';
import 'package:SEFER/main.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'dart:math' as math;
import '../../../constant/box_name.dart';
import '../../../print.dart';
import '../../functions/audio_controller.dart';
import '../../functions/crud.dart';
import '../../functions/location_controller.dart';
@@ -15,7 +17,7 @@ import 'home_captain_controller.dart';
class OrderRequestController extends GetxController {
double progress = 0;
double progressSpeed = 0;
int duration = 11;
int duration = 15;
int durationSpeed = 20;
int remainingTime = 0;
int remainingTimeSpeed = 0;
@@ -30,12 +32,17 @@ class OrderRequestController extends GetxController {
late int minutes;
@override
void onInit() {
Future<void> onInit() async {
// AudioController audioController = Get.put(AudioController());
print('onInit called');
await initilizeOrderPage();
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
// audioController.playAudio();
// getRefusedOrderByCaptain();
initilizeOrderPage();
addCustomStartIcon();
addCustomEndIcon();
@@ -51,34 +58,41 @@ class OrderRequestController extends GetxController {
late double lngPassengerLocation;
late double lngPassengerDestination;
late double latPassengerDestination;
initilizeOrderPage() {
final myListString = arguments['myListString'];
// final myList = arguments['DriverList'];
if (arguments['DriverList'] == null || arguments['DriverList'].isEmpty) {
Future<void> initilizeOrderPage() async {
final myListString = Get.arguments['myListString'];
if (Get.arguments['DriverList'] == null ||
Get.arguments['DriverList'].isEmpty) {
myList = jsonDecode(myListString);
Log.print('myList: ${myList}');
} else {
myList = arguments['DriverList'];
myList = Get.arguments['DriverList'];
Log.print('myList1: ${myList}');
}
body = arguments['body'];
Duration durationToAdd = Duration(seconds: int.parse(myList[4]));
body = Get.arguments['body'];
Duration durationToAdd =
Duration(seconds: (double.tryParse(myList[4]) ?? 0).toInt());
hours = durationToAdd.inHours;
minutes = (durationToAdd.inMinutes % 60).round();
startTimerSpeed(myList[6].toString(), body.toString());
var coords = myList[0].split(',');
var coordDestination = myList[1].split(',');
// Parse to double
latPassengerLocation = double.parse(coords[0]);
lngPassengerLocation = double.parse(coords[1]);
latPassengerDestination = double.parse(coordDestination[0]);
lngPassengerDestination = double.parse(coordDestination[1]);
// Instead of splitting, directly use the values from the list
// First coordinate pair is at index 0 and 1
latPassengerLocation = double.tryParse(myList[0]) ?? 0.0;
lngPassengerLocation = double.tryParse(myList[1]) ?? 0.0;
// Second coordinate pair is at index 2 and 3
latPassengerDestination = double.tryParse(myList[2]) ?? 0.0;
lngPassengerDestination = double.tryParse(myList[3]) ?? 0.0;
pointsDirection = [
LatLng(latPassengerLocation, lngPassengerLocation),
LatLng(latPassengerDestination, lngPassengerDestination)
]; // Calculate the midpoint between the two points
// Calculate the minimum and maximum latitude and longitude values
];
// Calculate bounds
double minLatitude =
math.min(pointsDirection[0].latitude, pointsDirection[1].latitude);
double maxLatitude =
@@ -87,17 +101,18 @@ class OrderRequestController extends GetxController {
math.min(pointsDirection[0].longitude, pointsDirection[1].longitude);
double maxLongitude =
math.max(pointsDirection[0].longitude, pointsDirection[1].longitude);
// Create a bounding box using the calculated values
bounds = LatLngBounds(
southwest: LatLng(minLatitude, minLongitude),
northeast: LatLng(maxLatitude, maxLongitude),
);
update();
}
getRideDEtailsForBackgroundOrder() async {
getRideDEtailsForBackgroundOrder(String rideId) async {
await CRUD().get(link: AppLink.getRidesDetails, payload: {
'id': box.read(BoxName.myList)[2].toString(),
'id': rideId,
});
}
@@ -193,20 +208,14 @@ class OrderRequestController extends GetxController {
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
CRUD().post(
link: '${AppLink.seferAlexandriaServer}/rides/update.php',
payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
CRUD().post(link: '${AppLink.seferGizaServer}/rides/update.php', payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
if (AppLink.endPoint != AppLink.seferCairoServer) {
CRUD().post(link: '${AppLink.endPoint}/rides/update.php', payload: {
'id': orderID,
// 'rideTimeStart': DateTime.now().toString(),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
}
// applied = true;
// if (box.read(BoxName.gender).toString() != 'Female') {
@@ -252,41 +261,24 @@ class OrderRequestController extends GetxController {
'distance': distance,
'duration': duration,
});
CRUD().post(
link:
'${AppLink.seferAlexandriaServer}/notificationCaptain/addWaitingRide.php',
payload: {
'id': orderID,
'start_location': startLocation,
'end_location': endLocation,
'date': date,
'time': time,
'price': price,
'passenger_id': passengerId,
'status': status,
'carType': carType,
'passengerRate': passengerRate,
'price_for_passenger': priceForPassenger,
'distance': distance,
'duration': duration,
});
CRUD().post(
link:
'${AppLink.seferGizaServer}/notificationCaptain/addWaitingRide.php',
payload: {
'id': orderID,
'start_location': startLocation,
'end_location': endLocation,
'date': date,
'time': time,
'price': price,
'passenger_id': passengerId,
'status': status,
'carType': carType,
'passengerRate': passengerRate,
'price_for_passenger': priceForPassenger,
'distance': distance,
'duration': duration,
});
if (AppLink.endPoint != AppLink.seferCairoServer) {
CRUD().post(
link: '${AppLink.endPoint}/notificationCaptain/addWaitingRide.php',
payload: {
'id': orderID,
'start_location': startLocation,
'end_location': endLocation,
'date': date,
'time': time,
'price': price,
'passenger_id': passengerId,
'status': status,
'carType': carType,
'passengerRate': passengerRate,
'price_for_passenger': priceForPassenger,
'distance': distance,
'duration': duration,
});
}
}
}