25-7-28-2
This commit is contained in:
94
lib/controller/rate/rate_app_controller.dart
Executable file
94
lib/controller/rate/rate_app_controller.dart
Executable file
@@ -0,0 +1,94 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:sefer_driver/constant/box_name.dart';
|
||||
import 'package:sefer_driver/constant/colors.dart';
|
||||
import 'package:sefer_driver/constant/links.dart';
|
||||
import 'package:sefer_driver/controller/functions/crud.dart';
|
||||
import 'package:sefer_driver/controller/functions/encrypt_decrypt.dart';
|
||||
import 'package:sefer_driver/main.dart';
|
||||
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
|
||||
import 'package:sefer_driver/views/widgets/mydialoug.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
// Import url_launcher to open the app store
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class RatingController extends GetxController {
|
||||
var userRating = 0.obs;
|
||||
final comment = TextEditingController();
|
||||
void submitRating(int rating) {
|
||||
userRating.value = rating;
|
||||
|
||||
_saveRating(rating);
|
||||
}
|
||||
|
||||
void _redirectToAppStore() async {
|
||||
// URLs for App Store and Google Play Store
|
||||
const appStoreUrl = 'https://apps.apple.com/app/6502189302';
|
||||
const playStoreUrl =
|
||||
'https://play.google.com/store/apps/details?id=com.sefer_driver';
|
||||
final url = GetPlatform.isIOS ? appStoreUrl : playStoreUrl;
|
||||
|
||||
if (await launchUrl(Uri.parse(url))) {
|
||||
await launchUrl(Uri.parse(url));
|
||||
} else {
|
||||
mySnackeBarError("Could not open the app store.");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveRating(int rating) async {
|
||||
// Build the payload with user data
|
||||
final payload = {
|
||||
"name": box.read(BoxName.driverID) != null
|
||||
? box.read(BoxName.nameDriver)
|
||||
: box.read(BoxName.name),
|
||||
"email": (box.read(BoxName.emailDriver)).toString(),
|
||||
"phone": (box.read(BoxName.phoneDriver)).toString(),
|
||||
"userId": box.read(BoxName.driverID),
|
||||
"userType": "driver",
|
||||
"rating": rating.toString(),
|
||||
"comment": comment.text.isEmpty
|
||||
? 'nothing'
|
||||
: comment.text, // Get actual text from comment controller
|
||||
};
|
||||
|
||||
// Send the rating data to the backend
|
||||
var res = await CRUD().post(link: AppLink.addRateApp, payload: payload);
|
||||
|
||||
// Handle the response and check if it's JSON-formatted
|
||||
if (res != 'failure') {
|
||||
try {
|
||||
// Attempt to parse the response as JSON
|
||||
final parsedResponse = jsonDecode(res);
|
||||
|
||||
if (parsedResponse['status'] == 'success') {
|
||||
// Display a success message
|
||||
CRUD().post(link: AppLink.sendEmailRateingApp, payload: {
|
||||
"name": payload["name"],
|
||||
"email": payload["email"],
|
||||
"rating": rating.toString(),
|
||||
"comment": payload["comment"],
|
||||
});
|
||||
MyDialog().getDialog('Rating submitted successfully'.tr, '', () {
|
||||
if (rating == 5) {
|
||||
Get.back();
|
||||
_redirectToAppStore();
|
||||
} else {
|
||||
Get.back();
|
||||
}
|
||||
});
|
||||
|
||||
// Send confirmation email if the rating was successfully submitted
|
||||
} else {
|
||||
mySnackeBarError('Failed to submit rating');
|
||||
}
|
||||
} catch (e) {
|
||||
// If JSON decoding fails, log the response directly
|
||||
// Get.snackbar('Success', 'Rating submitted successfully',
|
||||
// backgroundColor: AppColor.greenColor);
|
||||
}
|
||||
} else {
|
||||
mySnackeBarError('Failed to connect to the server');
|
||||
}
|
||||
}
|
||||
}
|
||||
152
lib/controller/rate/rate_conroller.dart
Executable file
152
lib/controller/rate/rate_conroller.dart
Executable file
@@ -0,0 +1,152 @@
|
||||
import 'package:sefer_driver/controller/firebase/firbase_messge.dart';
|
||||
import 'package:sefer_driver/controller/home/captin/map_driver_controller.dart';
|
||||
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_driver/constant/box_name.dart';
|
||||
import 'package:sefer_driver/constant/links.dart';
|
||||
import 'package:sefer_driver/constant/style.dart';
|
||||
import 'package:sefer_driver/controller/functions/crud.dart';
|
||||
import 'package:sefer_driver/main.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/home_captain/home_captin.dart';
|
||||
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
|
||||
|
||||
// import '../home/captin/home_captain_controller.dart';
|
||||
|
||||
class RateController extends GetxController {
|
||||
double selectedRateItemId = -1;
|
||||
TextEditingController comment = TextEditingController();
|
||||
TextEditingController passengerPayAmount = TextEditingController();
|
||||
String? rideId, passengerId, driverId, price;
|
||||
late GlobalKey<FormState> formKey;
|
||||
bool ispassengerWantWalletFromDriver = false;
|
||||
String walletChecked = '';
|
||||
@override
|
||||
void onInit() {
|
||||
formKey = GlobalKey<FormState>();
|
||||
passengerId = Get.arguments['passengerId'];
|
||||
rideId = Get.arguments['rideId'];
|
||||
driverId = Get.arguments['driverId'];
|
||||
price = Get.arguments['price'];
|
||||
walletChecked = Get.arguments['walletChecked'];
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void passengerWantPay() {
|
||||
ispassengerWantWalletFromDriver = true;
|
||||
update();
|
||||
}
|
||||
|
||||
Future addPassengerWallet() async {
|
||||
if (formKey.currentState!.validate()) {
|
||||
var priceOfTrip = double.parse(price.toString());
|
||||
// double.parse(Get.find<MapDriverController>().paymentAmount);
|
||||
double remainingFee = double.parse(passengerPayAmount.text) - priceOfTrip;
|
||||
if (remainingFee > 0) {
|
||||
var paymentToken2 = await Get.find<MapDriverController>()
|
||||
.generateTokenPassenger(remainingFee.toString());
|
||||
await CRUD().post(link: AppLink.addPassengersWallet, payload: {
|
||||
'passenger_id': passengerId,
|
||||
'balance': remainingFee.toString(),
|
||||
'token': paymentToken2,
|
||||
}).then((value) async {
|
||||
if (value != 'failure') {
|
||||
mySnackbarSuccess('Wallet Added'.tr);
|
||||
// if (double.parse(
|
||||
// Get.find<CaptainWalletController>().totalAmountVisa) >
|
||||
// remainingFee) {
|
||||
var paymentToken3 = await Get.find<MapDriverController>()
|
||||
.generateTokenDriver((-1 * remainingFee).toString());
|
||||
|
||||
await CRUD().post(link: AppLink.addDrivePayment, payload: {
|
||||
'rideId': 'remain$rideId',
|
||||
'amount': (-1 * remainingFee).toString(),
|
||||
'payment_method': 'Remainder',
|
||||
'passengerID': passengerId,
|
||||
'token': paymentToken3,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
});
|
||||
|
||||
Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
|
||||
'Wallet Added'.tr,
|
||||
'Wallet Added${(remainingFee).toStringAsFixed(0)}'.tr,
|
||||
Get.find<MapDriverController>().tokenPassenger,
|
||||
[],
|
||||
'tone2.wav');
|
||||
walletChecked = 'true';
|
||||
// }
|
||||
|
||||
update();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: '${'The price must be over than '.tr} $priceOfTrip',
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void selectRateItem(double id) {
|
||||
selectedRateItemId = id;
|
||||
update();
|
||||
}
|
||||
|
||||
void addRateToPassenger() async {
|
||||
// HomeCaptainController homeCaptainController =
|
||||
// Get.find<HomeCaptainController>();
|
||||
// Get.put(MapDriverController());
|
||||
if (selectedRateItemId < 1) {
|
||||
Get.defaultDialog(
|
||||
title: 'You Should choose rate figure'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
middleText: '',
|
||||
confirm: MyElevatedButton(title: 'Ok', onPressed: () => Get.back()));
|
||||
} else {
|
||||
await CRUD().post(
|
||||
link: "${AppLink.seferCairoServer}/ride/rate/add.php",
|
||||
payload: {
|
||||
'passenger_id': passengerId,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
'rideId': rideId.toString(),
|
||||
'rating': selectedRateItemId.toString(),
|
||||
'comment': comment.text ?? 'none',
|
||||
});
|
||||
if (AppLink.endPoint != AppLink.seferCairoServer) {
|
||||
CRUD().post(link: "${AppLink.endPoint}/ride/rate/add.php", payload: {
|
||||
'passenger_id': passengerId,
|
||||
'driverID': box.read(BoxName.driverID).toString(),
|
||||
'rideId': rideId.toString(),
|
||||
'rating': selectedRateItemId.toString(),
|
||||
'comment': comment.text ?? 'none',
|
||||
});
|
||||
}
|
||||
|
||||
CRUD().sendEmail(AppLink.sendEmailToPassengerForTripDetails, {
|
||||
'startLocation':
|
||||
Get.find<MapDriverController>().passengerLocation.toString(),
|
||||
'endLocation':
|
||||
Get.find<MapDriverController>().passengerDestination.toString(),
|
||||
'name': Get.find<MapDriverController>().passengerName.toString(),
|
||||
'timeOfTrip': Get.find<MapDriverController>().timeOfOrder.toString(),
|
||||
'fee': Get.find<MapDriverController>().totalPricePassenger.toString(),
|
||||
'duration': Get.find<MapDriverController>().duration.toString(),
|
||||
'phone': Get.find<MapDriverController>().passengerPhone.toString(),
|
||||
'email': Get.find<MapDriverController>().passengerEmail.toString(),
|
||||
'startNameLocation':
|
||||
Get.find<MapDriverController>().startNameLocation.toString(),
|
||||
'endNameLocation':
|
||||
Get.find<MapDriverController>().endNameLocation.toString(),
|
||||
});
|
||||
// homeCaptainController.isActive = true;
|
||||
// update();
|
||||
// homeCaptainController.getPaymentToday();
|
||||
Get.offAll(HomeCaptain());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user