This commit is contained in:
Hamza-Ayed
2024-02-14 22:31:28 +03:00
parent bbd4ce792e
commit ea7a5bb931
28 changed files with 941 additions and 605 deletions

View File

@@ -23,6 +23,7 @@ import '../../views/home/Captin/orderCaptin/order_request_page.dart';
import '../home/map_passenger_controller.dart';
import '../home/payment/captain_wallet_controller.dart';
import '../payment/payment_controller.dart';
import 'local_notification.dart';
class FirebaseMessagesController extends GetxController {
final fcmToken = FirebaseMessaging.instance;
@@ -128,6 +129,9 @@ class FirebaseMessagesController extends GetxController {
void fireBaseTitles(RemoteMessage message) {
if (message.notification!.title! == 'Order') {
if (Platform.isAndroid) {
NotificationController().showNotification('Order', '', 'order');
}
var myListString = message.data['DriverList'];
// print(myListString);
// print('9999999999999myListString999999999999999');
@@ -146,33 +150,57 @@ class FirebaseMessagesController extends GetxController {
// print('9999999999999my Apply Ride 999999999999999');
var myList = jsonDecode(passengerList) as List<dynamic>;
driverID = myList[2].toString();
driverAppliedTripSnakBar();
NotificationController().showNotification(
'Apply Order', 'Driver Applied the Ride for You'.tr, 'order');
// driverAppliedTripSnakBar();
} else if (message.notification!.title! == 'Promo') {
NotificationController()
.showNotification('Promo', 'Show latest promo'.tr, 'order');
Get.to(const PromosPassengerPage());
} else if (message.notification!.title == 'Cancel Trip') {
NotificationController().showNotification(
'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'order');
cancelTripDialog();
} else if (message.notification!.title! == 'DriverIsGoingToPassenger') {
Get.snackbar('Driver is Going To Passenger', '',
backgroundColor: AppColor.greenColor);
NotificationController().showNotification('Driver is Going To You'.tr,
'Please stay on the picked point.'.tr, 'order');
// Get.snackbar('Driver is Going To Passenger', '',
// backgroundColor: AppColor.greenColor);
} else if (message.notification!.title! == 'RideIsBegin') {
Get.snackbar('RideIsBegin', '', backgroundColor: AppColor.greenColor);
// Get.snackbar('RideIsBegin', '', backgroundColor: AppColor.greenColor);
NotificationController()
.showNotification('Trip is Begin'.tr, ''.tr, 'order');
update();
} else if (message.notification!.title! == 'Hi ,I will go now') {
Get.snackbar('Hi ,I will go now', '',
backgroundColor: AppColor.greenColor);
// Get.snackbar('Hi ,I will go now', '',
// backgroundColor: AppColor.greenColor);
NotificationController().showNotification(
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'order');
update();
} else if (message.notification!.title! == 'Hi ,I Arrive your site') {
NotificationController()
.showNotification('Hi ,I Arrive your site'.tr, ''.tr, 'order');
driverArrivePassengerDialoge();
update();
} else if (message.notification!.title! == 'Driver Finish Trip') {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
NotificationController().showNotification(
'Driver Finish Trip'.tr,
'you will pay to Driver'.tr +
' ${Get.find<MapPassengerController>().totalPassenger} \$'.tr,
'order');
if (Get.find<PaymentController>().isCashChecked == false &&
Get.find<PaymentController>().isWalletChecked == true) {
driverFinishTripDialoge(driverList);
} else {
} else if (double.parse(box.read(BoxName.passengerWalletTotal)) < 0) {
CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': box.read(BoxName.passengerID).toString(),
'balance':
((-1) * double.parse(box.read(BoxName.passengerWalletTotal)))
.toString()
});
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
@@ -184,6 +212,11 @@ class FirebaseMessagesController extends GetxController {
// .tr,
// 'message',
// backgroundColor: AppColor.redColor);
NotificationController().showNotification(
'Driver Cancel Your Trip'.tr,
'you will pay to Driver you will be pay the cost of driver time look to your SEFER Wallet'
.tr,
'order');
Get.find<MapPassengerController>().restCounter();
Get.offAll(const MapPagePassenger());
}
@@ -213,6 +246,7 @@ class FirebaseMessagesController extends GetxController {
Future<dynamic> cancelTripDialog() {
return Get.defaultDialog(
barrierDismissible: false,
title: 'Passenger Cancel Trip'.tr,
middleText: '',
confirm: MyElevatedButton(

View File

@@ -0,0 +1,29 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
class NotificationController extends GetxController {
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
// Initializes the local notifications plugin
Future<void> initNotifications() async {
const AndroidInitializationSettings android =
AndroidInitializationSettings('@mipmap/launcher_icon');
const InitializationSettings initializationSettings =
InitializationSettings(android: android);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
}
// Displays a notification with the given title and message
void showNotification(String title, String message, String tone) async {
AndroidNotificationDetails android = AndroidNotificationDetails(
'your channel id', 'your channel name',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
sound: RawResourceAndroidNotificationSound(tone));
NotificationDetails details = NotificationDetails(android: android);
await _flutterLocalNotificationsPlugin.show(0, title, message, details);
}
}

View File

@@ -31,7 +31,7 @@ class LocationController extends GetxController {
}
void startLocationUpdates() async {
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
_locationTimer = Timer.periodic(const Duration(seconds: 10), (timer) async {
try {
totalPoints = Get.find<CaptainWalletController>().totalPoints;
@@ -97,11 +97,11 @@ class LocationController extends GetxController {
: null)!;
// Print location details
print('myLocation: ${myLocation}');
print('Accuracy: ${_locationData.accuracy}');
print('Latitude: ${_locationData.latitude}');
print('Longitude: ${_locationData.longitude}');
print('Time: ${_locationData.time}');
// print('myLocation: ${myLocation}');
// print('Accuracy: ${_locationData.accuracy}');
// print('Latitude: ${_locationData.latitude}');
// print('Longitude: ${_locationData.longitude}');
// print('Time: ${_locationData.time}');
isLoading = false;
update();
}

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:ride/constant/box_name.dart';
import 'package:ride/controller/home/captin/map_driver_controller.dart';
import 'dart:async';
import '../../../constant/links.dart';
@@ -204,11 +205,12 @@ class HomeCaptainController extends GetxController {
}
addToken() async {
box.write(BoxName.statusDriverLocation, 'off');
await CRUD().post(link: AppLink.addTokensDriver, payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString()
}).then((value) => print('Token Added'));
MapDriverController().driverCallPassenger();
// box.write(BoxName.statusDriverLocation, 'off');
}
getPaymentToday() async {

View File

@@ -8,6 +8,7 @@ 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/style.dart';
import 'package:ride/controller/home/captin/home_captain_controller.dart';
import 'package:ride/views/widgets/elevated_btn.dart';
import '../../../constant/api_key.dart';
@@ -45,6 +46,7 @@ class MapDriverController extends GetxController {
late String step3;
late String step4;
late String duration;
late String totalCost;
late String distance;
late String name;
late String phone;
@@ -242,6 +244,46 @@ class MapDriverController extends GetxController {
tokenPassenger);
}
bool isSocialPressed = false;
driverCallPassenger() async {
String scam = await getDriverScam();
if (scam != 'failure') {
if (int.parse(scam) > 3) {
box.write(BoxName.statusDriverLocation, 'on');
Get.find<LocationController>().stopLocationUpdates();
await CRUD().post(link: AppLink.addNotificationCaptain, payload: {
'driverID': box.read(BoxName.driverID),
'title': 'scams operations'.tr,
'body':
'you have connect to passengers and let them cancel the order'.tr,
});
} else if (isSocialPressed == true) {
box.write(BoxName.statusDriverLocation, 'off');
await CRUD().post(link: AppLink.adddriverScam, payload: {
'driverID': box.read(BoxName.driverID),
'passengerID': passengerId,
'rideID': rideId,
'isDriverCalledPassenger': '$isSocialPressed'
});
}
}
}
Future<String> getDriverScam() async {
var res = await CRUD().post(link: AppLink.getdriverScam, payload: {
'driverID': box.read(BoxName.driverID),
});
if (res == 'failure') {
print('Scam is failure');
box.write(BoxName.statusDriverLocation, 'off');
return '0';
}
var d = jsonDecode(res);
print('Scam is ');
print(d['message'][0]['count']);
return d['message'][0]['count'];
}
void startRideFromDriver() async {
changeRideToBeginToPassenger();
isPassengerInfoWindow = false;
@@ -283,14 +325,20 @@ class MapDriverController extends GetxController {
// 'RideIsBegin', box.read(BoxName.name).toString(), tokenPassenger);
}
addWaittingTimeCostFromPassengerToDriverWallet() async {
calculateDistanseBetweenDriverAndPassengerLocation() {
double distance2 = Geolocator.distanceBetween(
latLngpassengerLocation.latitude,
latLngpassengerLocation.longitude,
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
);
if (distance2 > 80) {
return distance2;
}
addWaittingTimeCostFromPassengerToDriverWallet() async {
double distance2 = calculateDistanseBetweenDriverAndPassengerLocation();
if (distance2 > 40) {
Get.defaultDialog(
title: 'Your are far from passenger location'.tr,
middleText:
@@ -321,6 +369,7 @@ class MapDriverController extends GetxController {
'passenger_id': passengerId,
'balance': (cost * -1).toString()
});
box.write(BoxName.statusDriverLocation, 'off');
Get.offAll(HomeCaptain());
}
}
@@ -335,21 +384,30 @@ class MapDriverController extends GetxController {
'rideTimeFinish': DateTime.now().toString(),
'status': 'Finished'
});
Get.back();
if (walletChecked == 'true') {
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': passengerId,
'ba lance': ((-1) * double.parse(totalCost)).toString()
});
}
// Get.back();
Future.delayed(const Duration(milliseconds: 300));
FirebaseMessagesController().sendNotificationToPassengerToken(
'Driver Finish Trip',
'you will pay to Driver'.tr + ' $totalCost \$'.tr,
tokenPassenger,
[
box.read(BoxName.driverID),
rideId,
box.read(BoxName.tokenDriver),
],
);
Get.to(() => RatePassenger(), arguments: {
'rideId': rideId,
'passengerId': passengerId,
'driverId': driverId
});
FirebaseMessagesController().sendNotificationToPassengerToken(
'Driver Finish Trip',
box.read(BoxName.name).toString(),
tokenPassenger, [
box.read(BoxName.driverID),
rideId,
box.read(BoxName.tokenDriver),
]);
}
void cancelCheckRidefromPassenger() async {
@@ -623,6 +681,7 @@ class MapDriverController extends GetxController {
passengerLocation = Get.arguments['passengerLocation'];
passengerDestination = Get.arguments['passengerDestination'];
duration = Get.arguments['Duration'];
totalCost = Get.arguments['totalCost'];
passengerId = Get.arguments['passengerId'];
driverId = Get.arguments['driverId'];
distance = Get.arguments['Distance'];

View File

@@ -3,6 +3,7 @@ import 'package:get/get.dart';
import 'package:ride/constant/links.dart';
import 'package:ride/constant/style.dart';
import 'package:ride/main.dart';
import 'package:ride/views/home/Captin/home_captain/home_captin.dart';
import 'package:ride/views/widgets/elevated_btn.dart';
import '../../../constant/box_name.dart';
@@ -38,7 +39,7 @@ class OrderRequestController extends GetxController {
String driverId = box.read(BoxName.driverID).toString();
String customQuery = '''
SELECT COUNT(*) AS count
SELECT COUNT(*) AS count
FROM ${TableName.driverOrdersRefuse}
WHERE driver_id = '$driverId'
AND created_at LIKE '%$todayDay%'
@@ -95,12 +96,16 @@ class OrderRequestController extends GetxController {
'status': 'Refused'
});
Get.back();
// applied = true;
sql.insertData({
'order_id': orderID,
'created_at': DateTime.now().toString(),
'driver_id': box.read(BoxName.driverID).toString(),
'rideId': orderID
}, TableName.driverOrdersRefuse);
getRefusedOrderByCaptain();
box.write(BoxName.statusDriverLocation, 'off');
update();
// Get.offAll(HomeCaptain());
}
}

View File

@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:ride/controller/home/payment/captain_wallet_controller.dart';
import 'package:ride/views/home/my_wallet/walet_captain.dart';
import '../../../../constant/style.dart';
import '../../../../views/widgets/elevated_btn.dart';
@@ -34,7 +33,7 @@ class ConnectWidget extends StatelessWidget {
barrierDismissible: false,
title: double.parse(captainWalletController.totalPoints) <
-100
? 'You dont have Points'
? 'You dont have Points'.tr
: 'You Are Stopped For this Day !'.tr,
titleStyle: AppStyle.title,
content: Text(

View File

@@ -184,10 +184,11 @@ class MapPassengerController extends GetxController {
late double totalME = 0;
late double tax = 0;
late double totalPassenger = 0;
late double totalCostPassenger = 0;
late double totalDriver = 0;
late double averageDuration = 0;
late double costDuration = 0;
late double cost = 0;
late double costDistance = 0;
late double distance = 0;
late double duration = 0;
@@ -514,19 +515,24 @@ class MapPassengerController extends GetxController {
update();
}
rideTimerBegin = false;
isRideFinished = true;
update();
//print('rideTimerBegin: $rideTimerBegin');
//print('isRideFinished: $isRideFinished');
if (Get.find<PaymentController>().isWalletChecked == true &&
Get.find<PaymentController>().isCashChecked == false) {
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
'passenger_id': box.read(BoxName.passengerID).toString(),
'balance': ((-1) * totalPassenger).toString()
});
}
// if (Get.find<PaymentController>().isWalletChecked == true &&
// Get.find<PaymentController>().isCashChecked == false) {
// if (double.parse(box.read(BoxName.passengerWalletTotal)) < 0) {
// totalPassenger = totalCostPassenger +
// double.parse(box.read(BoxName.passengerWalletTotal));
// } else {
// totalPassenger = totalCostPassenger + 0;
// }
// await CRUD().post(link: AppLink.addPassengersWallet, payload: {
// 'passenger_id': box.read(BoxName.passengerID).toString(),
// 'balance': ((-1) * totalPassenger).toString()
// });
// }
}
void getBeginRideFromDriver() async {
@@ -699,10 +705,10 @@ class MapPassengerController extends GetxController {
List<String> body = [
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
totalPassenger.toString(),
totalDriver.toString(),
totalPassenger.toStringAsFixed(2),
totalDriver.toStringAsFixed(2),
durationToRide.toString(),
distance.toString(),
distance.toStringAsFixed(2),
dataCarsLocationByPassenger['message'][carsOrder]['driver_id']
.toString(),
box.read(BoxName.passengerID).toString(),
@@ -727,7 +733,7 @@ class MapPassengerController extends GetxController {
placesCoordinate[2],
placesCoordinate[3],
placesCoordinate[4],
cost.toStringAsFixed(2)
costDistance.toStringAsFixed(2)
];
FirebaseMessagesController().sendNotificationToDriverMAP(
'Order',
@@ -781,6 +787,7 @@ class MapPassengerController extends GetxController {
changeConfirmRide();
} else {
Get.defaultDialog(
barrierDismissible: false,
title: 'There no Driver Aplly your order sorry for that '.tr,
middleText: 'try next time .',
confirm: MyElevatedButton(
@@ -956,9 +963,9 @@ class MapPassengerController extends GetxController {
clearPlacesDestination();
clearPolyline();
data = [];
await CRUD().post(link: AppLink.updateDriverOrder, payload: {
"order_id": rideId.toString(), // Convert to String
"status": 'Cancel'
await CRUD().post(link: AppLink.updateRides, payload: {
"id": rideId.toString(), // Convert to String
"status": 'notApplyFromAnyDriver'
});
rideConfirm = false;
shouldFetch = false;
@@ -1780,8 +1787,14 @@ class MapPassengerController extends GetxController {
if (decode["status"] == "success") {
//print(totalPassenger);
var firstElement = decode["message"][0];
totalPassenger = totalPassenger -
(totalPassenger * int.parse(firstElement['amount']) / 100);
if (double.parse(box.read(BoxName.passengerWalletTotal)) < 0) {
totalPassenger = totalCostPassenger -
(totalCostPassenger * int.parse(firstElement['amount']) / 100);
} else {
totalPassenger = totalCostPassenger -
(totalCostPassenger * int.parse(firstElement['amount']) / 100);
}
totalDriver = totalDriver -
(totalDriver * int.parse(firstElement['amount']) / 100);
promoTaken = true;
@@ -1814,34 +1827,51 @@ class MapPassengerController extends GetxController {
averageDuration = (durationToRide / 60) / distance;
costDuration = (durationToRide / 60) * averageDuration * 0.016;
print('costDuration----- $costDuration');
var totalDriver1 = cost + costDuration;
totalPassenger = totalDriver1 + (totalDriver1 * .16);
print('costDistance----- $costDistance');
print(
'passengerWalletTotal----- ${box.read(BoxName.passengerWalletTotal)}');
var totalDriver1 = costDistance + costDuration;
totalCostPassenger = totalDriver1 + (totalDriver1 * .16);
totalDriver = totalDriver1 + (totalDriver1 * .16);
tax = totalPassenger * .16;
totalME = totalPassenger - tax;
tax = totalCostPassenger * .16;
totalME = totalCostPassenger - tax;
if (double.parse(box.read(BoxName.passengerWalletTotal)) < 0) {
totalPassenger = totalCostPassenger +
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
} else {
totalPassenger = totalCostPassenger;
}
update();
if (currentTime.hour >= 22) {
cost = distance * 0.23;
costDistance = distance * 0.23;
update();
} else if (currentTime.hour < 5) {
cost = distance * 0.25;
costDistance = distance * 0.25;
update();
} else if (currentTime.hour >= 13 && currentTime.hour <= 16) {
if (averageDuration > 2.5) {
cost = distance * 0.25;
costDistance = distance * 0.25;
update();
} else {
cost = distance * 0.21;
costDistance = distance * 0.21;
update();
}
} else {
cost = distance * 0.21;
costDistance = distance * 0.21;
update();
}
//print('cost $cost');
if (totalPassenger < 1) {
totalPassenger = 1;
totalDriver = 1;
if (totalCostPassenger < 1) {
totalCostPassenger = 1;
if (double.parse(box.read(BoxName.passengerWalletTotal)) < 0) {
totalPassenger = totalCostPassenger +
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
} else {
totalPassenger = totalCostPassenger;
}
update();
// if (totalDriver < .5) {
// totalDriver = .75;
@@ -1851,8 +1881,8 @@ class MapPassengerController extends GetxController {
// totalDriver = .90;
// totalME = .06;
// update();
// }
}
// }
// buttomSheetMapPage();
changeBottomSheetShown();

View File

@@ -459,6 +459,9 @@ class PaymentController extends GetxController {
@override
void onInit() {
timestamp = now.millisecondsSinceEpoch;
if (box.read(BoxName.passengerWalletTotal) == null) {
box.write(BoxName.passengerWalletTotal, '0');
}
getPassengerWallet();
final localAuth = LocalAuthentication();
super.onInit();

View File

@@ -6,6 +6,7 @@ import 'package:ride/constant/box_name.dart';
import 'package:ride/constant/links.dart';
import 'package:ride/controller/functions/crud.dart';
import 'package:ride/main.dart';
import 'package:ride/views/widgets/my_textField.dart';
import '../../views/widgets/elevated_btn.dart';
@@ -37,24 +38,30 @@ class ProfileController extends GetxController {
update();
}
updatField(String columnName) async {
updatField(String columnName, TextInputType type) async {
Get.defaultDialog(
title: '${'Update'.tr} $columnName',
content: Column(
children: [
SizedBox(
width: Get.width * .7,
child: TextField(
controller: txtController,
decoration: const InputDecoration(
border: OutlineInputBorder(), hintText: 'type here'),
),
),
width: Get.width * .7,
child: MyTextForm(
controller: txtController,
label: 'type here'.tr,
hint: 'type here',
type: type)
// TextField(
// controller: txtController,
// decoration: const InputDecoration(
// border: OutlineInputBorder(), hintText: 'type here'),
// ),
),
MyElevatedButton(
title: 'Update'.tr,
onPressed: () {
updateColumn({
'id': prfoileData['id'].toString(),
'id': box.read(BoxName.passengerID),
columnName: txtController.text,
});
if (columnName == 'first_name') {