This commit is contained in:
Hamza Aleghwairyeen
2024-04-09 02:52:52 +03:00
parent 207a87a5f0
commit d68eb5028f
11 changed files with 249 additions and 164 deletions

View File

@@ -196,6 +196,7 @@ class FirebaseMessagesController extends GetxController {
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
'price': driverList[3].toString()
});
}
} else if (message.notification!.title! == 'Call Income') {
@@ -347,6 +348,7 @@ class FirebaseMessagesController extends GetxController {
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
'price': driverList[3].toString()
});
},
kolor: AppColor.greenColor,
@@ -357,6 +359,7 @@ class FirebaseMessagesController extends GetxController {
Get.to(() => RateDriverFromPassenger(), arguments: {
'driverId': driverList[0].toString(),
'rideId': driverList[1].toString(),
'price': driverList[3].toString()
});
},
kolor: AppColor.redColor,

View File

@@ -1,101 +1,159 @@
import 'dart:io';
// import 'dart:io';
//
// import 'package:flutter/material.dart';
// import 'package:flutter_sound/flutter_sound.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
//
// import '../home/map_passenger_controller.dart';
//
// class AudioController extends GetxController {
// final recorder = FlutterSoundRecorder();
// bool isRecording = false;
//
// @override
// void onInit() {
// super.onInit();
// initRecorder();
// }
//
// Future<void> initRecorder() async {
// final status = await Permission.microphone.request();
// if (status != PermissionStatus.granted) {
// if (status.isPermanentlyDenied) {
// // Handle permission permanently denied
// showPermissionDeniedDialog();
// } else if (status.isDenied) {
// // Handle permission denied
// showPermissionDeniedSnackbar();
// } else if (status.isRestricted) {
// // Handle permission restricted
// showPermissionDeniedSnackbar();
// }
// return;
// }
// await recorder.openRecorder();
// recorder.setSubscriptionDuration(const Duration(minutes: 50));
// }
//
// Future<void> startRecording() async {
// if (!recorder.isStopped) {
// await recorder.startRecorder();
// }
// isRecording = true;
// update();
// }
//
// Future<void> stopRecording() async {
// final filePath = await recorder.stopRecorder();
// final audioFile = File(filePath!);
// print('Recorded file path: $audioFile');
// // Now you can send this file to the server
// isRecording = false;
// update();
// }
//
// @override
// void onClose() {
// recorder.stopRecorder();
// super.onClose();
// }
//
// void showPermissionDeniedDialog() {
// showDialog(
// context: Get.context!,
// builder: (context) => AlertDialog(
// title: const Text('Microphone Permission'),
// content:
// const Text('Microphone permission is required to record audio.'),
// actions: [
// TextButton(
// onPressed: () {
// Navigator.of(context).pop();
// openAppSettings();
// },
// child: const Text('Open Settings'),
// ),
// TextButton(
// onPressed: () {
// Navigator.of(context).pop();
// },
// child: const Text('Cancel'),
// ),
// ],
// ),
// );
// }
//
// void showPermissionDeniedSnackbar() {
// Get.snackbar(
// 'Microphone Permission',
// 'Microphone permission is required to record audio.',
// snackPosition: SnackPosition.BOTTOM,
// duration: const Duration(seconds: 5),
// mainButton: TextButton(
// onPressed: () {
// openAppSettings();
// },
// child: const Text(
// 'Open Settings',
// style: TextStyle(color: Colors.white),
// ),
// ),
// );
// }
// }
import 'package:flutter/material.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:get/get.dart';
import 'package:flutter_sound/flutter_sound.dart';
import 'package:permission_handler/permission_handler.dart';
import '../home/map_passenger_controller.dart';
class AudioController extends GetxController {
final recorder = FlutterSoundRecorder();
final flutterSoundHelper = FlutterSoundHelper();
bool isRecording = false;
@override
void onInit() {
super.onInit();
initRecorder();
}
Future<void> startRecording() async {
if (!await flutterSoundHelper.hasPermissions()) {
await flutterSoundHelper.requestPermissions();
}
Future<void> initRecorder() async {
final status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
if (status.isPermanentlyDenied) {
// Handle permission permanently denied
showPermissionDeniedDialog();
} else {
// Handle permission denied
showPermissionDeniedSnackbar();
}
if (!await flutterSoundHelper.hasPermissions()) {
return;
}
await recorder.openRecorder();
recorder.setSubscriptionDuration(const Duration(minutes: 50));
}
Future<void> startRecording() async {
final controller = Get.find<MapPassengerController>();
final filePath = 'audio_${controller.rideId}.wav'; // Specify the file name
await recorder.startRecorder(toFile: filePath);
await flutterSoundHelper.startRecorder();
isRecording = true;
update();
}
Future<void> stopRecording() async {
final filePath = await recorder.stopRecorder();
final audioFile = File(filePath!);
print('Recorded file path: $audioFile');
// Now you can send this file to the server
if (!isRecording) {
return;
}
await flutterSoundHelper.stopRecorder();
isRecording = false;
update();
}
@override
void onClose() {
recorder.stopRecorder();
super.onClose();
}
void showPermissionDeniedDialog() {
showDialog(
context: Get.context!,
builder: (context) => AlertDialog(
title: Text('Microphone Permission'),
content: Text('Microphone permission is required to record audio.'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
openAppSettings();
},
child: Text('Open Settings'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Cancel'),
),
],
),
);
}
void showPermissionDeniedSnackbar() {
Get.snackbar(
'Microphone Permission',
'Microphone permission is required to record audio.',
snackPosition: SnackPosition.BOTTOM,
duration: Duration(seconds: 5),
mainButton: TextButton(
onPressed: () {
openAppSettings();
},
child: Text(
'Open Settings',
style: TextStyle(color: Colors.white),
),
),
);
}
}
class FlutterSoundHelper {
final flutterSound = FlutterSoundRecorder();
Future<bool> hasPermissions() async {
return await Permission.microphone.isGranted;
}
Future<void> requestPermissions() async {
await Permission.microphone.request();
}
Future<void> startRecorder() async {
await flutterSound.openRecorder();
await flutterSound.startRecorder(toFile: 'audio.wav');
}
Future<void> stopRecorder() async {
await flutterSound.stopRecorder();
await flutterSound.closeRecorder();
}
}

View File

@@ -425,9 +425,11 @@ class MapDriverController extends GetxController {
isRideFinished = true;
isRideStarted = false;
isPriceWindow = false;
totalCost = carType == 'Comfort' || carType == 'Mashwari'
? price.toStringAsFixed(1)
: totalPassenger;
totalCost = carType != 'Comfort' || carType != 'Mashwari'
? totalPassenger
: price < double.parse(totalPassenger)
? totalPassenger
: price.toStringAsFixed(1);
paymentAmount = totalCost;
box.write(BoxName.statusDriverLocation, 'off');
// changeRideToBeginToPassenger();
@@ -466,7 +468,7 @@ class MapDriverController extends GetxController {
100; // for eygpt /100
var res = await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
'paymentID': 'rideId$rideId',
'amount': (pointsSubstraction).toString(),
'amount': (pointsSubstraction).toStringAsFixed(0),
'paymentMethod': paymentMethod,
'driverID': box.read(BoxName.driverID).toString(),
});
@@ -474,68 +476,18 @@ class MapDriverController extends GetxController {
Future.delayed(const Duration(milliseconds: 300));
FirebaseMessagesController().sendNotificationToPassengerToken(
'Driver Finish Trip',
'you will pay to Driver'.tr +
' ${carType == 'Comfort' || carType == 'Mashwari' ? price.toStringAsFixed(2) : totalPassenger} \$'
.tr,
'${'you will pay to Driver'.tr} $paymentAmount \$',
tokenPassenger,
[
box.read(BoxName.driverID),
rideId,
box.read(BoxName.tokenDriver),
carType == 'Comfort' || carType == 'Mashwari'
? price.toStringAsFixed(2)
: totalPassenger
// carType == 'Comfort' || carType == 'Mashwari'
// ? price.toStringAsFixed(2)
// : totalPassenger
paymentAmount.toString()
],
);
// } else {
// Get.defaultDialog(
// title: 'You don\'t arrive destenation yet .'.tr,
// middleText: '',
// confirm: MyElevatedButton(
// title: 'Ok'.tr,
// onPressed: () {
// Get.back();
// }));
// }
// } else {
// totalCost = price.toStringAsFixed(2);
// paymentAmount = totalCost;
// box.write(BoxName.statusDriverLocation, 'off');
// // changeRideToBeginToPassenger();
// await CRUD().post(link: AppLink.updateRides, payload: {
// 'id': rideId,
// 'rideTimeFinish': DateTime.now().toString(),
// 'status': 'Finished'
// });
// print('walletChecked is $walletChecked');
// if (walletChecked == 'true') {
// await CRUD().post(link: AppLink.addPassengersWallet, payload: {
// 'passenger_id': passengerId,
// 'balance': ((-1) * double.parse(paymentAmount)).toString()
// });
// }
// print('passengerWalletBurc bef ${double.parse(passengerWalletBurc)}');
// if (double.parse(passengerWalletBurc) < 0) {
// await CRUD().post(link: AppLink.addPassengersWallet, payload: {
// 'passenger_id': passengerId,
// 'balance': ((-1) * double.parse(passengerWalletBurc)).toString()
// });
// print('passengerWalletBurc aft ${double.parse(passengerWalletBurc)}');
// }
// 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),
// ],
// );
// }
// add wallet from passenger from driver
Get.to(() => RatePassenger(), arguments: {
'passengerId': passengerId,
'rideId': rideId,

View File

@@ -477,7 +477,9 @@ class MyTranslation extends Translations {
'Trip has Steps': "الرحلة تتكون من خطوات",
'Distance from Passenger to destination is ':
"المسافة من الراكب إلى الوجهة هي ",
'Cost Of Trip IS ': "تكلفة الرحلة هي ",
'price is': '‏التكلفة',
'distance is'
'Cost Of Trip IS ': "تكلفة الرحلة هي ",
"We noticed the speed is exceeding 100 km/h. Please slow down for your safety. If you feel unsafe, you can share your trip details with a contact or call the police using the red SOS button.":
"لقد لاحظنا أن السرعة تتجاوز ١٠٠ كم/ساعة. يرجى التباطؤ من أجل سلامتك. إذا كنت تشعر بعدم الأمان، يمكنك مشاركة تفاصيل رحلتك مع جهة اتصال أو الاتصال بالشرطة باستخدام زر SOS الأحمر.",
'Warning: Speeding detected!': "تحذير: تم رصد السرعة الزائدة!",

View File

@@ -17,7 +17,7 @@ import 'package:SEFER/views/widgets/elevated_btn.dart';
class RateController extends GetxController {
double selectedRateItemId = -1;
TextEditingController comment = TextEditingController();
String? rideId, passengerId, driverId;
String? rideId, passengerId, driverId, price;
late GlobalKey<FormState> formKey;
@override
void onInit() {
@@ -25,6 +25,7 @@ class RateController extends GetxController {
passengerId = Get.arguments['passengerId'];
rideId = Get.arguments['rideId'];
driverId = Get.arguments['driverId'];
price = Get.arguments['price'];
super.onInit();
}