This commit is contained in:
Hamza-Ayed
2024-09-04 14:49:36 +03:00
parent 04c47d3431
commit e23709c924
19 changed files with 568 additions and 266 deletions

View File

@@ -96,6 +96,22 @@ class RegisterController extends GetxController {
return validPrefixes.hasMatch(phoneNumber);
}
bool isValidPhoneNumber(String phoneNumber) {
// Remove any whitespace from the phone number
phoneNumber = phoneNumber.replaceAll(RegExp(r'\s+'), '');
// Check if the phone number has at least 10 digits
if (phoneNumber.length < 10) {
return false;
}
// Check for valid prefixes (modify this to match your use case)
RegExp validPrefixes = RegExp(r'^[0-9]+$');
// Check if the phone number contains only digits
return validPrefixes.hasMatch(phoneNumber);
}
sendOtpMessage() async {
SmsEgyptController smsEgyptController = Get.put(SmsEgyptController());
@@ -104,7 +120,7 @@ class RegisterController extends GetxController {
update();
if (formKey3.currentState!.validate()) {
if (box.read(BoxName.countryCode) == 'Egypt') {
if (isValidEgyptianPhoneNumber(phoneController.text)) {
if (isValidEgyptianPhoneNumber(phoneController.text) == true) {
var responseCheker = await CRUD()
.post(link: AppLink.checkPhoneNumberISVerfiedPassenger, payload: {
'phone_number': '+2${phoneController.text}',
@@ -148,16 +164,32 @@ class RegisterController extends GetxController {
// Get.snackbar(responseCheker, 'message');
}
} else if (isValidPhoneNumber(phoneController.text)) {
await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
'phone_number': '+${phoneController.text}',
'token': randomNumber.toString(),
});
await smsEgyptController.sendWhatsAppAuth(
phoneController.text, randomNumber.toString());
// await smsEgyptController.sendSmsEgypt(
// phoneController.text.toString(), randomNumber.toString());
isSent = true;
remainingTime = 300; // Reset to 5 minutes
startTimer();
isLoading = false;
update();
} else {
Get.snackbar('Phone Number wrong'.tr, '',
backgroundColor: AppColor.redColor);
backgroundColor: AppColor.redColor,
duration: const Duration(seconds: 5));
}
}
}
}
verifySMSCode() async {
if (formKey3.currentState!.validate()) {
// if (formKey3.currentState!.validate()) {
if (isValidEgyptianPhoneNumber(phoneController.text)) {
var res = await CRUD().post(link: AppLink.verifyOtpMessage, payload: {
'phone_number': '+2${phoneController.text}',
'token': verifyCode.text.toString(),
@@ -199,6 +231,48 @@ class RegisterController extends GetxController {
'Error'.tr, "The email or phone number is already registered.".tr,
backgroundColor: Colors.redAccent);
}
} else {
var res = await CRUD().post(link: AppLink.verifyOtpMessage, payload: {
'phone_number': '+${phoneController.text}',
'token': verifyCode.text.toString(),
});
if (res != 'failure') {
// var dec = jsonDecode(res);
box.write(BoxName.phoneDriver, '+${phoneController.text}');
var payload = {
'id': box.read(BoxName.passengerID),
'phone': '+${phoneController.text}',
'email': box.read(BoxName.email),
'password': 'unknown',
'gender': 'unknown',
'birthdate': '2002-01-01',
'site': 'unknown',
'first_name': box.read(BoxName.name).toString().split(' ')[0],
'last_name': box.read(BoxName.name).toString().split(' ')[1],
};
var res1 = await CRUD().post(
link: AppLink.signUp,
payload: payload,
);
if (res1 != 'failure') {
CRUD().post(
link: '${AppLink.seferAlexandriaServer}/auth/signup.php',
payload: payload,
);
CRUD().post(
link: '${AppLink.seferGizaServer}/auth/signup.php',
payload: payload,
);
box.write(BoxName.isVerified, '1');
box.write(BoxName.phone, '+${phoneController.text}');
Get.offAll(const MapPagePassenger());
}
} else {
Get.snackbar(
'Error'.tr, "The email or phone number is already registered.".tr,
backgroundColor: Colors.redAccent);
}
}
}

View File

@@ -1,6 +1,5 @@
import 'dart:io';
import 'package:SEFER/controller/home/map_passenger_controller.dart';
// import 'package:flutter_sound/flutter_sound.dart';
import 'package:path_provider/path_provider.dart';
@@ -13,12 +12,23 @@ class AudioRecorderController extends GetxController {
AudioRecorder recorder = AudioRecorder();
bool isRecording = false;
bool isPlaying = false;
bool isPaused = false;
String filePath = '';
String? selectedFilePath;
double currentPosition = 0;
double totalDuration = 0;
String? selectedFile;
Future<void> playSoundFromAssets(String sound) async {
try {
await audioPlayer.setAsset(sound);
audioPlayer.play();
} catch (e) {
print("Error playing sound: $e");
}
}
// Start recording
Future<void> startRecording() async {
final bool isPermissionGranted = await recorder.hasPermission();
if (!isPermissionGranted) {
@@ -48,26 +58,76 @@ class AudioRecorderController extends GetxController {
update();
}
Future<void> stopRecording() async {
final path = await recorder.stop();
isRecording = false;
update();
}
Future<void> playRecording() async {
if (filePath != null) {
await audioPlayer.setFilePath(filePath!);
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
audioPlayer.play();
audioPlayer.positionStream.listen((position) {
currentPosition = position.inSeconds.toDouble();
});
selectedFilePath = filePath;
// Pause recording
Future<void> pauseRecording() async {
if (isRecording && !isPaused) {
await recorder.pause();
isPaused = true;
update();
}
}
// Resume recording
Future<void> resumeRecording() async {
if (isRecording && isPaused) {
await recorder.resume();
isPaused = false;
update();
}
}
// Stop recording
Future<void> stopRecording() async {
await recorder.stop();
isRecording = false;
isPaused = false;
update();
}
// Play the selected recorded file
Future<void> playRecordedFile(String filePath) async {
await audioPlayer.setFilePath(filePath);
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
audioPlayer.play();
isPlaying = true;
isPaused = false;
audioPlayer.positionStream.listen((position) {
currentPosition = position.inSeconds.toDouble();
update();
});
selectedFilePath = filePath;
update();
}
// Pause playback
Future<void> pausePlayback() async {
if (isPlaying && !isPaused) {
await audioPlayer.pause();
isPaused = true;
update();
}
}
// Resume playback
Future<void> resumePlayback() async {
if (isPlaying && isPaused) {
await audioPlayer.play();
isPaused = false;
update();
}
}
// Stop playback
Future<void> stopPlayback() async {
await audioPlayer.stop();
isPlaying = false;
isPaused = false;
currentPosition = 0;
update();
}
// Get a list of recorded files
Future<List<String>> getRecordedFiles() async {
final directory = await getApplicationDocumentsDirectory();
final files = await directory.list().toList();
@@ -77,25 +137,16 @@ class AudioRecorderController extends GetxController {
.toList();
}
Future<void> playRecordedFile(String filePath) async {
await audioPlayer.setFilePath(filePath);
totalDuration = audioPlayer.duration?.inSeconds.toDouble() ?? 0;
audioPlayer.play();
audioPlayer.positionStream.listen((position) {
currentPosition = position.inSeconds.toDouble();
});
update();
}
// Delete a specific recorded file
Future<void> deleteRecordedFile(String filePath) async {
final file = File(filePath);
if (await file.exists()) {
await file.delete();
await getRecordedFiles();
} else {}
update();
}
}
// Delete all recorded files
Future<void> deleteAllRecordedFiles() async {
final directory = await getApplicationDocumentsDirectory();
final files = await directory.list().toList();

View File

@@ -5,6 +5,7 @@ import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/constant/info.dart';
import 'package:SEFER/constant/links.dart';
import 'package:SEFER/controller/auth/login_controller.dart';
import 'package:SEFER/env/env.dart';
import 'package:SEFER/main.dart';
import 'package:SEFER/views/widgets/elevated_btn.dart';
import 'package:get/get.dart';
@@ -58,7 +59,7 @@ class SmsEgyptController extends GetxController {
);
} else {
Get.defaultDialog(
title: 'You will receive code in sms message'.tr,
title: 'You will receive a code in SMS message'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'OK'.tr,
@@ -107,4 +108,52 @@ class SmsEgyptController extends GetxController {
headers: headers,
);
}
Future sendWhatsAppAuth(String to, String token) async {
var headers = {
'Authorization': 'Bearer ${Env.whatsapp}',
'Content-Type': 'application/json'
};
var request = http.Request(
'POST',
Uri.parse(
'https://graph.facebook.com/v20.0/${Env.whatappID}/messages'));
request.body = json.encode({
"messaging_product": "whatsapp",
"to": to, //"962798583052",
"type": "template",
"template": {
"name": "sefer1",
"language": {"code": "en"},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": token,
}
]
}
]
}
});
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
Get.defaultDialog(
title: 'You will receive a code in WhatsApp Messenger'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'OK'.tr,
onPressed: () {
Get.back();
}));
} else {
print(response.reasonPhrase);
}
}
}

View File

@@ -231,6 +231,7 @@ class MapPassengerController extends GetxController {
late double totalPassengerComfortDiscount = 0;
late double totalPassengerLadyDiscount = 0;
late double totalPassengerSpeedDiscount = 0;
late double totalPassengerBalashDiscount = 0;
late double totalPassengerRaihGaiDiscount = 0;
late double totalPassengerMotoDelivery = 0;
late double totalDriver = 0;
@@ -1132,50 +1133,50 @@ class MapPassengerController extends GetxController {
Log.print(
'body: ${dataCarsLocationByPassenger['message'][carsOrder]['token']}');
});
// CRUD().post(
// link: '${AppLink.seferAlexandriaServer}/ride/rides/add.php',
// payload: {
// "start_location": //'${data[0]['start_address']}',
// '${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
// "end_location": //'${data[0]['end_address']}',
// '${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
// "date": DateTime.now().toString(),
// "time": DateTime.now().toString(),
// "endtime": durationToAdd.toString(),
// "price": totalPassenger.toStringAsFixed(2),
// "passenger_id": box.read(BoxName.passengerID).toString(),
// "driver_id": dataCarsLocationByPassenger['message'][carsOrder]
// ['driver_id']
// .toString(),
// "status": "waiting",
// 'carType': box.read(BoxName.carType),
// "price_for_driver": totalPassenger.toString(),
// "price_for_passenger": totalME.toString(),
// "distance": distance.toString(),
// "paymentMethod": paymentController.isWalletChecked.toString(),
// });
// CRUD().post(
// link: '${AppLink.seferGizaServer}/ride/rides/add.php',
// payload: {
// "start_location": //'${data[0]['start_address']}',
// '${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
// "end_location": //'${data[0]['end_address']}',
// '${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
// "date": DateTime.now().toString(),
// "time": DateTime.now().toString(),
// "endtime": durationToAdd.toString(),
// "price": totalPassenger.toStringAsFixed(2),
// "passenger_id": box.read(BoxName.passengerID).toString(),
// "driver_id": dataCarsLocationByPassenger['message'][carsOrder]
// ['driver_id']
// .toString(),
// "status": "waiting",
// 'carType': box.read(BoxName.carType),
// "price_for_driver": totalPassenger.toString(),
// "price_for_passenger": totalME.toString(),
// "distance": distance.toString(),
// "paymentMethod": paymentController.isWalletChecked.toString(),
// });
CRUD().post(
link: '${AppLink.seferAlexandriaServer}/ride/rides/add.php',
payload: {
"start_location": //'${data[0]['start_address']}',
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
"end_location": //'${data[0]['end_address']}',
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
"date": DateTime.now().toString(),
"time": DateTime.now().toString(),
"endtime": durationToAdd.toString(),
"price": totalPassenger.toStringAsFixed(2),
"passenger_id": box.read(BoxName.passengerID).toString(),
"driver_id": dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
.toString(),
"status": "waiting",
'carType': box.read(BoxName.carType),
"price_for_driver": totalPassenger.toString(),
"price_for_passenger": totalME.toString(),
"distance": distance.toString(),
"paymentMethod": paymentController.isWalletChecked.toString(),
});
CRUD().post(
link: '${AppLink.seferGizaServer}/ride/rides/add.php',
payload: {
"start_location": //'${data[0]['start_address']}',
'${data[0]["start_location"]['lat']},${data[0]["start_location"]['lng']}',
"end_location": //'${data[0]['end_address']}',
'${data[0]["end_location"]['lat']},${data[0]["end_location"]['lng']}',
"date": DateTime.now().toString(),
"time": DateTime.now().toString(),
"endtime": durationToAdd.toString(),
"price": totalPassenger.toStringAsFixed(2),
"passenger_id": box.read(BoxName.passengerID).toString(),
"driver_id": dataCarsLocationByPassenger['message'][carsOrder]
['driver_id']
.toString(),
"status": "waiting",
'carType': box.read(BoxName.carType),
"price_for_driver": totalPassenger.toString(),
"price_for_passenger": totalME.toString(),
"distance": distance.toString(),
"paymentMethod": paymentController.isWalletChecked.toString(),
});
delayAndFetchRideStatus(rideId);
if (shouldFetch == false) {
@@ -1292,6 +1293,9 @@ class MapPassengerController extends GetxController {
showAndResearchForCaptain();
// delayAndFetchRideStatusForAllDriverAvailable(rideId);
} else if (res.toString() == 'Apply') {
// todo play sound
Get.find<AudioRecorderController>()
.playSoundFromAssets('assets/start.wav');
timer.cancel(); // Stop the current timer
shouldFetch = false; // Stop further fetches
statusRide = 'Apply';
@@ -1326,6 +1330,7 @@ class MapPassengerController extends GetxController {
"No Captain Accepted Your Order".tr,
"We are looking for a captain but the price may increase to let a captain accept"
.tr,
duration: const Duration(seconds: 5),
backgroundColor: AppColor.yellowColor,
);
}
@@ -1338,7 +1343,7 @@ class MapPassengerController extends GetxController {
Log.print('tick delayAndFetchRideStatusForAllDriverAvailable: ${tick}');
void fetchRideStatus() async {
if (attemptCounter < maxAttempts && !isApplied) {
if (attemptCounter < maxAttempts && !isApplied && tick < 20) {
attemptCounter++;
tick++;
var res = await getRideStatus(rideId);
@@ -1673,6 +1678,9 @@ class MapPassengerController extends GetxController {
timer.cancel();
} else {
attempt++;
if (reloadCount >= 3 || tick > 18 || reloadCount > 15) {
timer.cancel();
}
Log.print(
'Incrementing attempt to: ${attempt}'); // Log incremented attempt
@@ -1761,6 +1769,15 @@ class MapPassengerController extends GetxController {
'northeastLon': bounds.northeast.longitude.toString(),
});
break;
case 'Balash':
res = await CRUD()
.get(link: AppLink.getCarsLocationByPassengerBalash, payload: {
'southwestLat': bounds.southwest.latitude.toString(),
'southwestLon': bounds.southwest.longitude.toString(),
'northeastLat': bounds.northeast.latitude.toString(),
'northeastLon': bounds.northeast.longitude.toString(),
});
break;
default:
res = await CRUD()
.get(link: AppLink.getCarsLocationByPassenger, payload: {
@@ -2667,10 +2684,10 @@ class MapPassengerController extends GetxController {
// });
// }
bool reloadStartApp = false;
int reloadCount = 0;
startMarkerReloading() async {
Log.print('AppLink.endPoint: ${AppLink.endPoint}');
int reloadCount = 0;
if (reloadStartApp == false) {
Timer.periodic(const Duration(seconds: 5), (timer) async {
reloadCount++;
@@ -3249,6 +3266,7 @@ class MapPassengerController extends GetxController {
double costForDriver = 0;
double totalPassengerSpeed = 0;
double totalPassengerBalash = 0;
double totalPassengerLady = 0;
double totalPassengerRayehGai = 0;
Future bottomSheet() async {
@@ -3262,12 +3280,18 @@ class MapPassengerController extends GetxController {
// costDuration = (durationToRide / 60) * averageDuration * 0.016;
costDuration = (durationToRide / 60).floorToDouble();
'passengerWalletTotal----- ${box.read(BoxName.passengerWalletTotal)}';
double costComfort, costSpeed, costDelivery, costLady, costRayehGai = 0;
double costComfort,
costSpeed,
costDelivery,
costBalash,
costLady,
costRayehGai = 0;
update();
if (currentTime.hour >= 22 && currentTime.hour < 5) {
// costDistance = distance * latePrice;
costComfort = (distance * comfortPrice) + costDuration * latePrice;
costSpeed = (distance * speedPrice) + costDuration * latePrice;
costBalash = (distance * (speedPrice - 1)) + costDuration * latePrice;
costDelivery = (distance * deliveryPrice) + costDuration * latePrice;
costLady = (distance * comfortPrice + 2) + costDuration * latePrice;
costRayehGai = (distance * 2 * speedPrice) -
@@ -3280,6 +3304,7 @@ class MapPassengerController extends GetxController {
// costDistance = distance * heavyPrice;
costComfort = (distance * comfortPrice) + costDuration * heavyPrice;
costSpeed = (distance * speedPrice) + costDuration * heavyPrice;
costBalash = (distance * (speedPrice - 1)) + costDuration * heavyPrice;
costDelivery = (distance * deliveryPrice) + costDuration * heavyPrice;
costLady = (distance * comfortPrice + 2) + costDuration * heavyPrice;
costRayehGai = (distance * 2 * speedPrice) -
@@ -3292,6 +3317,7 @@ class MapPassengerController extends GetxController {
// costDistance = distance * (naturePrice - .1);
costComfort = (distance * comfortPrice) + costDuration;
costSpeed = (distance * speedPrice) + costDuration;
costBalash = (distance * (speedPrice - 1)) + costDuration;
costDelivery = (distance * deliveryPrice) + costDuration;
costLady = (distance * comfortPrice + 2) + costDuration;
costRayehGai = (distance * 2 * speedPrice) -
@@ -3308,6 +3334,8 @@ class MapPassengerController extends GetxController {
totalPassengerLady = (costLady + (costLady * kazan / 100)).ceilToDouble();
totalPassengerSpeed =
(costSpeed + (costSpeed * kazan / 100)).ceilToDouble();
totalPassengerBalash =
(costBalash + (costBalash * kazan / 100)).ceilToDouble();
totalPassengerRayehGai =
(costRayehGai + (costRayehGai * kazan / 100)).ceilToDouble();
totalPassengerComfortDiscount =
@@ -3315,15 +3343,19 @@ class MapPassengerController extends GetxController {
totalPassengerLadyDiscount =
totalPassengerLady + totalPassengerLady * (kazan - 0) / 100;
totalPassengerSpeedDiscount =
totalPassengerSpeed + totalPassengerSpeed * (kazan - 2) / 100;
totalPassengerSpeed + totalPassengerSpeed * (kazan) / 100;
totalPassengerBalashDiscount =
totalPassengerBalash + totalPassengerBalash * (kazan) / 100;
totalPassengerRaihGaiDiscount =
totalPassengerRayehGai + totalPassengerRayehGai * (kazan - 2) / 100;
totalPassengerRayehGai + totalPassengerRayehGai * (kazan) / 100;
totalPassengerMotoDelivery =
(costDelivery + (costDelivery * kazan / 100)).ceilToDouble();
totalPassengerComfort = totalPassengerComfortDiscount -
(totalPassengerComfortDiscount * kazan / 100);
totalPassengerSpeed = totalPassengerSpeedDiscount -
(totalPassengerSpeedDiscount * kazan / 100);
totalPassengerBalash = totalPassengerBalashDiscount -
(totalPassengerBalashDiscount * kazan / 100);
totalPassengerLady = totalPassengerLadyDiscount -
(totalPassengerLadyDiscount * kazan / 100);
totalDriver = totalDriver1 + (totalDriver1 * kazan / 100);
@@ -3334,6 +3366,7 @@ class MapPassengerController extends GetxController {
// for eygpt 20 le open ride
totalCostPassenger = 20;
totalPassengerSpeed = 20;
totalPassengerBalash = 20;
totalPassengerComfort = 30;
totalPassengerLady = 30;
totalPassengerMotoDelivery = 18;
@@ -3348,6 +3381,8 @@ class MapPassengerController extends GetxController {
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
totalPassengerLady = totalPassengerLady +
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
totalPassengerBalash = totalPassengerBalash +
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
totalPassengerMotoDelivery = totalPassengerMotoDelivery +
(-1) * (double.parse(box.read(BoxName.passengerWalletTotal)));
update();

View File

@@ -590,6 +590,11 @@ iOS [https://getapp.cc/app/6458734951]
" I am currently located at ": "أَنَا حَالِيًّا فِي",
"Please go to Car now ":
'الرَّجَاء التَّحَرُّك إِلَى السَّيَّارَة الآن',
'You will receive a code in WhatsApp Messenger':
"سوف تتلقى رمزًا في واتساب ماسنجر",
'Balash': 'أوفر كار',
"Old and affordable, perfect for budget rides.":
"سيارة ميسورة التكلفة، مثالية للرحلات الاقتصادية.",
" If you need to reach me, please contact the driver directly at":
"إِذَا كُنْت تَحْتَاج إِلَى التَّوَاصُل مَعِي، يُرْجَى التَّوَاصُل مَع السَّائِق مُبَاشَرَةً عَلَى",
"No Car or Driver Found in your area.":
@@ -920,6 +925,8 @@ iOS [https://getapp.cc/app/6458734951]
"Point": "نقطة",
"Driver Wallet": "محفظة السائق",
"Total Points is": "إجمالي النقاط هو",
"You will receive a code in SMS message":
"سوف تتلقى رمزًا في رسالة SMS",
"Total Budget from trips is ": "إجمالي الميزانية من الرحلات هو ",
"Total Amount:": "المبلغ الإجمالي:",
"Total Budget from trips by\nCredit card is ":