This commit is contained in:
Hamza-Ayed
2023-09-21 00:29:25 +03:00
parent 5f402a0b65
commit 9bc121f07a
19 changed files with 253 additions and 181 deletions

View File

@@ -101,24 +101,19 @@ class LoginCaptinController extends GetxController {
}
void loginByBoxData() async {
isloading = true;
update();
Get.offAll(() => const HomeCaptin());
Get.to(() => const HomeCaptin());
await CRUD().post(link: AppLink.addTokensDriver, payload: {
'token': box.read(BoxName.tokenDriver).toString(),
'captain_id': box.read(BoxName.driverID).toString()
});
isloading = false;
update();
}
@override
void onInit() {
void onInit() async {
super.onInit();
if (box.read(BoxName.driverID) != null ||
box.read(BoxName.driverID) != '') {
loginByBoxData();
}
// if (box.read(BoxName.driverID).toString() != null) {
// loginByBoxData();
// }
}
}

View File

@@ -6,7 +6,6 @@ import 'package:get/get.dart';
import 'package:ride/constant/links.dart';
import 'package:ride/controller/functions/crud.dart';
import 'package:ride/views/auth/login_page.dart';
import 'package:ride/views/home/map_page.dart';
import '../../views/auth/verify_email_page.dart';

View File

@@ -288,6 +288,12 @@ class FirebasMessagesController extends GetxController {
var passengerList = message.data['passengerList'];
print(passengerList);
print('9999999999999my Apply Ride 999999999999999');
MapController mapController = Get.find<MapController>();
mapController.rideConfirm = false;
update();
print('-----------------------------rideConfirm===' +
mapController.rideConfirm.toString());
var myList = jsonDecode(passengerList) as List<dynamic>;
driverID = myList[2].toString();
Get.snackbar(

View File

@@ -5,7 +5,7 @@ class ScanIdCard extends GetxController {
CardDetails? _cardDetails;
CardScanOptions scanOptions = const CardScanOptions(
scanCardHolderName: true,
// enableDebugLogs: true,
enableDebugLogs: true,
validCardsToScanBeforeFinishingScan: 5,
possibleCardHolderNamePositions: [
CardHolderNameScanPosition.aboveCardNumber,

View File

@@ -10,7 +10,7 @@ class TimerController extends GetxController {
@override
void onInit() {
startTimer();
// startTimer();//TODO check if it true
super.onInit();
}

View File

@@ -34,6 +34,7 @@ class MapController extends GetxController {
BitmapDescriptor markerIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
double height = 150;
DateTime currentTime = DateTime.now();
final location = Location();
late LocationData currentLocation;
double heightMenu = 0;
@@ -187,6 +188,7 @@ class MapController extends GetxController {
delayAndFetchRideStatus(rideId);
if (shouldFetch == false) {
startTimer();
update();
}
update();
}
@@ -204,15 +206,16 @@ class MapController extends GetxController {
decod['data'].toString() == 'Refused') {
shouldFetch = false; // Stop further fetches
rideConfirm = false;
startTimer();
update();
} else {
delayAndFetchRideStatus(
rideId); // Repeat the delay and fetch operation
shouldFetch = true;
update();
// delayAndFetchRideStatus(
// rideId); // Repeat the delay and fetch operation
}
}
});
startTimer();
}
void startTimer() async {
@@ -240,6 +243,108 @@ class MapController extends GetxController {
return response['status'];
}
Future getCarsLocationByPassenger() async {
carsLocationByPassenger = [];
LatLngBounds bounds =
calculateBounds(mylocation.latitude, mylocation.longitude, 8000);
print(
'Southwest: ${bounds.southwest.latitude}, ${bounds.southwest.longitude}');
print(
'Northeast: ${bounds.northeast.latitude}, ${bounds.northeast.longitude}');
var res =
await CRUD().get(link: AppLink.getCarsLocationByPassenger, payload: {
'southwestLat': southwest.latitude.toString(),
'southwestLon': southwest.longitude.toString(),
'northeastLat': northeast.latitude.toString(),
'northeastLon': northeast.longitude.toString(),
});
if (res == 'failure') {
Get.defaultDialog(
title: 'No Car in your site.Sorry!',
middleText: '',
confirm: MyElevatedButton(
title: 'Back',
onPressed: () {
Get.back();
markerReloadingTimer.cancel();
}));
} else {
dataCarsLocationByPassenger = jsonDecode(res);
// print(dataCarsLocationByPassenger);
for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
carsLocationByPassenger.add(LatLng(
double.parse(dataCarsLocationByPassenger['message'][i]['latitude']),
double.parse(
dataCarsLocationByPassenger['message'][i]['longitude'])));
}
update();
}
}
Future getDriverCarsLocationToPassengerAfterApplied() async {
driverCarsLocationToPassengerAfterApplied = [];
var res = await CRUD().get(
link: AppLink.getDriverCarsLocationToPassengerAfterApplied,
payload: {
'driver_id': dataCarsLocationByPassenger['message'][0]['driver_id']
});
datadriverCarsLocationToPassengerAfterApplied = jsonDecode(res);
driverCarsLocationToPassengerAfterApplied.add(LatLng(
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['longitude'])));
update();
}
Future runEvery50SecondsUntilConditionMet() async {
// Calculate the duration of the trip in minutes.
double tripDurationInMinutes = duration1 / 60;
int loopCount = tripDurationInMinutes.ceil();
// If the trip duration is less than or equal to 50 minutes, then break the loop.
for (var i = 0; i < loopCount; i++) {
// Wait for 50 seconds.
await Future.delayed(const Duration(
seconds:
50)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function.
await getDriverCarsLocationToPassengerAfterApplied();
reloadMarkerDriverCarsLocationToPassengerAfterApplied();
}
}
void reloadMarkerDriverCarsLocationToPassengerAfterApplied() {
// Clear existing markers
markers.clear();
update();
for (var i = 0; i < driverCarsLocationToPassengerAfterApplied.length; i++) {
// }
// for (var item in driverCarsLocationToPassengerAfterApplied) {
final marker = Marker(
infoWindow: InfoWindow(
title:
'${driverCarsLocationToPassengerAfterApplied[i].latitude} minutes'),
markerId: MarkerId(
datadriverCarsLocationToPassengerAfterApplied['message'][0]['id']
.toString()),
position: LatLng(driverCarsLocationToPassengerAfterApplied[i].latitude,
driverCarsLocationToPassengerAfterApplied[i].longitude),
);
markers.add(marker);
update();
mapController?.animateCamera(CameraUpdate.newLatLng(LatLng(
driverCarsLocationToPassengerAfterApplied[i].latitude,
driverCarsLocationToPassengerAfterApplied[i].longitude)));
update();
} // Update the map with the new markers
}
Future cancelRide() async {
print(rideConfirm);
@@ -398,100 +503,6 @@ class MapController extends GetxController {
update();
}
Future getCarsLocationByPassenger() async {
carsLocationByPassenger = [];
LatLngBounds bounds =
calculateBounds(mylocation.latitude, mylocation.longitude, 8000);
print(
'Southwest: ${bounds.southwest.latitude}, ${bounds.southwest.longitude}');
print(
'Northeast: ${bounds.northeast.latitude}, ${bounds.northeast.longitude}');
var res =
await CRUD().get(link: AppLink.getCarsLocationByPassenger, payload: {
'southwestLat': southwest.latitude.toString(),
'southwestLon': southwest.longitude.toString(),
'northeastLat': northeast.latitude.toString(),
'northeastLon': northeast.longitude.toString(),
});
if (res == 'failure') {
Get.defaultDialog(
title: 'No Car in your site.Sorry!',
middleText: '',
confirm: MyElevatedButton(
title: 'Back',
onPressed: () {
Get.back();
markerReloadingTimer.cancel();
}));
} else {
dataCarsLocationByPassenger = jsonDecode(res);
// print(dataCarsLocationByPassenger);
for (var i = 0; i < dataCarsLocationByPassenger['message'].length; i++) {
carsLocationByPassenger.add(LatLng(
double.parse(dataCarsLocationByPassenger['message'][i]['latitude']),
double.parse(
dataCarsLocationByPassenger['message'][i]['longitude'])));
}
update();
}
}
Future getDriverCarsLocationToPassengerAfterApplied() async {
driverCarsLocationToPassengerAfterApplied = [];
var res = await CRUD().get(
link: AppLink.getDriverCarsLocationToPassengerAfterApplied,
payload: {
'driver_id': dataCarsLocationByPassenger['message'][0]['driver_id']
});
datadriverCarsLocationToPassengerAfterApplied = jsonDecode(res);
driverCarsLocationToPassengerAfterApplied.add(LatLng(
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['latitude']),
double.parse(datadriverCarsLocationToPassengerAfterApplied['message'][0]
['longitude'])));
update();
}
Future runEvery50SecondsUntilConditionMet() async {
// Calculate the duration of the trip in minutes.
double tripDurationInMinutes = duration1 / 60;
int loopCount = tripDurationInMinutes.ceil();
// If the trip duration is less than or equal to 50 minutes, then break the loop.
for (var i = 0; i < loopCount; i++) {
// Wait for 50 seconds.
await Future.delayed(const Duration(
seconds:
50)); // Run the `getDriverCarsLocationToPassengerAfterApplied()` function.
await getDriverCarsLocationToPassengerAfterApplied();
reloadMarkerDriverCarsLocationToPassengerAfterApplied();
}
}
void reloadMarkerDriverCarsLocationToPassengerAfterApplied() {
// Clear existing markers
markers.clear();
for (var item in driverCarsLocationToPassengerAfterApplied) {
final marker = Marker(
infoWindow: InfoWindow(title: '${item.latitude} minutes'),
markerId: MarkerId(item.toString()),
position: LatLng(item.latitude, item.longitude),
);
markers.add(marker);
update();
mapController?.animateCamera(
CameraUpdate.newLatLng(LatLng(item.latitude, item.longitude)));
update();
} // Update the map with the new markers
}
LatLngBounds calculateBounds(
double centerLat, double centerLng, double radius) {
// double radius = 4000; // 10 km in meters
@@ -571,7 +582,10 @@ class MapController extends GetxController {
}
String duratioByPassenger = '';
late DateTime newTime1 = DateTime.now();
String distanceByPassenger = '';
late Duration durationfromDriverToPassenger;
void getNearestDriverByPassengerLocation() async {
if (polylines.isEmpty || data.isEmpty) {
double nearestDistance = double.infinity;
@@ -607,6 +621,8 @@ class MapController extends GetxController {
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);
duratioByPassenger =
data['rows'][0]['elements'][0]['duration']['text'];
@@ -771,7 +787,7 @@ class MapController extends GetxController {
late double cost = 0;
late double distance = 0;
late double duration = 0;
DateTime currentTime = DateTime.now();
late Duration durationToAdd;
late DateTime newTime = DateTime.now();
Future bottomSheet() async {

View File

@@ -44,32 +44,33 @@ class CreditCardController extends GetxController {
@override
void onInit() async {
super.onInit();
String? cardNumber = await SecureStorage().readData(BoxName.cardNumber);
String? cardHolderName =
await SecureStorage().readData(BoxName.cardHolderName);
String? expiryDate = await SecureStorage().readData(BoxName.expiryDate);
String? cvvCode = await SecureStorage().readData(BoxName.cvvCode);
openPayment();
// String? cardNumber = await SecureStorage().readData(BoxName.cardNumber);
// String? cardHolderName =
// await SecureStorage().readData(BoxName.cardHolderName);
// String? expiryDate = await SecureStorage().readData(BoxName.expiryDate);
// String? cvvCode = await SecureStorage().readData(BoxName.cvvCode);
print('cardNumber: $cardNumber');
print('cardHolderName: $cardHolderName');
print('expiryDate: $expiryDate');
print('cvvCode: $cvvCode');
// print('cardNumber: $cardNumber');
// print('cardHolderName: $cardHolderName');
// print('expiryDate: $expiryDate');
// print('cvvCode: $cvvCode');
if (cvvCode != null && cvvCode.isNotEmpty) {
final maskedCardNumber = DigitObscuringFormatter()
.formatEditUpdate(
TextEditingValue.empty,
TextEditingValue(text: cardNumber ?? ''),
)
.text;
// if (cvvCode != null && cvvCode.isNotEmpty) {
// final maskedCardNumber = DigitObscuringFormatter()
// .formatEditUpdate(
// TextEditingValue.empty,
// TextEditingValue(text: cardNumber ?? ''),
// )
// .text;
print('maskedCardNumber: $maskedCardNumber');
// print('maskedCardNumber: $maskedCardNumber');
cardNumberController.text = maskedCardNumber;
cardHolderNameController.text = cardHolderName ?? '';
expiryDateController.text = expiryDate ?? '';
cvvCodeController.text = cvvCode;
}
// cardNumberController.text = maskedCardNumber;
// cardHolderNameController.text = cardHolderName ?? '';
// expiryDateController.text = expiryDate ?? '';
// cvvCodeController.text = cvvCode;
// }
}
}