This commit is contained in:
Hamza-Ayed
2023-10-06 12:02:34 +03:00
parent edc3a4348d
commit 54e948e93b
14 changed files with 505 additions and 75 deletions

View File

@@ -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,
}),

View File

@@ -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');
}
}

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -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',

View File

@@ -26,9 +26,7 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print('===========back===${message.notification?.title}');
if (message.notification!.title == 'Sefer') {
// SendGpsNow().getSiteNotification();
}
if (message.notification!.title == 'Sefer') {}
}
void main() async {

View File

@@ -314,7 +314,7 @@ class MapPage extends StatelessWidget {
timerForCancelTripFromPassenger(),
// const DriverTimeArrivePassengerPage(),
const TimerToPassengerFromDriver(),
const PassengerInfoWindow()
// const PassengerInfoWindow()
],
),
),

View File

@@ -12,7 +12,8 @@ import '../../../controller/home/map_page_controller.dart';
GetBuilder<MapController> buttomSheetMapPage() {
Get.put(PaymentController());
return GetBuilder<MapController>(
builder: (controller) => controller.isBottomSheetShown
builder: (controller) => controller.isBottomSheetShown &&
controller.rideConfirm == false
? Positioned(
left: 5,
bottom: 0,

View File

@@ -1,8 +1,17 @@
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/material.dart';
import 'package:get/get.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/home/captin/map_dirction.dart';
import 'package:ride/main.dart';
import 'package:ride/views/widgets/elevated_btn.dart';
import '../../../constant/links.dart';
import '../../../constant/style.dart';
import '../../../controller/home/map_page_controller.dart';
import '../../../controller/functions/crud.dart';
import '../../../controller/functions/launch.dart';
class PassengerInfoWindow extends StatelessWidget {
const PassengerInfoWindow({
@@ -11,18 +20,215 @@ class PassengerInfoWindow extends StatelessWidget {
@override
Widget build(BuildContext context) {
Get.put(MapController());
return GetBuilder<MapController>(
builder: (controller) => controller.isPassengerInfoWindow
? Positioned(
bottom: 2,
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
height: controller.passengerInfoWindow,
width: Get.width,
decoration: AppStyle.boxDecoration,
Get.put(MapDirection());
return GetBuilder<MapDirection>(
builder: (controller) => controller.isPassengerInfoWindow == true
? Stack(
children: [
Positioned(
bottom: 6,
left: 8,
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
height: controller.passengerInfoWindow,
width: Get.width * .8,
decoration: AppStyle.boxDecoration,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DefaultTextStyle(
style: AppStyle.title,
child: AnimatedTextKit(
animatedTexts: [
ScaleAnimatedText(
'Go to passenger Location now'.tr,
),
WavyAnimatedText(
'Go to passenger Location now'.tr),
FlickerAnimatedText(
'Go to passenger Location now'.tr),
WavyAnimatedText(
'Go to passenger Location now'.tr),
],
isRepeatingAnimation: true,
onTap: () {
// print("Tap Event");
},
),
),
Row(
children: [
Text('Duration of the Ride is '.tr,
style: AppStyle.title),
Text(
controller.duration.toString() +
' ' +
'Minute'.tr,
style: AppStyle.title),
],
),
Row(
children: [
Text('Distance of the Ride is '.tr,
style: AppStyle.title),
Text(
controller.distance.toString() + ' ' + 'KM'.tr,
style: AppStyle.title,
),
],
),
Row(
children: [
Text('Name of the Passenger is '.tr,
style: AppStyle.title),
Text(
controller.name.toString(),
style: AppStyle.title,
),
],
),
controller.isRideBegin
? const SizedBox()
: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () {
launchCommunication('phone',
controller.phone.toString(), '');
},
icon: const Icon(
Icons.phone,
color: AppColor.blueColor,
)),
IconButton(
onPressed: () {
launchCommunication(
'whatsapp',
controller.phone.toString(),
'Hello this is Captain ${box.read(BoxName.nameDriver)}');
},
icon: const Icon(
Icons.whatshot,
color: AppColor.greenColor,
)),
IconButton(
onPressed: () {
launchCommunication(
'sms',
controller.phone.toString(),
'Hello this is Captain ${box.read(BoxName.nameDriver)}');
},
icon: const Icon(
Icons.sms_rounded,
color: AppColor.blueColor,
)),
IconButton(
onPressed: () {
launchCommunication(
'email',
controller.phone.toString(),
'Hello this is Captain ${box.read(BoxName.nameDriver)}');
},
icon: const Icon(
Icons.email,
color: AppColor.redColor,
)),
IconButton(
onPressed: () =>
FirebaseMessagesController()
.sendNotificationToPassengerToken(
'Hi',
'body',
controller.tokenPassenger,
[]),
icon:
const Icon(Icons.notification_add))
],
),
controller.remainingTimeToPassenger != 0
? Stack(
children: [
LinearProgressIndicator(
backgroundColor: AppColor.accentColor,
color:
controller.remainingTimeToPassenger <
60
? AppColor.redColor
: AppColor.greenColor,
minHeight: 50,
borderRadius: BorderRadius.circular(15),
value: controller.progressToPassenger
.toDouble(),
),
Center(
child: Text(
controller.remainingTimeToPassenger
.toString() +
' Seconds'.tr,
style: AppStyle.title,
),
)
],
)
: controller.isRideBegin
? const SizedBox()
: MyElevatedButton(
title: 'Start the Ride'.tr,
onPressed: () {
controller.beginRideFromDriver();
}),
],
),
),
),
),
)
: const SizedBox());
],
)
: Positioned(
bottom: Get.height * .3,
left: 15,
child: Container(
decoration: AppStyle.boxDecoration,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Stack(
alignment: Alignment.center,
children: [
const CircularProgressIndicator(
backgroundColor: AppColor.redColor,
strokeWidth: 10,
color: AppColor.redColor,
value: 1,
),
CircularProgressIndicator(
value: controller.progress,
// Set the color based on the "isNearEnd" condition
color: AppColor.yellowColor,
),
Text(
'${controller.remainingTimeToShowPassengerInfoWindowFromDriver}',
style: AppStyle.number,
),
],
),
const SizedBox(
width: 10,
),
Text(
'Please Wait If passenger want To Cancel!'.tr,
style: AppStyle.title,
),
],
),
),
),
),
);
}
}

View File

@@ -15,19 +15,36 @@ GetBuilder<MapController> timerForCancelTripFromPassenger() {
? Positioned(
bottom: Get.height * .35,
left: Get.width * .05,
child: Stack(
alignment: Alignment.center,
children: [
CircularProgressIndicator(
value: controller.progress,
// Set the color based on the "isNearEnd" condition
color: isNearEnd ? Colors.red : Colors.blue,
child: Container(
decoration: AppStyle.boxDecoration,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Stack(
alignment: Alignment.center,
children: [
CircularProgressIndicator(
value: controller.progress,
// Set the color based on the "isNearEnd" condition
color: isNearEnd ? Colors.red : Colors.blue,
),
Text(
'${controller.remainingTime}',
style: AppStyle.number,
),
],
),
const SizedBox(
width: 30,
),
Text(
'You can cancel Ride now'.tr,
style: AppStyle.title,
)
],
),
Text(
'${controller.remainingTime}',
style: AppStyle.number,
),
],
),
),
)
: const SizedBox();

View File

@@ -78,7 +78,7 @@ class TimerToPassengerFromDriver extends StatelessWidget {
controller.driverArrivePassenger();
// Send notification to driver to alert him that trip is begin
FirebaseMessagesController()
.sendNotificationToDriverId(
.sendNotificationToAnyWithoutData(
'BeginTrip',
box.read(BoxName.name).toString(),
controller.driverToken.toString(),

View File

@@ -74,7 +74,7 @@ class OrderRequestPage extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: RichText(
text: TextSpan(
text: 'Tatal From Passenger is '.tr,
text: 'Total From Passenger is '.tr,
style: AppStyle.title,
children: [
TextSpan(
@@ -116,7 +116,7 @@ class OrderRequestPage extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: RichText(
text: TextSpan(
text: 'Tatal For You is '.tr,
text: 'Total For You is '.tr,
style: AppStyle.title,
children: [
TextSpan(
@@ -179,7 +179,7 @@ class OrderRequestPage extends StatelessWidget {
];
// print(bodyToPassenger);
FirebaseMessagesController()
.sendNotificanToPassengerToken(
.sendNotificationToPassengerToken(
'Apply Ride',
arguments['DriverList'][9].toString(),
arguments['DriverList'][9].toString(),
@@ -189,6 +189,16 @@ class OrderRequestPage extends StatelessWidget {
Get.back();
Get.to(() => PassengerLocationDirection(), arguments: {
'passengerLocation': myList[0].toString(),
'Duration': myList[4].toString(),
'Distance': myList[5].toString(),
'name': myList[8].toString(),
'phone': myList[10].toString(),
'WalletChecked': myList[13].toString(),
'tokenPassenger': myList[9].toString(),
'direction':
'https://www.google.com/maps/dir/${myList[0]}/${myList[1]}/',
'DurationToPassenger': myList[15].toString(),
'rideId': myList[16].toString(),
});
},
),
@@ -225,7 +235,7 @@ class OrderRequestPage extends StatelessWidget {
myList[6].toString(), body.toString());
FirebaseMessagesController()
.sendNotificanToPassengerToken(
.sendNotificationToPassengerToken(
'Refused Ride',
arguments['DriverList'][9].toString(),
arguments['DriverList'][9].toString(),

View File

@@ -5,6 +5,8 @@ import 'package:ride/controller/home/captin/map_dirction.dart';
import 'package:ride/views/widgets/my_scafold.dart';
import '../../constant/colors.dart';
import '../../constant/style.dart';
import '../../controller/functions/launch.dart';
import '../../controller/functions/location_controller.dart';
import '../home/map_widget.dart/passenger_info_window.dart';
import '../home/map_widget.dart/timer_to_passenger_from_driver.dart';
@@ -24,10 +26,18 @@ class PassengerLocationDirection extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: GetBuilder<MapDirection>(
builder: (controller) => GoogleMap(
onMapCreated: controller.onMapCreated,
initialCameraPosition: CameraPosition(
target: locationController.myLocation,
zoom: 15,
),
// onCameraMove: (position) {
// locationController.myLocation = position.target;
// print(position);
// },
minMaxZoomPreference: const MinMaxZoomPreference(6, 18),
buildingsEnabled: true,
mapToolbarEnabled: true,
polylines: {
Polyline(
zIndex: 2,
@@ -55,14 +65,10 @@ class PassengerLocationDirection extends StatelessWidget {
),
),
},
onCameraMove: (cameraPosition) {
controller.updateMarker();
},
),
),
),
// const TimerToPassengerFromDriver(),
const PassengerInfoWindow()
const PassengerInfoWindow(),
],
isleading: true);
}