This commit is contained in:
Hamza-Ayed
2024-02-25 00:23:00 +03:00
parent a9f557ca83
commit b33e797f76
22 changed files with 368 additions and 159 deletions

View File

@@ -1,11 +1,13 @@
import 'dart:convert';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/constant/links.dart';
import 'package:SEFER/main.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:SEFER/env/env.dart';
import '../../constant/api_key.dart';
import '../home/captin/map_driver_controller.dart';
class CRUD {
Future<dynamic> get({
@@ -189,6 +191,28 @@ class CRUD {
return (jsonData['status']);
}
sendEmail(
String link,
Map<String, String>? payload,
) async {
var headers = {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
};
var request = http.Request('POST', Uri.parse(link));
request.bodyFields = payload!;
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
} else {
print(response.reasonPhrase);
}
}
Future<dynamic> postFromDialogue({
required String link,
Map<String, dynamic>? payload,

View File

@@ -101,6 +101,12 @@ class LogOutController extends GetxController {
box.remove(BoxName.phone);
box.remove(BoxName.tokenFCM);
box.remove(BoxName.tokens);
box.remove(BoxName.addHome);
box.remove(BoxName.addWork);
box.remove(BoxName.agreeTerms);
box.remove(BoxName.apiKeyRun);
box.remove(BoxName.countryCode);
box.remove(BoxName.accountIdStripeConnect);
Get.offAll(OnBoardingPage());
},
child: Text(

View File

@@ -144,7 +144,7 @@ class HomeCaptainController extends GetxController {
update();
}
GoogleMapController? mapHomeCaptaiController;
late GoogleMapController mapHomeCaptaiController;
void onMapCreated(GoogleMapController controller) {
mapHomeCaptaiController = controller;
controller.getVisibleRegion();

View File

@@ -49,6 +49,8 @@ class MapDriverController extends GetxController {
late String totalCost;
late String distance;
late String name;
late String email;
late String totalPassenger;
late String phone;
late String rideId;
late String isHaveSteps;
@@ -69,7 +71,7 @@ class MapDriverController extends GetxController {
bool isdriverWaitTimeEnd = false;
bool isRideFinished = false;
bool isRideStarted = false;
double passengerInfoWindow = Get.height * .35;
double passengerInfoWindow = Get.height * .39;
double driverEndPage = 100;
double progress = 0;
double progressToPassenger = 0;
@@ -406,11 +408,11 @@ class MapDriverController extends GetxController {
}
print('passengerWalletBurc bef ${double.parse(passengerWalletBurc)}');
if (double.parse(passengerWalletBurc) < 0) {
print('passengerWalletBurc aft ${double.parse(passengerWalletBurc)}');
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': passengerId,
'balance': ((-1) * double.parse(passengerWalletBurc)).toString()
});
print('passengerWalletBurc aft ${double.parse(passengerWalletBurc)}');
}
Future.delayed(const Duration(milliseconds: 300));
FirebaseMessagesController().sendNotificationToPassengerToken(
@@ -718,6 +720,8 @@ class MapDriverController extends GetxController {
driverId = Get.arguments['driverId'];
distance = Get.arguments['Distance'];
name = Get.arguments['name'];
email = Get.arguments['email'];
totalPassenger = Get.arguments['totalPassenger'];
phone = Get.arguments['phone'];
walletChecked = Get.arguments['WalletChecked'];
tokenPassenger = Get.arguments['tokenPassenger'];

View File

@@ -9,6 +9,7 @@ import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
import 'package:intl/intl.dart';
import 'package:location/location.dart';
import 'package:SEFER/constant/colors.dart';
import 'package:SEFER/constant/style.dart';
@@ -120,6 +121,9 @@ class MapPassengerController extends GetxController {
bool rideConfirm = false;
bool isMarkersShown = false;
bool isMainBottomMenuMap = true;
late Timer markerReloadingTimer2;
late Timer markerReloadingTimer1;
late int duration1;
bool isWayPointSheet = false;
bool isWayPointStopsSheet = false;
bool isWayPointStopsSheetUtilGetMap = false;
@@ -516,7 +520,13 @@ class MapPassengerController extends GetxController {
update();
}
late String arrivalTime;
void rideIsBeginPassengerTimer() async {
// Calculate arrival time considering current time and duration
DateTime now = DateTime.now();
DateTime arrivalTime1 = now.add(Duration(seconds: durationToRide));
arrivalTime = DateFormat('hh:mm').format(arrivalTime1);
for (int i = 0; i <= durationToRide; i++) {
await Future.delayed(const Duration(seconds: 1));
progressTimerRideBegin = i / durationToRide;
@@ -762,6 +772,7 @@ class MapPassengerController extends GetxController {
? double.parse(box.read(BoxName.passengerWalletTotal))
.toStringAsFixed(2)
: '0',
box.read(BoxName.email).toString(),
];
FirebaseMessagesController().sendNotificationToDriverMAP(
'Order',
@@ -1022,6 +1033,8 @@ class MapPassengerController extends GetxController {
"order_id": rideId.toString(), // Convert to String
"status": 'Cancel'
});
FirebaseMessagesController().sendNotificationToDriverMAP(
'Cancel Trip', 'Trip Cancelled'.tr, driverToken, []);
}
rideConfirm = false;
shouldFetch = false;
@@ -1407,9 +1420,6 @@ class MapPassengerController extends GetxController {
// });
// }
late Timer markerReloadingTimer2;
late Timer markerReloadingTimer1;
late int duration1;
void startMarkerReloading() {
int reloadCount = 0;
@@ -1461,61 +1471,61 @@ class MapPassengerController extends GetxController {
getNearestDriverByPassengerLocation() async {
if (polyLines.isEmpty || data.isEmpty) {
if (rideConfirm == false) {
double nearestDistance = double.infinity;
if (dataCarsLocationByPassenger != 'failure') {
if (dataCarsLocationByPassenger['message'].length > 0) {
for (var i = 0;
i < dataCarsLocationByPassenger['message'].length;
i++) {
var carLocation = dataCarsLocationByPassenger['message'][i];
return null; // Early return if data is empty
}
if (!rideConfirm) {
double nearestDistance = double.infinity;
if (dataCarsLocationByPassenger != 'failure') {
if (dataCarsLocationByPassenger['message'].length > 0) {
for (var i = 0;
i < dataCarsLocationByPassenger['message'].length;
i++) {
var carLocation = dataCarsLocationByPassenger['message'][i];
// }
// isloading = true;
// }
// isloading = true;
update();
// Make API request to get exact distance and duration
String apiUrl =
'${AppLink.googleMapsLink}distancematrix/json?destinations=${carLocation['latitude']},${carLocation['longitude']}&origins=${passengerLocation.latitude},${passengerLocation.longitude}&units=metric&key=${AK.mapAPIKEY}';
var response = await CRUD().getGoogleApi(link: apiUrl, payload: {});
if (response['status'] == "OK") {
var data = response;
// Extract distance and duration from the response and handle accordingly
int distance1 =
data['rows'][0]['elements'][0]['distance']['value'];
distanceByPassenger =
data['rows'][0]['elements'][0]['distance']['text'];
duration1 = data['rows'][0]['elements'][0]['duration']['value'];
durationFromDriverToPassenger =
Duration(seconds: duration1.toInt());
newTime1 = currentTime.add(durationFromDriverToPassenger);
timeFromDriverToPassenger =
newTime1.add(Duration(minutes: 2.toInt()));
durationByPassenger =
data['rows'][0]['elements'][0]['duration']['text'];
update();
// Make API request to get exact distance and duration
String apiUrl =
'${AppLink.googleMapsLink}distancematrix/json?destinations=${carLocation['latitude']},${carLocation['longitude']}&origins=${passengerLocation.latitude},${passengerLocation.longitude}&units=metric&key=${AK.mapAPIKEY}';
var response =
await CRUD().getGoogleApi(link: apiUrl, payload: {});
if (response['status'] == "OK") {
var data = response;
// Extract distance and duration from the response and handle accordingly
int distance1 =
data['rows'][0]['elements'][0]['distance']['value'];
distanceByPassenger =
data['rows'][0]['elements'][0]['distance']['text'];
duration1 = data['rows'][0]['elements'][0]['duration']['value'];
if (distance1 < nearestDistance) {
nearestDistance = distance1.toDouble();
durationFromDriverToPassenger =
Duration(seconds: duration1.toInt());
newTime1 = currentTime.add(durationFromDriverToPassenger);
timeFromDriverToPassenger =
newTime1.add(Duration(minutes: 2.toInt()));
durationByPassenger =
data['rows'][0]['elements'][0]['duration']['text'];
nearestCar = CarLocation(
distance: distance1.toDouble(),
duration: duration1.toDouble(),
id: carLocation['driver_id'],
latitude: double.parse(carLocation['latitude']),
longitude: double.parse(carLocation['longitude']),
);
// isloading = false;
update();
if (distance1 < nearestDistance) {
nearestDistance = distance1.toDouble();
nearestCar = CarLocation(
distance: distance1.toDouble(),
duration: duration1.toDouble(),
id: carLocation['driver_id'],
latitude: double.parse(carLocation['latitude']),
longitude: double.parse(carLocation['longitude']),
);
// isloading = false;
update();
}
}
}
// Handle the distance and duration as needed
else {
//print(
// 'Failed to retrieve distance and duration: ${response['status']}');
// Handle the failure case
}
// Handle the distance and duration as needed
else {
//print(
// 'Failed to retrieve distance and duration: ${response['status']}');
// Handle the failure case
}
}
}
@@ -1537,7 +1547,8 @@ class MapPassengerController extends GetxController {
driverCarsLocationToPassengerAfterApplied.last.longitude,
);
if (distance > 500) {
cancelRide();
isCancelRidePageShown = true;
update();
} else {
Get.defaultDialog(
title: 'The Driver Will be in your location soon .'.tr,

View File

@@ -23,7 +23,7 @@ class SplashScreenController extends GetxController
animationController = AnimationController(
vsync: this,
duration: const Duration(seconds: 7),
duration: const Duration(seconds: 4),
);
zoomInAnimation = Tween<double>(begin: 1.0, end: 1.5).animate(
@@ -45,7 +45,7 @@ class SplashScreenController extends GetxController
}
void startTimer() {
Timer(const Duration(seconds: 7), () {
Timer(const Duration(seconds: 4), () {
box.read(BoxName.onBoarding) == null
? Get.off(() => OnBoardingPage())
: box.read(BoxName.email) != null

View File

@@ -115,7 +115,7 @@ class MyTranslation extends Translations {
"My Wallet": "محفظتي",
"Tariff": "تعرفة",
"Settings": "الإعدادات",
"Feed Back": "التغذية الراجعة",
"Feed Back": "اقتراحات",
"Promos": "العروض الترويجية",
"Please enter a valid 16-digit card number":
"الرجاء إدخال رقم بطاقة صالح مكون من 16 رقمًا",
@@ -438,6 +438,14 @@ class MyTranslation extends Translations {
'Camera not initilaized yet': "الكاميرا لم تُثبت بعد",
'Scan ID MklGoogle': "مسح هوية MklGoogle",
'Language': "اللغة",
"Jordan": "الأردن",
"USA": "الولايات المتحدة الأمريكية",
"Egypt": "مصر",
"Turkey": "تركيا",
"Saudi Arabia": "المملكة العربية السعودية",
"Qatar": "قطر",
"Bahrain": "البحرين",
"Kuwait": "الكويت",
'Your trip cost is': "تكلفة رحلتك هي",
'But you have a negative salary of': "لكن لديك راتب سلبي بقيمة",
' in your': "في",
@@ -558,7 +566,11 @@ class MyTranslation extends Translations {
'Night': "الليل",
'from 23:59 till 05:30': "من 23:59 إلى 05:30",
'Rate Driver': "تقييم السائق",
'Total Cost is ': ' صافي الربح ',
'Write note': 'اكتب ملاحظه',
'Time to arrive': 'وقت الوصول',
'Ride Summaries': "ملخصات الرحلات",
'Total Cost': "المبلغ الاجمالي",
'Average of Hours of': "متوسط ساعات",
' is ON for this month': "في هذا الشهر",
'Days': "أيام",

View File

@@ -29,6 +29,14 @@ class ProfileController extends GetxController {
update();
}
String? selectedCountry;
void setCountry(String? country) {
selectedCountry = country;
// box.write(BoxName.countryCode, country);
update();
}
updateColumn(Map<String, dynamic> payload) async {
isloading = true;
update();

View File

@@ -36,6 +36,7 @@ class RateController extends GetxController {
void addRateToPassenger() async {
// HomeCaptainController homeCaptainController =
// Get.find<HomeCaptainController>();
// Get.put(MapDriverController());
if (selectedRateItemId < 1) {
Get.defaultDialog(
title: 'You Should choose rate figure'.tr,
@@ -50,18 +51,17 @@ class RateController extends GetxController {
'rating': selectedRateItemId.toString(),
'comment': comment.text,
});
await CRUD()
.post(link: AppLink.sendEmailToPassengerForTripDetails, payload: {
await CRUD().sendEmail(AppLink.sendEmailToPassengerForTripDetails, {
'startLocation':
Get.find<MapDriverController>().latLngpassengerLocation.toString(),
'endLocation': Get.find<MapDriverController>()
.latLngPassengerDestination
.toString(),
Get.find<MapDriverController>().passengerLocation.toString(),
'endLocation':
Get.find<MapDriverController>().passengerDestination.toString(),
'name': Get.find<MapDriverController>().name.toString(),
'timeOfTrip': Get.find<MapDriverController>().duration.toString(),
'fee': Get.find<MapDriverController>().timeOfOrder.toString(),
'timeOfTrip': Get.find<MapDriverController>().timeOfOrder.toString(),
'fee': Get.find<MapDriverController>().totalPassenger.toString(),
'duration': Get.find<MapDriverController>().duration.toString(),
'phone': Get.find<MapDriverController>().phone.toString(),
'email': Get.find<MapDriverController>().email.toString(),
});
// homeCaptainController.isActive = true;
// update();