10/6/1
This commit is contained in:
@@ -96,8 +96,11 @@ class FirebaseMessagesController extends GetxController {
|
||||
|
||||
Future getToken() async {
|
||||
fcmToken.getToken().then((token) {
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
box.write(BoxName.tokenDriver, token);
|
||||
if (box.read(BoxName.email) == null) {
|
||||
box.write(BoxName.tokenDriver, token);
|
||||
} else {
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
}
|
||||
print(token);
|
||||
});
|
||||
|
||||
@@ -184,7 +187,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
);
|
||||
} else if (message.notification!.title!.contains('Promo')) {
|
||||
Get.to(const PromosPassengerPage());
|
||||
} else if (message.notification!.title!.contains('BeginTrip')) {
|
||||
} else if (message.notification!.title!.contains('RideIsBegin')) {
|
||||
// MapDirection mapDirection = Get.find<MapDirection>();
|
||||
// mapDirection.clearPolyline();
|
||||
print('jjjjjjjjjjjjjjjjjjjjjjjjjjj');
|
||||
@@ -371,6 +374,15 @@ class FirebaseMessagesController extends GetxController {
|
||||
);
|
||||
} else if (message.notification!.title!.contains('Promo')) {
|
||||
Get.to(const PromosPassengerPage());
|
||||
} else if (message.notification!.title!.contains('RideIsBegin')) {
|
||||
// MapDirection mapDirection = Get.find<MapDirection>();
|
||||
// mapDirection.clearPolyline();
|
||||
print('jjjjjjjjjjjjjjjjjjjjjjjjjjj');
|
||||
Get.defaultDialog(
|
||||
title: 'The Ride is Begin'.tr,
|
||||
backgroundColor: AppColor.greenColor,
|
||||
);
|
||||
MapDirection().clearPolyline();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -442,7 +454,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
// }
|
||||
// }
|
||||
|
||||
void sendNotificanToPassengerToken(
|
||||
void sendNotificationToPassengerToken(
|
||||
String title, body, token, List<String> map) async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
@@ -479,7 +491,7 @@ class FirebaseMessagesController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void sendNotificationToDriverId(
|
||||
void sendNotificationToAnyWithoutData(
|
||||
String title, String body, String token) async {
|
||||
try {
|
||||
final response = await http.post(
|
||||
@@ -494,7 +506,11 @@ class FirebaseMessagesController extends GetxController {
|
||||
'body': body,
|
||||
'sound': 'true'
|
||||
},
|
||||
'data': {},
|
||||
'data': <String, dynamic>{
|
||||
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
|
||||
'id': '1',
|
||||
'status': 'done'
|
||||
},
|
||||
'priority': 'high',
|
||||
'to': token,
|
||||
}),
|
||||
|
||||
@@ -7,3 +7,32 @@ void launchUrl1(String url) async {
|
||||
print('Could not launch $url');
|
||||
}
|
||||
}
|
||||
|
||||
void launchCommunication(
|
||||
String method, String contactInfo, String message) async {
|
||||
String url;
|
||||
|
||||
switch (method) {
|
||||
case 'phone':
|
||||
url = 'tel:$contactInfo';
|
||||
break;
|
||||
case 'sms':
|
||||
url = 'sms:$contactInfo?body=$message';
|
||||
break;
|
||||
case 'whatsapp':
|
||||
url = 'whatsapp://send?phone=$contactInfo&text=$message';
|
||||
break;
|
||||
case 'email':
|
||||
url = 'mailto:$contactInfo?subject=Subject&body=$message';
|
||||
break;
|
||||
default:
|
||||
print('Invalid communication method');
|
||||
return;
|
||||
}
|
||||
|
||||
if (await canLaunchUrl(Uri.parse(url))) {
|
||||
launchUrl(Uri.parse(url));
|
||||
} else {
|
||||
print('Could not launch $url');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ class LocationController extends GetxController {
|
||||
: null)!;
|
||||
|
||||
// Print location details
|
||||
// print('Accuracy: ${_locationData.accuracy}');
|
||||
// print('Latitude: ${_locationData.latitude}');
|
||||
// print('Longitude: ${_locationData.longitude}');
|
||||
// print('Time: ${_locationData.time}');
|
||||
print('Accuracy: ${_locationData.accuracy}');
|
||||
print('Latitude: ${_locationData.latitude}');
|
||||
print('Longitude: ${_locationData.longitude}');
|
||||
print('Time: ${_locationData.time}');
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ import 'package:get/get.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../constant/links.dart';
|
||||
import '../../../main.dart';
|
||||
import '../../functions/crud.dart';
|
||||
import '../../functions/location_controller.dart';
|
||||
|
||||
class HomeCaptainController extends GetxController {
|
||||
@@ -50,6 +52,15 @@ class HomeCaptainController extends GetxController {
|
||||
return totalDuration;
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
await CRUD().post(link: AppLink.addTokensDriver, payload: {
|
||||
'token': box.read(BoxName.tokenDriver),
|
||||
'captain_id': box.read(BoxName.driverID).toString()
|
||||
}).then((value) => print('cccc'));
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
activeTimer?.cancel();
|
||||
|
||||
@@ -4,8 +4,11 @@ import 'package:flutter/material.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:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/controller/firebase/firbase_messge.dart';
|
||||
import 'package:ride/controller/functions/location_controller.dart';
|
||||
import 'package:ride/main.dart';
|
||||
|
||||
import '../../../constant/credential.dart';
|
||||
import '../../../constant/links.dart';
|
||||
@@ -19,6 +22,70 @@ class MapDirection extends GetxController {
|
||||
final List<LatLng> polylineCoordinates = [];
|
||||
List<Polyline> polyLines = [];
|
||||
Set<Marker> markers = {};
|
||||
late String passengerLocation;
|
||||
late String duration;
|
||||
late String distance;
|
||||
late String name;
|
||||
late String phone;
|
||||
late String rideId;
|
||||
late String tokenPassenger;
|
||||
late String durationToPassenger;
|
||||
late String walletChecked;
|
||||
late String direction;
|
||||
bool isPassengerInfoWindow = false;
|
||||
bool isBtnRideBegin = false;
|
||||
double passengerInfoWindow = Get.height * .32;
|
||||
double progress = 0;
|
||||
double progressToPassenger = 0;
|
||||
bool isRideBegin = false;
|
||||
int progressTimerToShowPassengerInfoWindowFromDriver = 25;
|
||||
int remainingTimeToShowPassengerInfoWindowFromDriver = 25;
|
||||
int remainingTimeToPassenger = 60;
|
||||
bool isDriverNearPassengerStart = false;
|
||||
GoogleMapController? mapController;
|
||||
late LatLng myLocation;
|
||||
|
||||
void onMapCreated(GoogleMapController controller) {
|
||||
LocationController locationController = Get.find<LocationController>();
|
||||
myLocation = locationController.myLocation;
|
||||
mapController = controller;
|
||||
controller.getVisibleRegion();
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(myLocation),
|
||||
);
|
||||
update();
|
||||
|
||||
// Set up a timer or interval to trigger the marker update every 3 seconds.
|
||||
Timer.periodic(const Duration(seconds: 3), (_) {
|
||||
updateMarker();
|
||||
});
|
||||
}
|
||||
|
||||
void checkIsDriverNearPassenger() async {
|
||||
if (isDriverNearPassengerStart) {
|
||||
Timer.periodic(const Duration(seconds: 3), (timer) {
|
||||
String driverLat =
|
||||
Get.find<LocationController>().myLocation.latitude.toString();
|
||||
String driverLng =
|
||||
Get.find<LocationController>().myLocation.longitude.toString();
|
||||
|
||||
// Replace "passengerLat" and "passengerLng" with the actual passenger's location
|
||||
String passengerLat = passengerLocation; // Set the passenger's latitude
|
||||
String passengerLng = ""; // Set the passenger's longitude
|
||||
|
||||
// double distance = calculateDistance(
|
||||
// double.parse(driverLat),
|
||||
// double.parse(driverLng),
|
||||
// double.parse(passengerLat),
|
||||
// double.parse(passengerLng),
|
||||
// );
|
||||
|
||||
// if (distance < 50) {
|
||||
// print("Distance to passenger: $distance meters");
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void clearPolyline() {
|
||||
polyLines = [];
|
||||
@@ -26,29 +93,87 @@ class MapDirection extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
void changeRideToBegin() {
|
||||
isRideBegin = true;
|
||||
passengerInfoWindow = Get.height * .22;
|
||||
update();
|
||||
}
|
||||
|
||||
void startTimerToShowPassengerInfoWindowFromDriver() async {
|
||||
for (int i = 0;
|
||||
i <= progressTimerToShowPassengerInfoWindowFromDriver;
|
||||
i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
progress = i / progressTimerToShowPassengerInfoWindowFromDriver;
|
||||
remainingTimeToShowPassengerInfoWindowFromDriver =
|
||||
progressTimerToShowPassengerInfoWindowFromDriver - i;
|
||||
if (remainingTimeToShowPassengerInfoWindowFromDriver == 0) {
|
||||
isPassengerInfoWindow = true;
|
||||
print(isPassengerInfoWindow);
|
||||
update();
|
||||
startTimerToShowDriverToPassengerDuration();
|
||||
}
|
||||
print(isPassengerInfoWindow);
|
||||
print(remainingTimeToShowPassengerInfoWindowFromDriver);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void startTimerToShowDriverToPassengerDuration() async {
|
||||
for (int i = 0; i <= int.parse(durationToPassenger); i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
progressToPassenger = i / int.parse(durationToPassenger);
|
||||
remainingTimeToPassenger = int.parse(durationToPassenger) - i;
|
||||
if (remainingTimeToPassenger == 0) {
|
||||
isBtnRideBegin = true;
|
||||
print(isBtnRideBegin);
|
||||
update();
|
||||
}
|
||||
print(isBtnRideBegin);
|
||||
print(remainingTimeToPassenger);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
beginRideFromDriver() async {
|
||||
changeRideToBegin();
|
||||
await CRUD().post(link: AppLink.updateRides, payload: {
|
||||
'id': rideId,
|
||||
'rideTimeStart': DateTime.now().toString(),
|
||||
'status': 'Applied'
|
||||
});
|
||||
FirebaseMessagesController().sendNotificationToAnyWithoutData('RideIsBegin',
|
||||
box.read(BoxName.tokenDriver).toString(), tokenPassenger);
|
||||
}
|
||||
|
||||
void updateMarker() {
|
||||
// Remove the existing marker with the ID `MyLocation`.
|
||||
markers.remove(MarkerId('MyLocation'.tr));
|
||||
|
||||
// Add a new marker with the ID `MyLocation` at the current location of the user.
|
||||
LocationController locationController = Get.find<LocationController>();
|
||||
markers.add(Marker(
|
||||
markerId: MarkerId('MyLocation'.tr),
|
||||
position: locationController.myLocation,
|
||||
draggable: true,
|
||||
icon: carIcon,
|
||||
// infoWindow: const InfoWindow(
|
||||
// title: 'Time',
|
||||
// ),
|
||||
));
|
||||
myLocation = locationController.myLocation;
|
||||
markers.add(
|
||||
Marker(
|
||||
markerId: MarkerId('MyLocation'.tr),
|
||||
position: locationController.myLocation,
|
||||
draggable: true,
|
||||
icon: carIcon,
|
||||
// infoWindow: const InfoWindow(
|
||||
// title: 'Time',
|
||||
// ),
|
||||
),
|
||||
);
|
||||
|
||||
// Update the `markers` set and call the `update()` method on the controller to notify the view that the marker position has changed.
|
||||
update();
|
||||
|
||||
// Reload the marker after 3 seconds.
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
updateMarker();
|
||||
});
|
||||
// No recursive call here. The marker update will be triggered externally.
|
||||
|
||||
// Optionally, you can animate the camera to the new location after updating the marker.
|
||||
mapController!.animateCamera(
|
||||
CameraUpdate.newLatLng(locationController.myLocation),
|
||||
);
|
||||
}
|
||||
|
||||
void addCustomCarIcon() {
|
||||
@@ -106,17 +231,34 @@ class MapDirection extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void changePassengerInfoWindow() {
|
||||
isPassengerInfoWindow = !isPassengerInfoWindow;
|
||||
passengerInfoWindow = isPassengerInfoWindow == true ? 200 : 0;
|
||||
update();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// Get the passenger location from the arguments.
|
||||
String passengerLocation = Get.arguments['passengerLocation'];
|
||||
passengerLocation = Get.arguments['passengerLocation'];
|
||||
duration = Get.arguments['Duration'];
|
||||
distance = Get.arguments['Distance'];
|
||||
name = Get.arguments['name'];
|
||||
phone = Get.arguments['phone'];
|
||||
walletChecked = Get.arguments['WalletChecked'];
|
||||
tokenPassenger = Get.arguments['tokenPassenger'];
|
||||
direction = Get.arguments['direction'];
|
||||
durationToPassenger = Get.arguments['DurationToPassenger'];
|
||||
rideId = Get.arguments['rideId'];
|
||||
String lat = Get.find<LocationController>().myLocation.latitude.toString();
|
||||
String lng = Get.find<LocationController>().myLocation.longitude.toString();
|
||||
String origin = '$lat,$lng';
|
||||
// Set the origin and destination coordinates for the Google Maps directions request.
|
||||
getMap(origin, passengerLocation);
|
||||
addCustomCarIcon();
|
||||
updateMarker();
|
||||
// updateMarker();
|
||||
startTimerToShowPassengerInfoWindowFromDriver();
|
||||
// checkIsDriverNearPassenger();
|
||||
super.onInit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ class MapController extends GetxController {
|
||||
bool isCancelRidePageShown = false;
|
||||
bool isCashConfirmPageShown = false;
|
||||
bool isPaymentMethodPageShown = false;
|
||||
bool isPassengerInfoWindow = false;
|
||||
|
||||
bool rideConfirm = false;
|
||||
bool isMainBottomMenuMap = true;
|
||||
double heightBottomSheetShown = 0;
|
||||
double cashConfirmPageShown = 250;
|
||||
double passengerInfoWindow = 250;
|
||||
|
||||
double widthMapTypeAndTraffic = 50;
|
||||
double paymentPageShown = Get.height * .6;
|
||||
late LatLng southwest;
|
||||
@@ -92,12 +92,6 @@ class MapController extends GetxController {
|
||||
update();
|
||||
}
|
||||
|
||||
void changePassengerInfoWindow() {
|
||||
isPassengerInfoWindow = !isPassengerInfoWindow;
|
||||
passengerInfoWindow = isPassengerInfoWindow == true ? 200 : 0;
|
||||
update();
|
||||
}
|
||||
|
||||
void changePaymentMethodPageShown() {
|
||||
isPaymentMethodPageShown = !isPaymentMethodPageShown;
|
||||
paymentPageShown = isPaymentMethodPageShown == true ? Get.height * .6 : 0;
|
||||
@@ -203,8 +197,6 @@ class MapController extends GetxController {
|
||||
// List<String> body = [
|
||||
rideId = jsonDecode(value)['message'];
|
||||
List<String> body = [
|
||||
// '${data[0]['start_address']}',
|
||||
// '${data[0]['end_address']}',
|
||||
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
|
||||
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
|
||||
totalPassenger.toString(),
|
||||
@@ -220,6 +212,8 @@ class MapController extends GetxController {
|
||||
distanceByPassenger.toString(),
|
||||
paymentController.isWalletChecked.toString(),
|
||||
dataCarsLocationByPassenger['message'][carsOrder]['token'].toString(),
|
||||
duration1.toString(),
|
||||
rideId,
|
||||
];
|
||||
FirebaseMessagesController().sendNotificationToDriverMAP(
|
||||
'Order',
|
||||
|
||||
Reference in New Issue
Block a user