3/1/1
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../../constant/api_key.dart';
|
||||
import '../../../constant/box_name.dart';
|
||||
@@ -130,6 +131,22 @@ class MapDriverController extends GetxController {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void openGoogleMapFromDriverToPassenger() async {
|
||||
var endLat = latLngpassengerLocation.latitude;
|
||||
var endLng = latLngpassengerLocation.longitude;
|
||||
|
||||
var startLat = Get.find<LocationController>().myLocation.latitude;
|
||||
var startLng = Get.find<LocationController>().myLocation.longitude;
|
||||
|
||||
String url =
|
||||
'https://www.google.com/maps/dir/$startLat,$startLng/$endLat,$endLng/&directionsmode=driving';
|
||||
if (await canLaunchUrl(Uri.parse(url))) {
|
||||
await launchUrl(Uri.parse(url));
|
||||
} else {
|
||||
throw 'Could not launch google maps';
|
||||
}
|
||||
}
|
||||
|
||||
void checkIsDriverNearPassenger() async {
|
||||
if (isDriverNearPassengerStart) {
|
||||
Timer.periodic(const Duration(seconds: 3), (timer) {
|
||||
@@ -248,6 +265,9 @@ class MapDriverController extends GetxController {
|
||||
'DriverIsGoingToPassenger',
|
||||
box.read(BoxName.name).toString(),
|
||||
tokenPassenger);
|
||||
if (box.read(BoxName.googlaMapApp) == true) {
|
||||
openGoogleMapFromDriverToPassenger();
|
||||
}
|
||||
}
|
||||
|
||||
bool isSocialPressed = false;
|
||||
@@ -291,76 +311,100 @@ class MapDriverController extends GetxController {
|
||||
}
|
||||
|
||||
Position? currentPosition;
|
||||
|
||||
void startRideFromDriver() async {
|
||||
changeRideToBeginToPassenger();
|
||||
isPassengerInfoWindow = false;
|
||||
isRideStarted = true;
|
||||
isRideFinished = false;
|
||||
remainingTimeInPassengerLocatioWait = 0;
|
||||
timeWaitingPassenger = 0;
|
||||
box.write(BoxName.statusDriverLocation, 'on');
|
||||
double _distance =
|
||||
await calculateDistanseBetweenDriverAndPassengerLocation();
|
||||
|
||||
update();
|
||||
await CRUD().post(link: AppLink.addDriverpayment, payload: {
|
||||
'rideId': rideId,
|
||||
'amount': paymentAmount,
|
||||
'payment_method': paymentMethod,
|
||||
'passengerID': passengerId,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
if (_distance < 50) {
|
||||
changeRideToBeginToPassenger();
|
||||
isPassengerInfoWindow = false;
|
||||
isRideStarted = true;
|
||||
isRideFinished = false;
|
||||
remainingTimeInPassengerLocatioWait = 0;
|
||||
timeWaitingPassenger = 0;
|
||||
box.write(BoxName.statusDriverLocation, 'on');
|
||||
|
||||
await CRUD().post(link: AppLink.updateRides, payload: {
|
||||
'id': rideId,
|
||||
'rideTimeStart': DateTime.now().toString(),
|
||||
'status': 'Begin'
|
||||
});
|
||||
FirebaseMessagesController().sendNotificationToAnyWithoutData(
|
||||
'RideIsBegin', box.read(BoxName.name).toString(), tokenPassenger);
|
||||
rideIsBeginPassengerTimer();
|
||||
double pointsSubstraction = 0;
|
||||
pointsSubstraction = double.parse(paymentAmount) * -100;
|
||||
var res = await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
|
||||
'paymentID': 'rideId$rideId',
|
||||
'amount': (pointsSubstraction).toString(),
|
||||
'paymentMethod': paymentMethod,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
var d = jsonDecode(res);
|
||||
// mapController!.animateCamera(
|
||||
// CameraUpdate.newLatLngZoom(
|
||||
// myLocation,
|
||||
// 12,
|
||||
// ),
|
||||
// );
|
||||
update();
|
||||
await CRUD().post(link: AppLink.addDriverpayment, payload: {
|
||||
'rideId': rideId,
|
||||
'amount': paymentAmount,
|
||||
'payment_method': paymentMethod,
|
||||
'passengerID': passengerId,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
|
||||
await CRUD().post(link: AppLink.updateRides, payload: {
|
||||
'id': rideId,
|
||||
'rideTimeStart': DateTime.now().toString(),
|
||||
'status': 'Begin',
|
||||
});
|
||||
FirebaseMessagesController().sendNotificationToAnyWithoutData(
|
||||
'RideIsBegin', box.read(BoxName.name).toString(), tokenPassenger);
|
||||
rideIsBeginPassengerTimer();
|
||||
double pointsSubstraction = 0;
|
||||
pointsSubstraction = double.parse(paymentAmount) * -17;
|
||||
var res =
|
||||
await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
|
||||
'paymentID': 'rideId$rideId',
|
||||
'amount': (pointsSubstraction).toString(),
|
||||
'paymentMethod': paymentMethod,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
var d = jsonDecode(res);
|
||||
|
||||
update();
|
||||
// Start updating location and moving camera
|
||||
// updateLocation();
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'Your are far from passenger location'.tr,
|
||||
middleText:
|
||||
'go to your passenger location before\nPassenger cancel trip'.tr,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok',
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void updateLocation() async {
|
||||
StreamSubscription<Position>? locationSubscription;
|
||||
|
||||
try {
|
||||
locationSubscription =
|
||||
Geolocator.getPositionStream().listen((Position position) {
|
||||
currentPosition = position;
|
||||
// Update camera position on the map
|
||||
mapController!.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: LatLng(position.latitude, position.longitude),
|
||||
zoom: 7,
|
||||
for (var i = 0; i < remainingTimeTimerRideBegin; i++) {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
locationSubscription =
|
||||
Geolocator.getPositionStream().listen((Position position) {
|
||||
currentPosition = position;
|
||||
// Update camera position on the map
|
||||
mapController!.animateCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
target: myLocation,
|
||||
zoom: 17, // Adjust zoom level as needed
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}); // Stop listening to GPS updates when the ride is finished
|
||||
);
|
||||
});
|
||||
update();
|
||||
}
|
||||
|
||||
// Stop listening after ride finishes
|
||||
if (!isRideBegin) {
|
||||
locationSubscription?.cancel();
|
||||
}
|
||||
} catch (error) {
|
||||
debugPrint('Error listening to GPS: $error');
|
||||
// Handle GPS errors gracefully, e.g., show a user-friendly message
|
||||
// Handle GPS errors gracefully
|
||||
}
|
||||
|
||||
update();
|
||||
print('...................');
|
||||
print(d);
|
||||
print('...................');
|
||||
// Periodically call updateLocation again
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
updateLocation();
|
||||
}
|
||||
|
||||
calculateDistanseBetweenDriverAndPassengerLocation() {
|
||||
@@ -527,6 +571,7 @@ class MapDriverController extends GetxController {
|
||||
int seconds = remainingTimeTimerRideBegin % 60;
|
||||
stringRemainingTimeRideBegin =
|
||||
'$minutes:${seconds.toString().padLeft(2, '0')}';
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user