6/9/1
This commit is contained in:
@@ -5,6 +5,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:SEFER/controller/functions/tts.dart';
|
||||
import 'package:SEFER/views/home/map_page_passenger.dart';
|
||||
import 'package:SEFER/views/widgets/my_textField.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -44,7 +45,7 @@ class MapPassengerController extends GetxController {
|
||||
TextEditingController wayPoint4Controller = TextEditingController();
|
||||
TextEditingController sosPhonePassengerProfile = TextEditingController();
|
||||
final sosFormKey = GlobalKey<FormState>();
|
||||
final increasFeeFormKey = GlobalKey<FormState>();
|
||||
final increaseFeeFormKey = GlobalKey<FormState>();
|
||||
List data = [];
|
||||
List<LatLng> bounds = [];
|
||||
List placesStart = [];
|
||||
@@ -338,7 +339,7 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
|
||||
increaseFeeByPassengerAndReOrder() async {
|
||||
if (increasFeeFormKey.currentState!.validate()) {
|
||||
if (increaseFeeFormKey.currentState!.validate()) {
|
||||
if (double.parse(increasFeeFromPassenger.text) > totalPassenger) {
|
||||
totalPassenger = double.parse(increasFeeFromPassenger.text);
|
||||
Get.back();
|
||||
@@ -675,6 +676,16 @@ class MapPassengerController extends GetxController {
|
||||
box.write(BoxName.arrivalTime, '');
|
||||
remainingTimeTimerRideBegin = 0;
|
||||
box.write(BoxName.passengerWalletTotal, '0');
|
||||
if (box.read(BoxName.parentTripSelected) == true) {
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
"Finish Monitor",
|
||||
"Finish Monitor".tr,
|
||||
box.read(BoxName.tokenParent),
|
||||
[],
|
||||
);
|
||||
box.write(BoxName.parentTripSelected, false);
|
||||
box.remove(BoxName.tokenParent);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -1088,32 +1099,35 @@ class MapPassengerController extends GetxController {
|
||||
Timer(const Duration(milliseconds: 200), () async {
|
||||
if (shouldFetch) {
|
||||
// //print('shouldFetch is =$shouldFetch');
|
||||
var res = await getRideStatus(rideId);
|
||||
// print(res);
|
||||
// var decod = jsonDecode(res);
|
||||
print(
|
||||
' 000000000000000000delayAndFetchRideStatus0000000000000000000000000000000');
|
||||
print(res);
|
||||
if (res.toString() == 'Apply') {
|
||||
// getUpdatedRideForDriverApply(rideId);
|
||||
shouldFetch = false; // Stop further fetches
|
||||
statusRide = 'Apply';
|
||||
rideConfirm = false;
|
||||
isSearchingWindow = false;
|
||||
update();
|
||||
startTimerFromDriverToPassengerAfterApplied();
|
||||
// startTimer();
|
||||
} else if (res.toString() == 'Refused') {
|
||||
statusRide = 'Refused';
|
||||
// isDriversTokensSend = false;
|
||||
if (isDriversTokensSend == false) {
|
||||
confirmRideForAllDriverAvailable();
|
||||
isDriversTokensSend = true;
|
||||
if (remainingTimeToPassengerFromDriverAfterApplied > 0) {
|
||||
var res = await getRideStatus(rideId);
|
||||
|
||||
// print(res);
|
||||
// var decod = jsonDecode(res);
|
||||
print(
|
||||
' 000000000000000000delayAndFetchRideStatus0000000000000000000000000000000');
|
||||
print(res);
|
||||
if (res.toString() == 'Apply') {
|
||||
// getUpdatedRideForDriverApply(rideId);
|
||||
shouldFetch = false; // Stop further fetches
|
||||
statusRide = 'Apply';
|
||||
rideConfirm = false;
|
||||
isSearchingWindow = false;
|
||||
update();
|
||||
startTimerFromDriverToPassengerAfterApplied();
|
||||
// startTimer();
|
||||
} else if (res.toString() == 'Refused') {
|
||||
statusRide = 'Refused';
|
||||
// isDriversTokensSend = false;
|
||||
if (isDriversTokensSend == false) {
|
||||
confirmRideForAllDriverAvailable();
|
||||
isDriversTokensSend = true;
|
||||
}
|
||||
} else if (isDriversTokensSend == false) {
|
||||
delayAndFetchRideStatus(
|
||||
rideId); // Repeat the delay and fetch operation
|
||||
update();
|
||||
}
|
||||
} else if (isDriversTokensSend == false) {
|
||||
delayAndFetchRideStatus(
|
||||
rideId); // Repeat the delay and fetch operation
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1210,7 +1224,7 @@ class MapPassengerController extends GetxController {
|
||||
driverRate = response['data']['ratingDriver'];
|
||||
}
|
||||
driversToken.remove(driverToken);
|
||||
for (var i = 0; i < driversToken.length; i++) {
|
||||
for (var i = 1; i < driversToken.length; i++) {
|
||||
FirebaseMessagesController().sendNotificationToAnyWithoutData(
|
||||
'Order Applied',
|
||||
'$driverName Apply order\nTake attention in other order'.tr,
|
||||
@@ -1310,6 +1324,107 @@ class MapPassengerController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future getTokenForParent() async {
|
||||
if (box.read(BoxName.sosPhonePassenger) == null) {
|
||||
Get.defaultDialog(
|
||||
title: 'Add SOS Phone'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
content: Form(
|
||||
key: sosFormKey,
|
||||
child: MyTextForm(
|
||||
controller: sosPhonePassengerProfile,
|
||||
label: 'insert sos phone'.tr,
|
||||
hint: 'insert sos phone'.tr,
|
||||
type: TextInputType.phone,
|
||||
),
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Add SOS Phone'.tr,
|
||||
onPressed: () async {
|
||||
if (sosFormKey.currentState!.validate()) {
|
||||
Get.back();
|
||||
await CRUD().post(
|
||||
link: AppLink.updateprofile,
|
||||
payload: {
|
||||
'id': box.read(BoxName.passengerID),
|
||||
'sosPhone': sosPhonePassengerProfile.text,
|
||||
},
|
||||
);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
var res = await CRUD().getTokenParent(
|
||||
link: AppLink.getTokenParent,
|
||||
payload: {'phone': '+2' + box.read(BoxName.sosPhonePassenger)});
|
||||
|
||||
// Check if `res` is already a map
|
||||
if (res is Map<String, dynamic>) {
|
||||
var res1 = res;
|
||||
handleResponse(res1);
|
||||
} else {
|
||||
// If it's a string, decode it
|
||||
var res1 = jsonDecode(res);
|
||||
handleResponse(res1);
|
||||
}
|
||||
}
|
||||
|
||||
void handleResponse(Map<String, dynamic> res1) {
|
||||
if (res1['message'] == "No passenger found for the given phone number") {
|
||||
print(res1);
|
||||
Get.defaultDialog(
|
||||
title: "No user found for the given phone number".tr,
|
||||
titleStyle: AppStyle.title,
|
||||
content: Column(
|
||||
children: [
|
||||
Text(
|
||||
"No passenger found for the given phone number".tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
"Send Sefer app to him".tr,
|
||||
style: AppStyle.title.copyWith(color: AppColor.greenColor),
|
||||
)
|
||||
],
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
var phone = box.read(BoxName.countryCode) == 'Egypt'
|
||||
? '+2${box.read(BoxName.sosPhonePassenger)}'
|
||||
: '+962${box.read(BoxName.sosPhonePassenger)}';
|
||||
var message = '''Dear ,
|
||||
|
||||
🚀 I have just started an exciting trip and I would like to share the details of my journey and my current location with you in real-time! Please download the SEFER app. It will allow you to view my trip details and my latest location.
|
||||
|
||||
👉 Download link:
|
||||
Android [https://play.google.com/store/apps/details?id=com.mobileapp.store.ride]
|
||||
iOS [https://getapp.cc/app/6458734951]
|
||||
|
||||
I look forward to keeping you close during my adventure!
|
||||
|
||||
SEFER ,'''
|
||||
.tr;
|
||||
launchCommunication('whatsapp', phone, message);
|
||||
}),
|
||||
cancel: MyElevatedButton(
|
||||
title: 'No'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
} else if (res1['status'] == 'success') {
|
||||
var tokenParent = res1['data'][0]['token'];
|
||||
FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
"Trip Monitoring",
|
||||
"Trip Monitoring".tr,
|
||||
tokenParent,
|
||||
[rideId, driverId]);
|
||||
box.write(BoxName.parentTripSelected, true);
|
||||
box.write(BoxName.tokenParent, tokenParent);
|
||||
}
|
||||
}
|
||||
|
||||
LatLng driverLocationToPassenger = const LatLng(32, 35);
|
||||
Future getDriverCarsLocationToPassengerAfterApplied() async {
|
||||
driverCarsLocationToPassengerAfterApplied = [];
|
||||
|
||||
@@ -28,7 +28,7 @@ class ComplaintController extends GetxController {
|
||||
Get.defaultDialog(
|
||||
title: 'Success'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
middleText: 'Feedback data saved successfully'.tr,
|
||||
middleText: 'Complaint data saved successfully'.tr,
|
||||
middleTextStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
kolor: AppColor.greenColor,
|
||||
|
||||
@@ -19,16 +19,16 @@ class PromosController extends GetxController {
|
||||
Future getPromoByToday() async {
|
||||
var res = await CRUD().get(link: AppLink.getPromoBytody, payload: {});
|
||||
if (res.toString() == 'failure') {
|
||||
Get.defaultDialog(
|
||||
title: 'No Promo for today .'.tr,
|
||||
middleText: '',
|
||||
titleStyle: AppStyle.title,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Back'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
Get.back();
|
||||
}));
|
||||
// Get.defaultDialog(
|
||||
// title: 'No Promo for today .'.tr,
|
||||
// middleText: '',
|
||||
// titleStyle: AppStyle.title,
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Back'.tr,
|
||||
// onPressed: () {
|
||||
// Get.back();
|
||||
// Get.back();
|
||||
// }));
|
||||
isLoading = false;
|
||||
update();
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:SEFER/constant/links.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
class TripMonitorController extends GetxController {
|
||||
bool isLoading = false;
|
||||
Map tripData = {};
|
||||
late String rideId;
|
||||
late String driverId;
|
||||
GoogleMapController? mapController;
|
||||
List myListString = [];
|
||||
late Timer timer;
|
||||
late LatLng parentLocation;
|
||||
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
|
||||
double rotation = 0;
|
||||
double speed = 0;
|
||||
|
||||
getLocationParent() async {
|
||||
var res = await CRUD().get(
|
||||
link: AppLink.getLocationParents, payload: {"driver_id": driverId});
|
||||
if (res != 'failure') {
|
||||
tripData = jsonDecode(res);
|
||||
parentLocation = LatLng(
|
||||
double.parse(tripData['message'][0]['latitude'].toString()),
|
||||
double.parse(tripData['message'][0]['longitude'].toString()));
|
||||
rotation = double.parse(tripData['message'][0]['heading'].toString());
|
||||
speed = double.parse(tripData['message'][0]['speed'].toString());
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void onMapCreated(GoogleMapController controller) async {
|
||||
mapController = controller;
|
||||
controller.getVisibleRegion();
|
||||
controller.animateCamera(
|
||||
CameraUpdate.newLatLng(parentLocation),
|
||||
);
|
||||
update();
|
||||
// Set up a timer or interval to trigger the marker update every 3 seconds.
|
||||
timer = Timer.periodic(const Duration(seconds: 10), (_) async {
|
||||
await getLocationParent();
|
||||
mapController?.animateCamera(CameraUpdate.newLatLng(parentLocation));
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
init() async {
|
||||
final arguments = Get.arguments;
|
||||
driverId = arguments['driverId'];
|
||||
rideId = arguments['rideId'];
|
||||
await getLocationParent();
|
||||
}
|
||||
|
||||
void addCustomCarIcon() {
|
||||
ImageConfiguration config = ImageConfiguration(
|
||||
size: const Size(30, 30), devicePixelRatio: Get.pixelRatio);
|
||||
BitmapDescriptor.fromAssetImage(config, 'assets/images/car.png',
|
||||
mipmaps: false)
|
||||
.then((value) {
|
||||
carIcon = value;
|
||||
update();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
addCustomCarIcon();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
timer.cancel();
|
||||
mapController?.dispose();
|
||||
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user