25-7-28-2

This commit is contained in:
Hamza-Ayed
2025-07-28 12:21:28 +03:00
parent 660d60e1f5
commit 83a97baed1
549 changed files with 109870 additions and 0 deletions

90
lib/constant/api_key.dart Executable file
View File

@@ -0,0 +1,90 @@
import 'package:secure_string_operations/secure_string_operations.dart';
import '../env/env.dart';
import 'char_map.dart';
class AK {
static final String sss_pass = X.r(X.r(X.r(Env.sss_pass, cn), cC), cs);
static final String allowed = Env.allowed;
static final String allowedWallet = Env.allowedWallet;
static final String passnpassenger = X
.r(X.r(X.r(Env.passnpassenger, cn), cC), cs)
.toString()
.split(Env.addd)[0];
static final String newId = Env.newId;
static final String sss_encryptionSalt =
X.r(X.r(X.r(Env.sss_encryptionSalt, cn), cC), cs);
static final String publishableKeyStripe =
X.r(X.r(X.r(Env.stripePublishableKe, cn), cC), cs);
static final String secretKeyStripe =
X.r(X.r(X.r(Env.secretKey, cn), cC), cs);
static final String basicAuthCredentials =
X.r(X.r(X.r(Env.basicAuthCredentials, cn), cC), cs);
static final String basicCompareFaces =
X.r(X.r(X.r(Env.basicCompareFaces, cn), cC), cs);
static final String accountSIDTwillo =
X.r(X.r(X.r(Env.accountSIDTwillo, cn), cC), cs);
static final String serverAPI = X.r(X.r(X.r(Env.serverAPI, cn), cC), cs);
static final String mapAPIKEY = X.r(X.r(X.r(Env.mapAPIKEY, cn), cC), cs);
static final String twilloRecoveryCode =
X.r(X.r(X.r(Env.twilloRecoveryCode, cn), cC), cs);
static final String authTokenTwillo =
X.r(X.r(X.r(Env.authTokenTwillo, cn), cC), cs);
static final String chatGPTkey = X.r(X.r(X.r(Env.chatGPTkey, cn), cC), cs);
static final String transactionCloude =
X.r(X.r(X.r(Env.transactionCloude, cn), cC), cs);
static final String visionApi = X.r(X.r(X.r(Env.visionApi, cn), cC), cs);
static final String chatGPTkeySefer =
X.r(X.r(X.r(Env.chatGPTkeySefer, cn), cC), cs);
static final String chatGPTkeySeferNew =
X.r(X.r(X.r(Env.chatGPTkeySeferNew, cn), cC), cs);
static final String serverPHP = Env.serverPHP;
static final String llamaKey = X.r(X.r(X.r(Env.llamaKey, cn), cC), cs);
static final String cohere = X.r(X.r(X.r(Env.cohere, cn), cC), cs);
static final String claudeAiAPI = X.r(X.r(X.r(Env.claudeAiAPI, cn), cC), cs);
static final String payPalClientId =
X.r(X.r(X.r(Env.payPalClientId, cn), cC), cs);
static final String payPalSecret =
X.r(X.r(X.r(Env.payPalSecret, cn), cC), cs);
static final String geminiApi = X.r(X.r(X.r(Env.geminiApi, cn), cC), cs);
static final String agoraAppId = X.r(X.r(X.r(Env.agoraAppId, cn), cC), cs);
static final String agoraAppCertificate =
X.r(X.r(X.r(Env.agoraAppCertificate, cn), cC), cs);
static final String payPalClientIdLive =
X.r(X.r(X.r(Env.payPalClientIdLive, cn), cC), cs);
static final String payPalSecretLive =
X.r(X.r(X.r(Env.payPalSecretLive, cn), cC), cs);
static final String integrationIdPayMob =
X.r(X.r(X.r(Env.integrationIdPayMob, cn), cC), cs);
static final String passwordPayMob =
X.r(X.r(X.r(Env.passwordPayMob, cn), cC), cs);
static final String usernamePayMob =
X.r(X.r(X.r(Env.usernamePayMob, cn), cC), cs);
static final String payMobApikey =
X.r(X.r(X.r(Env.payMobApikey, cn), cC), cs);
static final String integrationIdPayMobWallet =
X.r(X.r(X.r(Env.integrationIdPayMobWallet, cn), cC), cs);
static final String smsPasswordEgypt =
X.r(X.r(X.r(Env.smsPasswordEgypt, cn), cC), cs);
static final String ocpApimSubscriptionKey = Env.ocpApimSubscriptionKey;
static final String chatGPTkeySeferNew4 =
X.r(X.r(X.r(Env.chatGPTkeySeferNew4, cn), cC), cs);
static final String anthropicAIkeySeferNew =
X.r(X.r(X.r(Env.anthropicAIkeySeferNew, cn), cC), cs);
static final String llama3Key = X.r(X.r(X.r(Env.llama3Key, cn), cC), cs);
static final String payMobOutPassword =
X.r(X.r(X.r(Env.payMobOutPassword, cn), cC), cs);
// static final String privateKeyFCM = Env.privateKeyFCM;
static final String payMobOutUserName =
X.r(X.r(X.r(Env.payMobOutUserName, cn), cC), cs);
///////////
static final String keyOfApp = X.r(X.r(X.r(Env.keyOfApp, cn), cC), cs);
}
class KN {
static const String pmobsec = 'PAYMOBOUTCLIENTSECRET';
static const String pmobid = 'PAYMOBOUTCLIENT_ID';
}

116
lib/constant/box_name.dart Executable file
View File

@@ -0,0 +1,116 @@
class BoxName {
static const String driverID = "driverID";
static const String countryCode = "countryCode";
static const String googlaMapApp = "googlaMapApp";
static const String keyOfApp = 'keyOfApp';
static const String initializationVector = 'initializationVector';
static const String firstTimeLoadKey = 'firstTimeLoadKey';
static const String jwt = "jwt";
static const String rideId = "rideId";
static const String rideArgumentsFromBackground =
"rideArgumentsFromBackground";
static const String FCM_PRIVATE_KEY = "FCM_PRIVATE_KEY";
static const String hmac = "hmac";
static const String fingerPrint = "fingerPrint";
static const String payMobApikey = "payMobApikey";
static const String refreshToken = "refreshToken";
static const String lang = "lang";
static const String isvibrate = "isvibrate";
static const String myListString = "myListString";
static const String myList = "myList";
static const String bodyOrder = "bodyOrder";
static const String gender = "gender";
static const String phoneWallet = "phoneWallet";
static const String locationName = "locationName";
static const String basicLink = "basicLink";
static const String paymentLink = "paymentLink";
static const String isSavedPhones = "IsSavedPhones";
static const String isTest = "isTest";
static const String carType = "carType";
static const String carTypeOfDriver = "carTypeOfDriver";
static const String isFirstTime = "isFirstTime";
static const String deviceInfo = "deviceInfo";
static const String packagInfo = "packagInfo";
static const String phoneVerified = "phoneVerified";
static const String carPlate = "carPlate";
static const String statusDriverLocation = "statusDriverLocation";
static const String rideStatus = "rideStatus";
static const String nameArabic = "nameArabic";
static const String carYear = "carYear";
static const String password = "password";
static const String isVerified = '0';
static const String arrivalTime = "arrivalTime";
static const String locationPermission = "locationPermission";
static const String passwordDriver = "passwordDriver";
static const String agreeTerms = "agreeTerms";
static const String addWork = 'addWork';
static const String addHome = 'addHome';
static const String rideArguments = 'rideArguments';
static const String durationData = 'durationData';
static const String rideStaticDriverData = 'rideStaticDriverData';
static const String lastTimeStaticThrottle = 'lastTimeStaticThrottle';
static const String lastTimeCaptainWalletCashOut =
'lastTimeCaptainWalletCashOut';
static const String tipPercentage = 'tipPercentage';
static const String accountIdStripeConnect = "accountIdStripeConnect";
static const String faceDetectTimes = "faceDetectTimes";
static const String sosPhonePassenger = "sosPhonePassenger";
static const String sosPhoneDriver = "sosPhoneDriver";
static const String passengerID = "pasengerID";
static const String phone = "phone";
static const String phoneDriver = "phoneDriver";
static const String is_claimed = "is_claimed";
static const String isInstall = "isInstall";
static const String isGiftToken = "isGiftToken";
static const String lastOtpTime = "lastOtpTime";
static const String bankCodeDriver = "bankCodeDriver";
static const String accountBankNumberDriver = "accountBankNumberDriver";
static const String dobDriver = "dobDriver";
static const String sexDriver = "sexDriver";
static const String lastNameDriver = "lastNameDriver";
static const String name = "name";
static const String nameDriver = "nameDriver";
static const String driverPhotoUrl = "driverPhotoUrl";
static const String email = "email";
static const String emailDriver = "emailDriver";
static const String tokens = "tokens";
static const String tokenFCM = "tokenFCM";
static const String tokenDriver = "tokenDriver";
static const String cardNumber = "cardNumber";
static const String cardNumberDriver = "cardNumberDriver";
static const String cardHolderName = "cardHolderName";
static const String cardHolderNameDriver = "cardHolderNameDriver";
static const String expiryDate = "expiryDate";
static const String expiryDateDriver = "expiryDateDriver";
static const String cvvCode = "cvvCode";
static const String cvvCodeDriver = "cvvCodeDriver";
static const String passengerWalletDetails = "passengerWalletDetails";
static const String passengerWalletTotal = "passengerWalletTotal";
static const String passengerWalletFound = "passengerWalletFound";
static const String periods = 'periods';
static const String onBoarding = 'onBoarding';
static const String stripePublishableKey = 'stripe_publishableKe';
static const String apiKeyRun = 'apiKeyRun';
static const String serverAPI = 'serverAPI';
static const String serverChosen = 'serverChosen';
static const String secretKey = 'secretKey';
static const String basicAuthCredentials = 'basicAuthCredentials';
static const String mapAPIKEY = 'mapAPIKEY';
static const String twilloRecoveryCode = 'twilloRecoveryCode';
static const String accountSIDTwillo = 'accountSIDTwillo';
static const String authTokenTwillo = 'authTokenTwillo';
static const String chatGPTkey = 'chatGPTkey';
static const String chatGPTkeySefer = 'chatGPTkeySefer';
static const String transactionCloude = 'transactionCloude';
static const String visionApi = 'visionApi';
static const String vin = "vin";
static const String make = "make";
static const String model = "model";
static const String year = "year";
static const String expirationDate = "expirationDate";
static const String color = "color";
static const String owner = "owner";
static const String registrationDate = "registrationDate";
static const String recentLocations = 'recentLocations';
static const String tripData = 'tripData';
}

75
lib/constant/char_map.dart Executable file
View File

@@ -0,0 +1,75 @@
import '../env/env.dart';
Map<String, String> cs = {
"a": Env.a,
"b": Env.b,
"c": Env.c,
"d": Env.d,
"e": Env.e,
"f": Env.f,
"g": Env.g,
"h": Env.h,
"i": Env.i,
"j": Env.j,
"k": Env.k,
"l": Env.l,
"m": Env.m,
"n": Env.n,
"o": Env.o,
"p": Env.p,
"q": Env.q,
"r": Env.r,
"s": Env.s,
"t": Env.t,
"u": Env.u,
"v": Env.v,
"w": Env.w,
"x": Env.x,
"y": Env.y,
"z": Env.z,
};
Map<String, String> cC = {
"A": Env.A,
"B": Env.B,
"C": Env.C,
"D": Env.D,
"E": Env.E,
"F": Env.F,
"G": Env.G,
"H": Env.H,
"I": Env.I,
"J": Env.J,
"K": Env.K,
"L": Env.L,
"M": Env.M,
"N": Env.N,
"O": Env.O,
"P": Env.P,
"Q": Env.Q,
"R": Env.R,
"S": Env.S,
"T": Env.T,
"U": Env.U,
"V": Env.V,
"W": Env.W,
"X": Env.X,
"Y": Env.Y,
"Z": Env.Z
};
//
//
Map<String, String> cn = {
"0": "3",
"1": "7",
"2": "1",
"3": "9",
"4": "0",
"5": "5",
"6": "2",
"7": "6",
"8": "4",
"9": "8"
};

33
lib/constant/colors.dart Executable file
View File

@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
class AppColor {
static const Color primaryColor = Color(0xFF1DA1F2);
static const Color writeColor = Color(0xff222359);
static const Color bronze = Color(0xFFCD7F32);
static const Color goldenBronze = Color(0xFFB87333); // Golden bronze color
static const Color gold = Color(0xFFD4AF37);
static const Color secondaryColor = Colors.white;
static const Color accentColor = Colors.grey;
static const Color greyColor = Colors.grey;
static const Color twitterColor = Color(0xFF1DA1F2); // Twitter blue
static const Color redColor = Color(0xFFEA4335); // Google Red
static const Color greenColor = Color(0xFF34A853); // Google Green
static const Color blueColor = Color(0xFF1DA1F2); // Google Blue
static const Color yellowColor = Color(0xFFFBBC05); // Google Yellow
static Color deepPurpleAccent =
const Color.fromARGB(255, 123, 76, 254).withOpacity(0.3);
// For dynamic elements like gradients
static List<Color> gradientStartEnd = [
Color.fromARGB(255, 40, 158, 232), // Start with primary color
Color.fromARGB(
255, 44, 63, 75), // End with a slightly darker shade of Twitter blue
];
static List<Color> secondaryGradientStartEnd = [
const Color(0xFF1DA1F2), // Start with Twitter blue
const Color(0xFF0C7ABF), // End with a slightly darker shade of Twitter blue
];
}

104
lib/constant/credential.dart Executable file
View File

@@ -0,0 +1,104 @@
import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import '../controller/functions/crud.dart';
import '../main.dart';
import 'box_name.dart';
import 'char_map.dart';
import 'links.dart';
class AC {
gAK() async {
if (box.read(BoxName.apiKeyRun).toString() != 'run') {
var res = await CRUD().get(link: AppLink.getApiKey, payload: {});
var decod = jsonDecode(res);
// print(decod);
Map<String, dynamic> jsonData = {};
for (var i = 0; i < decod['message'].length; i++) {
String h = decod['message'][i]['hashed_key'].toString();
String retrievedString = X.r(X.r(X.r(h, cn), cC), cs);
await storage.write(
key: decod['message'][i]['name'].toString(),
value: retrievedString.toString(),
);
//
String name = decod['message'][i]['name'].toString();
String value = decod['message'][i]['hashed_key'].toString();
jsonData[name] = value;
}
String jsonString = json.encode(jsonData);
print(jsonString);
box.write(BoxName.apiKeyRun, 'run');
}
}
String q(String b, String c) {
final d = utf8.encode(c);
final e = utf8.encode(b);
final f = Hmac(sha256, d);
final g = f.convert(e);
final h = g.bytes;
final i = base64Url.encode(h);
return i;
}
String j(String k, String l) {
final m = utf8.encode(l);
final n = base64Url.decode(k);
final o = Hmac(sha256, m);
final p = o.convert(n);
final q = utf8.decode(p.bytes);
return q;
}
String a(String b, String c) {
int d = b.length;
int e = d ~/ 4;
List<String> f = [];
for (int g = 0; g < d; g += e) {
int h = g + e;
if (h > d) {
h = d;
}
String i = b.substring(g, h);
f.add(i);
}
print(f);
Map<String, String> j = {};
j['birinci'] = f[4];
j['ikinci'] = f[2];
j['üçüncü'] = c + f[1];
j['dördüncü'] = f[0];
j['beş'] = f[3];
String k = '';
j.forEach((l, m) {
k += m;
});
return k;
}
Map<String, String> n(String o, String c) {
String p = o.replaceAll(c, '');
Map<String, String> q = {};
q['birinci'] = p[p.length - 5] + p[p.length - 3];
q['ikinci'] = p[p.length - 1] + p[p.length - 15];
q['üçüncü'] = p[p.length - 9] + p[p.length - 12];
q['dördüncü'] = p[p.length - 11] + p[p.length - 6];
q['beş'] = p[p.length - 2] + p[p.length - 8];
return q;
}
}

4508
lib/constant/info.dart Executable file

File diff suppressed because one or more lines are too long

382
lib/constant/links.dart Executable file
View File

@@ -0,0 +1,382 @@
// import 'package:sefer_driver/env/env.dart';
import 'package:sefer_driver/env/env.dart';
import '../main.dart';
import 'box_name.dart';
class AppLink {
static String serverPHP = box.read('serverPHP');
static String seferPaymentServer =
'https://walletintaleq.intaleq.xyz/v1/main';
static String seferPaymentServer0 =
'https://walletintaleq.intaleq.xyz/v1/main';
static final String endPoint = 'https://intaleq.xyz/intaleq';
// 'https://api.tripz-egypt.com/tripz';
static final String server = endPoint;
static String seferCairoServer = endPoint;
static String seferGizaServer =
box.read('Giza') ?? box.read(BoxName.serverChosen);
static String seferAlexandriaServer =
box.read('Alexandria') ?? box.read(BoxName.serverChosen);
// static final String server = Env.serverPHP;
static String loginJwtDriver = "$server/loginJwtDriver.php";
static String loginJwtWalletDriver =
"$seferPaymentServer/loginJwtWalletDriver.php";
static String loginFirstTimeDriver = "$server/loginFirstTimeDriver.php";
static String googleMapsLink = 'https://maps.googleapis.com/maps/api/';
static String llama = 'https://api.llama-api.com/chat/completions';
static String gemini =
'https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText';
static String test = "$server/test.php";
static String ride = '$server/ride';
//===============contact==========================
static String savePhones = "$ride/egyptPhones/add.php";
static String getPhones = "$ride/egyptPhones/get.php";
////===============firebase==========================
static String getTokens = "$ride/firebase/get.php";
static String getDriverToken = "$ride/firebase/getDriverToken.php";
static String addTokens = "$ride/firebase/add.php";
static String addTokensDriver = "$ride/firebase/addDriver.php";
//=======================Wallet===================
static String wallet = '$seferPaymentServer/ride/passengerWallet';
static String walletDriver = '$seferPaymentServer/ride/driverWallet';
static String getAllPassengerTransaction =
"$wallet/getAllPassengerTransaction.php";
static String payWithMTNConfirm =
"$seferPaymentServer/ride/mtn/driver/confirm_payment.php";
static String payWithMTNStart =
"$seferPaymentServer/ride/mtn/driver/mtn_start.php";
static String payWithEcashDriver =
"$seferPaymentServer/ride/ecash/driver/payWithEcash.php";
static String payWithEcashPassenger =
"$seferPaymentServer/ride/ecash/passenger/payWithEcash.php";
// wl.tripz-egypt.com/v1/main/ride/ecash/driver
static String getWalletByPassenger = "$wallet/getWalletByPassenger.php";
static String getPassengersWallet = "$wallet/get.php";
static String getPassengerWalletArchive =
"$wallet/getPassengerWalletArchive.php";
static String addPassengersWallet = "$wallet/add.php";
static String deletePassengersWallet = "$wallet/delete.php";
static String updatePassengersWallet = "$wallet/update.php";
static String getWalletByDriver = "$walletDriver/getWalletByDriver.php";
static String driverStatistic = "$walletDriver/driverStatistic.php";
static String getDriverDetails =
"$seferCairoServer/ride/driverWallet/getDriverDetails.php";
static String getDriverWeekPaymentMove =
"$walletDriver/getDriverWeekPaymentMove.php";
static String getDriversWallet = "$walletDriver/get.php";
static String addDriversWalletPoints = "$walletDriver/add.php";
static String addpromotionDriver = "$walletDriver/promotionDriver.php";
static String deleteDriversWallet = "$walletDriver/delete.php";
static String updateDriversWallet = "$walletDriver/update.php";
//=======================promo===================ride.mobile-app.store/ride/promo/get.php
static String promo = '$server/ride/promo';
static String getPassengersPromo = "$promo/get.php";
static String getPromoBytody = "$promo/getPromoBytody.php";
static String addPassengersPromo = "$promo/add.php";
static String deletePassengersPromo = "$promo/delete.php";
static String updatePassengersPromo = "$promo/update.php";
////=======================cancelRide===================
static String addCancelRideFromPassenger = "$ride/cancelRide/add.php";
static String addCancelTripFromDriverAfterApplied =
"$ride/cancelRide/addCancelTripFromDriverAfterApplied.php";
static String cancelRide = "$ride/cancelRide/get.php";
//-----------------ridessss------------------
static String addRides = "$ride/rides/add.php";
static String getRides = "$ride/rides/get.php";
static String getMishwari = "$ride/mishwari/get.php";
static String getMishwariDriver = "$ride/mishwari/getDriver.php";
static String getTripCountByCaptain = "$ride/rides/getTripCountByCaptain.php";
static String getRideOrderID = "$ride/rides/getRideOrderID.php";
static String getRideStatus = "$ride/rides/getRideStatus.php";
static String getOverLayStatus = "$ride/overLay/get.php";
static String getArgumentAfterAppliedFromBackground =
"$ride/overLay/getArgumentAfterAppliedFromBackground.php";
static String addOverLayStatus = "$ride/overLay/add.php";
static String getapiKey = "$ride/apiKey/get.php";
static String getapiKeySefer = "$ride/apiKey/get.php";
static String getRideStatusBegin = "$ride/rides/getRideStatusBegin.php";
static String getRideStatusFromStartApp =
"$ride/rides/getRideStatusFromStartApp.php";
static String updateRides = "$ride/rides/update.php";
static String updateRideAndCheckIfApplied =
"$ride/rides/updateRideAndCheckIfApplied.php";
static String updateStausFromSpeed = "$ride/rides/updateStausFromSpeed.php";
static String deleteRides = "$ride/rides/delete.php";
//-----------------DriverPayment------------------
static String addDriverScam = "$ride/driver_scam/add.php";
static String getDriverScam = "$ride/driver_scam/get.php";
/////////---getKazanPercent===////////////
static String getKazanPercent = "$ride/kazan/get.php";
static String addKazanPercent = "$ride/kazan/add.php";
////-----------------DriverPayment------------------
static String addDrivePayment = "$seferPaymentServer/ride/payment/add.php";
static String payWithPayMobCardDriver =
"$seferPaymentServer/ride/payMob/paymob_driver/payWithCard.php";
static String payWithWallet =
"$seferPaymentServer/ride/payMob/paymob_driver/payWithWallet.php";
static String paymetVerifyDriver =
"$seferPaymentServer/ride/payMob/paymob_driver/paymet_verfy.php";
static String updatePaymetToPaid =
"$seferPaymentServer/ride/payment/updatePaymetToPaid.php";
static String paymobPayoutDriverWallet =
"$seferPaymentServer/ride/payMob/paymob_driver/paymob_payout.php'";
static String addSeferWallet = "$seferPaymentServer/ride/seferWallet/add.php";
static String getSeferWallet = "$seferPaymentServer/ride/seferWallet/get.php";
static String addDriverPaymentPoints =
"$seferPaymentServer/ride/driverPayment/add.php";
static String addPaymentTokenDriver =
"$seferPaymentServer/ride/driverWallet/addPaymentToken.php"; //driverWallet/addPaymentToken.php
static String addPaymentTokenPassenger =
"$seferPaymentServer/ride/passengerWallet/addPaymentTokenPassenger.php";
static String getDriverPaymentPoints =
"$seferPaymentServer/ride/driverWallet/get.php";
static String getDriverPaymentToday =
"$seferPaymentServer/ride/payment/get.php";
static String getCountRide = "$ride/payment/getCountRide.php";
static String getAllPaymentFromRide =
"$seferPaymentServer/ride/payment/getAllPayment.php";
static String getAllPaymentVisa =
"$seferPaymentServer/ride/payment/getAllPaymentVisa.php";
//-----------------Passenger NotificationCaptain------------------
static String addNotificationPassenger =
"$ride/notificationPassenger/add.php";
static String getNotificationPassenger =
"$ride/notificationPassenger/get.php";
static String updateNotificationPassenger =
"$ride/notificationPassenger/update.php";
//-----------------Driver NotificationCaptain------------------
static String addNotificationCaptain = "$ride/notificationCaptain/add.php";
static String addWaitingRide = "$ride/notificationCaptain/addWaitingRide.php";
static String deleteAvailableRide =
"$ride/notificationCaptain/deleteAvailableRide.php";
static String updateWaitingRide =
"$ride/notificationCaptain/updateWaitingTrip.php";
static String getRideWaiting =
"$endPoint/ride/notificationCaptain/getRideWaiting.php";
static String getNotificationCaptain = "$ride/notificationCaptain/get.php";
static String updateNotificationCaptain =
"$ride/notificationCaptain/update.php";
static String deleteNotificationCaptain =
"$ride/notificationCaptain/delete.php";
//-----------------Api Key------------------
static String addApiKey = "$ride/apiKey/add.php";
static String getApiKey = "$ride/apiKey/get.php";
static String getCnMap = "$server/auth/cnMap.php";
static String getPromptDriverDocumentsEgypt =
"$server/auth/captin/getPromptDriverDocumentsEgypt.php";
static String updateApiKey = "$ride/apiKey/update.php";
static String deleteApiKey = "$ride/apiKey/delete.php";
static String checkPhoneNumberISVerfiedDriver =
"$auth/checkPhoneNumberISVerfiedDriver.php";
static String getTesterApp = "$auth/Tester/getTesterApp.php";
static String updateTesterApp = "$auth/Tester/updateTesterApp.php";
//-----------------healthInsuranceProvider------------------
static String addHealthInsuranceProvider = "$server/driver_assurance/add.php";
static String getHealthInsuranceProvider = "$server/driver_assurance/get.php";
//-----------------Feed Back------------------
static String addFeedBack = "$ride/feedBack/add.php";
static String getFeedBack = "$ride/feedBack/get.php";
static String updateFeedBack = "$ride/feedBack/updateFeedBack.php";
//-----------------Tips------------------
static String addTips = "$ride/tips/add.php";
static String getTips = "$ride/tips/get.php";
static String updateTips = "$ride/tips/update.php";
//-----------------Help Center------------------
static String addhelpCenter = "$ride/helpCenter/add.php";
static String gethelpCenter = "$ride/helpCenter/get.php";
static String getByIdhelpCenter = "$ride/helpCenter/getById.php";
static String updatehelpCenter = "$ride/helpCenter/update.php";
static String deletehelpCenter = "$ride/helpCenter/delete.php";
//-----------------license------------------
static String addLicense = "$ride/license/add.php";
static String getLicense = "$ride/license/get.php";
static String updateLicense = "$ride/license/updateFeedBack.php";
//-----------------RegisrationCar------------------
static String addRegisrationCar = "$ride/RegisrationCar/add.php";
static String getRegisrationCar = "$endPoint/ride/RegisrationCar/get.php";
static String updateRegisrationCar = "$ride/RegisrationCar/update.php";
static String makeDefaultCar = "$ride/RegisrationCar/makeDefaultCar.php";
//-----------------DriverOrder------------------
static String addDriverOrder = "$ride/driver_order/add.php";
static String getDriverOrder = "$ride/driver_order/get.php";
static String getOrderCancelStatus =
"$ride/driver_order/getOrderCancelStatus.php";
static String updateDriverOrder = "$ride/driver_order/update.php";
static String deleteDriverOrder = "$ride/driver_order/delete.php";
// =====================================
static String addRateToPassenger = "$ride/rate/add.php";
static String addRateToDriver = "$ride/rate/addRateToDriver.php";
static String addRateApp = "$ride/rate/add_rate_app.php";
static String sendEmailRateingApp = "$ride/rate/sendEmailRateingApp.php";
static String getDriverRate = "$ride/rate/getDriverRate.php";
static String getPassengerRate = "$ride/rate/getPassengerRate.php";
////////////////emails ============//
static String sendEmailToPassengerForTripDetails =
"$ride/rides/emailToPassengerTripDetail.php";
static String sendEmailToDrivertransaction =
"$server/Admin/sendEmailToDrivertransaction.php";
// ===========================================
static String pathImage = "$server/upload/types/";
static String uploadImage = "$server/uploadImage.php";
static String uploadImage1 = "$server/uploadImage1.php";
static String uploadImagePortrate = "$server/uploadImagePortrate.php";
static String uploadImageType = "$server/uploadImageType.php";
//=============egypt documents ==============
static String uploadEgyptidFront =
"$server/EgyptDocuments/uploadEgyptidFront.php";
static String uploadEgypt = "$server/uploadEgypt.php";
static String uploadEgypt1 = "$server/uploadEgypt1.php";
//==================certifcate==========
static String location = '$endPoint/ride/location';
static String getCarsLocationByPassenger = "$location/get.php";
static String addpassengerLocation = "$location/addpassengerLocation.php";
static String getLocationAreaLinks = "$location/get_location_area_links.php";
static String getLatestLocationPassenger =
"$location/getLatestLocationPassenger.php";
static String getFemalDriverLocationByPassenger =
"$location/getFemalDriver.php";
static String getDriverCarsLocationToPassengerAfterApplied =
"$location/getDriverCarsLocationToPassengerAfterApplied.php";
static String addCarsLocationByPassenger = "$location/add.php";
static String saveBehavior = "$location/save_behavior.php";
static String addCarsLocationGizaEndpoint = "$location/add.php";
static String addCarsLocationAlexandriaEndpoint = "$location/add.php";
static String addCarsLocationCairoEndpoint = "$location/add.php";
static String deleteCarsLocationByPassenger = "$location/delete.php";
static String updateCarsLocationByPassenger = "$location/update.php";
static String getTotalDriverDuration = "$location/getTotalDriverDuration.php";
static String getRidesDriverByDay = "$location/getRidesDriverByDay.php";
static String getTotalDriverDurationToday =
"$location/getTotalDriverDurationToday.php";
//==================get_driver_behavior.php=============
static String get_driver_behavior =
'$ride/driver_behavior/get_driver_behavior.php';
//==================cars new drivers=============
static String addNewCarsDrivers = '$ride/carDrivers/add.php';
static String getNewCarsDrivers = '$ride/carDrivers/get.php';
static String deleteNewCarsDrivers = '$ride/carDrivers/delete.php';
//==================Blog=============
static String profile = '$ride/profile';
static String getprofile = "$profile/get.php";
static String getCaptainProfile = "$profile/getCaptainProfile.php";
static String addprofile = "$profile/add.php";
static String deleteprofile = "$profile/delete.php";
static String updateprofile = "$profile/update.php";
//===================Auth============
static String addInviteDriver = "$ride/invitor/add.php";
static String addInvitationPassenger =
"$ride/invitor/addInvitationPassenger.php";
static String getInviteDriver = "$ride/invitor/get.php";
static String getDriverInvitationToPassengers =
"$ride/invitor/getDriverInvitationToPassengers.php";
static String updateInviteDriver = "$ride/invitor/update.php";
static String updatePassengerGift = "$ride/invitor/updatePassengerGift.php";
static String updateInvitationCodeFromRegister =
"$ride/invitor/updateInvitationCodeFromRegister.php";
static String updateDriverInvitationDirectly =
"$ride/invitor/updateDriverInvitationDirectly.php";
static String updatePassengersInvitation =
"$ride/invitor/updatePassengersInvitation.php";
//===================Auth============
static String auth = '$server/auth';
static String login = "$auth/login.php";
static String signUp = "$auth/signup.php";
static String updateDriverClaim = "$auth/captin/updateDriverClaim.php";
static String sendVerifyEmail = "$auth/sendVerifyEmail.php";
static String passengerRemovedAccountEmail =
"$auth/passengerRemovedAccountEmail.php";
static String verifyEmail = "$auth/verifyEmail.php";
//===================Auth Captin============
static String authCaptin = '$server/auth/captin';
static String loginCaptin = "$authCaptin/login.php";
static String loginFromGoogleCaptin = "$authCaptin/loginFromGoogle.php";
static String loginUsingCredentialsWithoutGoogle =
"$authCaptin/loginUsingCredentialsWithoutGoogle.php";
static String packageInfo = "$server/auth/packageInfo.php";
static String signUpCaptin = "$authCaptin/register.php";
static String addCriminalDocuments = "$authCaptin/addCriminalDocuments.php";
static String sendVerifyEmailCaptin = "$authCaptin/sendVerifyEmail.php";
static String sendVerifyOtpMessage =
"$server/auth/captin/sendOtpMessageDriver.php";
static String verifyOtpMessage = "$server/auth/verifyOtpMessage.php";
static String verifyOtpDriver = "$server/auth/captin/verifyOtpDriver.php";
static String verifyEmailCaptin = "$authCaptin/verifyEmail.php";
static String removeUser = "$authCaptin/removeAccount.php";
static String deletecaptainAccounr = "$authCaptin/deletecaptainAccounr.php";
static String updateAccountBank = "$authCaptin/updateAccountBank.php";
static String getAccount = "$authCaptin/getAccount.php";
static String uploadImageToAi = "$auth/document_syria/ai_document.php";
static String isPhoneVerified = "$auth/syria/driver/isPhoneVerified.php";
//===================Admin Captin============
static String getPassengerDetailsByPassengerID =
"$server/Admin/getPassengerDetailsByPassengerID.php";
static String getPassengerDetails = "$server/Admin/getPassengerDetails.php";
static String getPassengerbyEmail = "$server/Admin/getPassengerbyEmail.php";
static String addAdminUser = "$server/Admin/adminUser/add.php";
static String addError = "$server/Admin/errorApp.php";
static String getAdminUser = "$server/Admin/adminUser/get.php";
static String getCaptainDetailsByEmailOrIDOrPhone =
"$server/Admin/AdminCaptain/getCaptainDetailsByEmailOrIDOrPhone.php";
static String getCaptainDetails = "$server/Admin/AdminCaptain/get.php";
static String getRidesPerMonth =
"$server/Admin/AdminRide/getRidesPerMonth.php";
static String getRidesDetails = "$server/Admin/AdminRide/get.php";
//////////Sms egypt///////////
static String sendSms = "https://sms.kazumi.me/api/sms/send-sms";
static String senddlr = "https://sms.kazumi.me/api/sms/send-dlr";
static String sendvalidity = "https://sms.kazumi.me/api/sms/send-validity";
static String sendmany = "https://sms.kazumi.me/api/sms/send-many";
static String checkCredit = "https://sms.kazumi.me/api/sms/check-credit";
static String checkStatus = "https://sms.kazumi.me/api/sms/check-status";
static String getSender = "$server/auth/sms/getSender.php";
static String updatePhoneInvalidSMS =
"$server/auth/sms/updatePhoneInvalidSMS.php";
//////////////service///////////
static String serviceApp = "$server/serviceapp";
static String getComplaintAllData = "$serviceApp/getComplaintAllData.php";
static String getComplaintAllDataForDriver =
"$serviceApp/getComplaintAllDataForDriver.php";
}

22
lib/constant/notification.dart Executable file
View File

@@ -0,0 +1,22 @@
List<String> driverMessages = [
"💸 فرص الربح: افتح تطبيق انطلق الآن وزد دخلك اليوم! المزيد من الطلبات بانتظارك! 🚗",
"🚀 طلبات جديدة: لا تضيع الفرصة! المزيد من الركاب ينتظرونك الآن على تطبيق انطلق. 🏃‍♂️",
"📈 زيادة الدخل: حقق أعلى أرباح اليوم مع انطلق! افتح التطبيق وابدأ عملك الآن. 💵",
"🕒 أوقات الذروة: استعد لكسب المزيد خلال فترات الطلب المرتفعة. افتح التطبيق الآن! 📲",
"🚗 طلبات جديدة: كن مستعداً، افتح تطبيق انطلق الآن واستقبل المزيد من الطلبات. 🔔",
"🎉 فرص النجاح: ابدأ رحلتك إلى النجاح! افتح تطبيق انطلق لزيادة دخلك اليوم. 💼",
"🌍 طلبات مرتفعة: المزيد من الركاب بانتظارك، لا تفوّت الفرص، افتح التطبيق الآن! 🚖",
"💪 زيادة الدخل: انطلق نحو تحقيق أهدافك المالية، افتح تطبيق انطلق واكسب المزيد. 🏆",
"💰 أرباح إضافية: افتح التطبيق واستعد لتحقيق أرباح إضافية مع انطلق! المزيد من الطلبات في انتظارك. 🛣️",
"🔥 فرص جديدة: تطبيق انطلق مزدحم الآن! افتح التطبيق وزد أرباحك بفرص جديدة. 🚗",
"🚨 طلبات متزايدة: افتح تطبيق انطلق الآن! الطلب مرتفع وفرص الربح كبيرة! 💸",
"💼 زيادة الدخل: هل أنت جاهز لتحقيق المزيد من الدخل؟ افتح التطبيق وانطلق الآن! 🚖",
"🚗 أوقات الذروة: احجز مقعدك في فترات الطلب العالي، افتح تطبيق انطلق الآن واكسب المزيد. 📈",
"📲 بدء اليوم: ابدأ يومك مع انطلق، وافتح التطبيق الآن لتزيد من فرص الربح. 💵",
"💸 فرص مستمرة: لا تفوت فرص الربح، افتح تطبيق انطلق الآن وكن على استعداد للمزيد! 🔔",
"📆 زيادة الطلب: انطلق اليوم واستفد من الطلبات المتزايدة على تطبيق انطلق! افتح التطبيق الآن. 🚗",
"💥 دخل إضافي: افتح تطبيق انطلق الآن واستقبل طلبات جديدة تحقق لك المزيد من الدخل. 💰",
"🏆 فرص مرتفعة: استفد من طلبات اليوم المرتفعة، افتح التطبيق الآن مع انطلق. 📲",
"🚗 تفضيل العملاء: كن السائق الذي يختاره الجميع! افتح تطبيق انطلق اليوم واربح المزيد. 🔥",
"💸 دخل إضافي: فرص الدخل الإضافي في انتظارك! افتح تطبيق انطلق واستمتع بالطلبات المتزايدة. 💼",
];

70
lib/constant/style.dart Executable file
View File

@@ -0,0 +1,70 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/main.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'colors.dart';
class AppStyle {
static TextStyle headTitle = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 36,
color: AppColor.accentColor,
fontFamily: box.read(BoxName.lang) == 'ar'
// ?GoogleFonts.markaziText().fontFamily
? GoogleFonts.markaziText().fontFamily
: GoogleFonts.inter().fontFamily);
static TextStyle headTitle2 = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24,
color: AppColor.writeColor,
fontFamily: box.read(BoxName.lang) == 'ar'
? GoogleFonts.markaziText().fontFamily
: GoogleFonts.inter().fontFamily);
static TextStyle title = TextStyle(
fontWeight: FontWeight.normal,
fontSize: 16,
color: AppColor.writeColor,
fontFamily: box.read(BoxName.lang) == 'ar'
? GoogleFonts.markaziText().fontFamily
: GoogleFonts.inter().fontFamily);
static TextStyle subtitle = TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12,
color: AppColor.writeColor,
fontFamily: box.read(BoxName.lang) == 'ar'
? GoogleFonts.markaziText().fontFamily
: GoogleFonts.inter().fontFamily);
static TextStyle number = const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: AppColor.writeColor,
fontFamily: 'digit');
static BoxDecoration boxDecoration = const BoxDecoration(
boxShadow: [
BoxShadow(
color: AppColor.accentColor, blurRadius: 5, offset: Offset(2, 4)),
BoxShadow(
color: AppColor.accentColor, blurRadius: 5, offset: Offset(-2, -2))
],
color: AppColor.secondaryColor,
borderRadius: BorderRadius.all(
Radius.elliptical(15, 30),
));
static BoxDecoration boxDecoration1 = const BoxDecoration(
boxShadow: [
BoxShadow(
color: Color.fromARGB(255, 237, 230, 230),
blurRadius: 5,
offset: Offset(2, 4)),
BoxShadow(
color: Color.fromARGB(255, 242, 237, 237),
blurRadius: 5,
offset: Offset(-2, -2))
],
color: AppColor.secondaryColor,
borderRadius: BorderRadius.all(
Radius.elliptical(15, 30),
),
);
}

19
lib/constant/table_names.dart Executable file
View File

@@ -0,0 +1,19 @@
class TableName {
static const String placesFavorite = "placesFavorite";
static const String recentLocations = "recentLocations";
static const String carLocations = "carLocations";
static const String driverOrdersRefuse = "driverOrdersRefuse";
static const String rideLocation = "rideLocation";
static const String faceDetectTimes = "faceDetectTimes";
static const String behavior = "behavior";
static const String captainNotification = "captainNotification";
static const String applyRideFromOverLay = "applyRideFromOverLay";
}
class Driver {
static const String driverPass = 'MG6DEJZSczBT6Rx0jOlehQ==';
static const String payMobApikey = 'payMobApikey';
static const String initializationVector = 'initializationVector';
static const String keyOfApp = 'keyOfApp';
static const String FCM_PRIVATE_KEY = 'FCM_PRIVATE_KEY';
}

View File

@@ -0,0 +1,34 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:get/get.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
class AuthController extends GetxController {
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<User?> signInWithApple() async {
try {
final appleCredential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
final oAuthProvider = OAuthProvider('apple.com');
final credential = oAuthProvider.credential(
idToken: appleCredential.identityToken,
accessToken: appleCredential.authorizationCode,
);
UserCredential userCredential =
await _auth.signInWithCredential(credential);
return userCredential.user;
} catch (error) {
return null;
}
}
void signOut() async {
await _auth.signOut();
}
}

View File

@@ -0,0 +1,61 @@
import 'dart:convert';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:get/get.dart';
import '../../../constant/box_name.dart';
import '../../../constant/links.dart';
import '../../../main.dart';
import '../../../views/home/Captin/history/history_details_page.dart';
import '../../functions/crud.dart';
import '../../functions/encrypt_decrypt.dart';
class HistoryCaptainController extends GetxController {
bool isloading = false;
Map historyData = {};
Map historyDetailsData = {};
late String orderID;
getOrderId(String orderId) {
orderID = orderId;
update();
}
getHistory() async {
isloading = true;
var res = await CRUD().get(
link: AppLink.getDriverOrder,
payload: {'driver_id': box.read(BoxName.driverID)});
if (res != 'failure') {
historyData = jsonDecode(res);
isloading = false;
update();
} else {
Get.defaultDialog(
title: 'No ride yet'.tr,
middleText: '',
barrierDismissible: false,
confirm: MyElevatedButton(
title: 'Back'.tr,
onPressed: () {
Get.back();
Get.back();
}));
}
}
getHistoryDetails(String orderId) async {
isloading = true;
var res = await CRUD()
.get(link: AppLink.getRideOrderID, payload: {'id': (orderId)});
historyDetailsData = jsonDecode(res);
isloading = false;
update();
Get.to(() => HistoryDetailsPage());
}
@override
void onInit() {
getHistory();
super.onInit();
}
}

View File

@@ -0,0 +1,416 @@
import 'dart:convert';
import 'package:local_auth/local_auth.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/firebase/local_notification.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/controller/functions/encrypt_decrypt.dart';
import 'package:sefer_driver/controller/home/payment/captain_wallet_controller.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import 'package:flutter/material.dart';
import 'package:flutter_contacts/contact.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:get/get.dart';
import 'package:share_plus/share_plus.dart';
import '../../../main.dart';
import '../../../views/widgets/error_snakbar.dart';
import '../../functions/launch.dart';
import '../../notification/notification_captain_controller.dart';
class InviteController extends GetxController {
final TextEditingController invitePhoneController = TextEditingController();
List driverInvitationData = [];
List driverInvitationDataToPassengers = [];
String? couponCode;
String? driverCouponCode;
int selectedTab = 0;
PassengerStats passengerStats = PassengerStats();
void updateSelectedTab(int index) {
selectedTab = index;
update();
}
Future<void> shareCouponCode() async {
// TODO: Implement sharing functionality
// You can use share_plus package to share the coupon code
}
Future<void> shareDriverCode() async {
if (driverCouponCode != null) {
final String shareText = '''
Join Intaleq as a driver using my referral code!
Use code: $driverCouponCode
Download the Intaleq Driver app now and earn rewards!
''';
await Share.share(shareText);
}
}
Future<void> sharePassengerCode() async {
if (couponCode != null) {
final String shareText = '''
Get a discount on your first Intaleq ride!
Use my referral code: $couponCode
Download the Intaleq app now and enjoy your ride!
''';
await Share.share(shareText);
}
}
@override
void onInit() {
super.onInit();
// fetchDriverStats();
}
void fetchDriverStats() async {
try {
var response = await CRUD().get(link: AppLink.getInviteDriver, payload: {
"driverId": box.read(BoxName.driverID),
});
if (response != 'failure') {
var data = jsonDecode(response);
driverInvitationData = data['message'];
update();
}
} catch (e) {}
}
void fetchDriverStatsPassengers() async {
try {
var response = await CRUD()
.get(link: AppLink.getDriverInvitationToPassengers, payload: {
"driverId": box.read(BoxName.driverID),
});
if (response != 'failure') {
var data = jsonDecode(response);
driverInvitationDataToPassengers = data['message'];
update();
}
} catch (e) {}
}
void selectPhone(String phone) {
if (box.read(BoxName.countryCode) == 'Egypt') {
invitePhoneController.text = phone;
update();
Get.back();
}
}
Future<void> saveContactsToServer() async {
try {
// TODO: Implement the actual server upload logic here
// Simulating a server request
await Future.delayed(Duration(seconds: 2));
mySnackbarSuccess(
'${selectedContacts.length} contacts saved to server'.tr);
} catch (e) {
mySnackeBarError(
'An error occurred while saving contacts to server: $e'.tr);
}
}
List<Contact> contacts = <Contact>[];
List<Contact> selectedContacts = <Contact>[];
RxList<Map<String, dynamic>> contactMaps = <Map<String, dynamic>>[].obs;
Future<void> pickContacts() async {
try {
if (await FlutterContacts.requestPermission(readonly: true)) {
final List<Contact> fetchedContacts =
await FlutterContacts.getContacts(withProperties: true);
contacts = fetchedContacts;
// Convert contacts to a list of maps
contactMaps.value = fetchedContacts.map((contact) {
return {
'name': contact.displayName,
'phones':
contact.phones.map((phone) => phone.normalizedNumber).toList(),
'emails': contact.emails.map((email) => email.address).toList(),
};
}).toList();
update();
if (contacts.isEmpty) {
mySnackeBarError('Please add contacts to your phone.'.tr);
}
} else {
mySnackeBarError('Contact permission is required to pick contacts'.tr);
}
} catch (e) {
mySnackeBarError('An error occurred while picking contacts: $e'.tr);
}
}
void onSelectDriverInvitation(int index) async {
MyDialog().getDialog(
int.parse((driverInvitationData[index]['countOfInvitDriver'])) < 100
? '${'When'.tr} ${(driverInvitationData[index]['invitorName'])} ${"complete, you can claim your gift".tr} '
: 'You deserve the gift'.tr,
'${(driverInvitationData[index]['invitorName'])} ${(driverInvitationData[index]['countOfInvitDriver'])} / 100 ${'Trip'.tr}',
() async {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (int.parse((driverInvitationData[index]['countOfInvitDriver'])) <
100) {
Get.back();
} else
//claim your gift
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
if ((driverInvitationData[index]['isGiftToken']).toString() ==
'0') {
Get.back();
await CRUD().post(
link: AppLink.updateInviteDriver,
payload: {'id': (driverInvitationData[index]['id'])});
await Get.find<CaptainWalletController>().addDriverPayment(
'paymentMethod',
('500'),
'',
);
// add for invitor too
await Get.find<CaptainWalletController>()
.addDriverWalletToInvitor(
'paymentMethod',
(driverInvitationData[index]['driverInviterId']),
('500'),
);
// await Get.find<CaptainWalletController>()
// .addSeferWallet('giftInvitation', ('-1000'));
NotificationCaptainController().addNotificationCaptain(
driverInvitationData[index]['driverInviterId'].toString(),
"You have got a gift for invitation".tr,
'${"You have 500".tr} ${'LE'.tr}',
false);
NotificationController().showNotification(
"You have got a gift for invitation".tr,
'${"You have 500".tr} ${'LE'.tr}',
'tone1',
'');
} else {
Get.back();
MyDialog().getDialog("You have got a gift".tr,
"Share the app with another new driver".tr, () {
Get.back();
});
}
} else {
// Authentication failed, handle accordingly
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
}
},
);
}
void onSelectPassengerInvitation(int index) async {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
MyDialog().getDialog(
int.parse(driverInvitationDataToPassengers[index]['countOfInvitDriver']
.toString()) <
3
? '${'When'.tr} ${(driverInvitationDataToPassengers[index]['passengerName'].toString())} ${"complete, you can claim your gift".tr} '
: 'You deserve the gift'.tr,
'${(driverInvitationDataToPassengers[index]['passengerName'].toString())} ${driverInvitationDataToPassengers[index]['countOfInvitDriver']} / 3 ${'Trip'.tr}',
() async {
if (int.parse(driverInvitationDataToPassengers[index]
['countOfInvitDriver']
.toString()) <
3) {
Get.back();
} else if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
// Claim the gift if 100 trips are completed
if (driverInvitationDataToPassengers[index]['isGiftToken']
.toString() ==
'0') {
Get.back();
// Add wallet to the inviter
await Get.find<CaptainWalletController>()
.addDriverWallet('paymentMethod', '50', '50');
// add for invitor too
await Get.find<CaptainWalletController>()
.addDriverWalletToInvitor('paymentMethod',
driverInvitationData[index]['driverInviterId'], '50');
// Update invitation as claimed
await CRUD().post(
link: AppLink.updatePassengerGift,
payload: {'id': driverInvitationDataToPassengers[index]['id']},
);
// Notify the inviter
NotificationCaptainController().addNotificationCaptain(
driverInvitationDataToPassengers[index]['passengerInviterId']
.toString(),
"You have got a gift for invitation".tr,
'${"You have 50".tr} ${'LE'}',
false,
);
} else {
Get.back();
MyDialog().getDialog(
"You have got a gift".tr,
"Share the app with another new passenger".tr,
() {
Get.back();
},
);
}
} else {
// Authentication failed, handle accordingly
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
}
},
);
}
savePhoneToServer() async {
for (var i = 0; i < contactMaps.length; i++) {
var phones = contactMaps[i]['phones'];
if (phones != null && phones.isNotEmpty && phones[0].isNotEmpty) {
var res = await CRUD().post(link: AppLink.savePhones, payload: {
"name": contactMaps[i]['name'] ?? 'none',
"phones": phones[0] ?? 'none',
"phones2": phones.join(', ') ??
'none', // Convert List<String> to a comma-separated string
});
if (res != 'failure') {}
} else {}
}
}
String formatPhoneNumber(String input) {
// Remove any non-digit characters
String digitsOnly = input.replaceAll(RegExp(r'\D'), '');
// Ensure the number starts with the country code
if (digitsOnly.startsWith('20')) {
digitsOnly = digitsOnly.substring(1);
}
return digitsOnly;
}
void sendInvite() async {
if (invitePhoneController.text.isEmpty) {
mySnackeBarError('Please enter an phone address'.tr);
return;
}
// try {
String phoneNumber = formatPhoneNumber(invitePhoneController.text);
var response = await CRUD().post(link: AppLink.addInviteDriver, payload: {
"driverId": box.read(BoxName.driverID),
"inviterDriverPhone": '+2$phoneNumber'
});
if (response != 'failure') {
var d = (response);
mySnackbarSuccess('Invite sent successfully'.tr);
String message = '${'*Intaleq DRIVER CODE*'.tr}\n\n'
'${"Use this code in registration".tr}\n'
'${"To get a gift for both".tr}\n\n'
'${"The period of this code is 1 hour".tr}\n\n'
'${'before'.tr} *${d['message']['expirationTime'].toString()}*\n\n'
'_*${d['message']['inviteCode'].toString()}*_\n\n'
'${"Install our app:".tr}\n'
'*Android:* https://play.google.com/store/apps/details?id=com.sefer_driver\n\n\n'
'*iOS:* https://apps.apple.com/ae/app/sefer-driver/id6502189302';
launchCommunication('whatsapp', '+2$phoneNumber', message);
invitePhoneController.clear();
} else {
mySnackeBarError("Invite code already used".tr);
}
}
void sendInviteToPassenger() async {
if (invitePhoneController.text.isEmpty) {
mySnackeBarError('Please enter an phone address'.tr);
return;
}
// try {
String phoneNumber = formatPhoneNumber(invitePhoneController.text);
var response =
await CRUD().post(link: AppLink.addInvitationPassenger, payload: {
"driverId": box.read(BoxName.driverID),
"inviterPassengerPhone": '+2$phoneNumber'
});
if (response != 'failure') {
var d = jsonDecode(response);
mySnackbarSuccess('Invite sent successfully'.tr);
String message = '${'*Intaleq APP CODE*'.tr}\n\n'
'${"Use this code in registration".tr}\n'
'${"To get a gift for both".tr}\n\n'
'${"The period of this code is 1 hour".tr}\n\n'
'${'before'.tr} *${d['message']['expirationTime'].toString()}*\n\n'
'_*${d['message']['inviteCode'].toString()}*_\n\n'
'${"Install our app:".tr}\n'
'*Android:* https://play.google.com/store/apps/details?id=com.mobileapp.store.ride\n\n\n'
'*iOS:* https://apps.apple.com/us/app/sefer/id6458734951';
launchCommunication('whatsapp', '+2$phoneNumber', message);
invitePhoneController.clear();
} else {
mySnackeBarError(
"Invite code already used".tr,
);
}
}
}
class PassengerStats {
final int totalInvites;
final int activeUsers;
final double totalEarnings;
PassengerStats({
this.totalInvites = 0,
this.activeUsers = 0,
this.totalEarnings = 0.0,
});
}

View File

@@ -0,0 +1,608 @@
import 'dart:convert';
import 'dart:io';
import 'package:crypto/crypto.dart';
import 'dart:math';
import 'package:http/http.dart' as http;
import 'package:permission_handler/permission_handler.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:sefer_driver/controller/functions/location_background_controller.dart';
import 'package:sefer_driver/views/auth/captin/cards/sms_signup.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.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/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/home/Captin/home_captain/home_captin.dart';
import 'package:location/location.dart';
import '../../../constant/api_key.dart';
import '../../../constant/char_map.dart';
import '../../../constant/info.dart';
import '../../../constant/table_names.dart';
import '../../../print.dart';
import '../../../views/auth/captin/cards/syrian_card_a_i.dart';
import '../../../views/auth/captin/otp_page.dart';
import '../../../views/auth/captin/otp_token_page.dart';
import '../../firebase/firbase_messge.dart';
import '../../functions/encrypt_decrypt.dart';
import '../../functions/package_info.dart';
import '../../functions/secure_storage.dart';
import '../../functions/security_checks.dart';
class LoginDriverController extends GetxController {
final formKey = GlobalKey<FormState>();
TextEditingController emailController = TextEditingController();
TextEditingController phoneController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController passwordController2 = TextEditingController();
bool isAgreeTerms = false;
bool isGoogleDashOpen = false;
bool isGoogleLogin = false;
bool isloading = false;
late int isTest = 1;
final FlutterSecureStorage _storage = const FlutterSecureStorage();
final location = Location();
void changeAgreeTerm() {
isAgreeTerms = !isAgreeTerms;
update();
}
bool isPasswordHidden = true;
void togglePasswordVisibility() {
isPasswordHidden = !isPasswordHidden;
update([
'passwordVisibility'
]); // Use a unique ID to only update the password field
}
void changeGoogleDashOpen() {
isGoogleDashOpen = !isGoogleDashOpen;
update();
}
@override
void onInit() async {
box.write(BoxName.countryCode, 'Syria');
box.read(BoxName.isTest) == null ||
box.read(BoxName.isTest).toString() == '0'
? await getAppTester()
: null;
super.onInit();
}
getAppTester() async {
var res = await CRUD().get(
link: AppLink.getTesterApp,
payload: {'appPlatform': AppInformation.appName});
if (res != 'failure') {
var d = jsonDecode(res);
isTest = d['message'][0]['isTest'];
update();
} else {
return false;
}
}
updateAppTester(String appPlatform) async {
await CRUD().post(
link: AppLink.updateTesterApp, payload: {'appPlatform': appPlatform});
}
isPhoneVerified() async {
var res = await CRUD().post(link: AppLink.isPhoneVerified, payload: {
'phone_number': box.read(
BoxName.phoneDriver,
)
});
if (res != 'failure') {
Get.offAll(() => SyrianCardAI());
// isloading = false;
// update();
} else {
Get.offAll(() => PhoneNumberScreen());
}
}
void saveAgreementTerms() {
box.write(BoxName.agreeTerms, 'agreed');
update();
}
void saveCountryCode(String countryCode) {
box.write(BoxName.countryCode, countryCode);
update();
}
var dev = '';
getJwtWallet() async {
final random = Random();
if (random.nextBool()) {
await SecurityHelper.performSecurityChecks();
} else {
await SecurityChecks.isDeviceRootedFromNative(Get.context!);
}
String fingerPrint = await DeviceHelper.getDeviceFingerprint();
// print('fingerPrint: ${fingerPrint}');
dev = Platform.isAndroid ? 'android' : 'ios';
var payload = {
'id': box.read(BoxName.driverID),
'password': AK.passnpassenger,
'aud': '${AK.allowedWallet}$dev',
'fingerPrint': fingerPrint
};
var response1 = await http.post(
Uri.parse(AppLink.loginJwtWalletDriver),
body: payload,
);
// Log.print('response.request: ${response1.request}');
// Log.print('response.body: ${response1.body}');
// print(payload);
// Log.print(
// 'jsonDecode(response1.body)["jwt"]: ${jsonDecode(response1.body)['jwt']}');
await box.write(BoxName.hmac, jsonDecode(response1.body)['hmac']);
return jsonDecode(response1.body)['jwt'].toString();
}
String shortHash(String password) {
var bytes = utf8.encode(password);
var digest = sha256.convert(bytes);
return base64UrlEncode(digest.bytes);
}
getJWT() async {
dev = Platform.isAndroid ? 'android' : 'ios';
Log.print(
'box.read(BoxName.firstTimeLoadKey): ${box.read(BoxName.firstTimeLoadKey)}');
if (box.read(BoxName.firstTimeLoadKey).toString() != 'false') {
var payload = {
'id': box.read(BoxName.driverID) ?? AK.newId,
'password': AK.passnpassenger,
'aud': '${AK.allowed}$dev',
};
Log.print('payload: ${payload}');
var response0 = await http.post(
Uri.parse(AppLink.loginFirstTimeDriver),
body: payload,
);
Log.print('response0: ${response0.body}');
Log.print('request: ${response0.request}');
if (response0.statusCode == 200) {
final decodedResponse1 = jsonDecode(response0.body);
// Log.print('decodedResponse1: ${decodedResponse1}');
final jwt = decodedResponse1['jwt'];
box.write(BoxName.jwt, c(jwt));
// await box.write(BoxName.hmac, decodedResponse1['hmac']);
// await AppInitializer().getAIKey(Driver.payMobApikey);
// await AppInitializer().getAIKey(Driver.FCM_PRIVATE_KEY);
// await AppInitializer().getAIKey(Driver.initializationVector);
// await AppInitializer().getAIKey(Driver.keyOfApp);
// ✅ بعد التأكد أن كل المفاتيح موجودة
await EncryptionHelper.initialize();
await AppInitializer().getKey();
} else {}
} else {
await EncryptionHelper.initialize();
var payload = {
'id': box.read(BoxName.driverID),
'password': box.read(BoxName.emailDriver),
'aud': '${AK.allowed}$dev',
};
print(payload);
var response1 = await http.post(
Uri.parse(AppLink.loginJwtDriver),
body: payload,
);
print(response1.request);
print(response1.body);
if (response1.statusCode == 200) {
final decodedResponse1 = jsonDecode(response1.body);
// Log.print('decodedResponse1: ${decodedResponse1}');
final jwt = decodedResponse1['jwt'];
await box.write(BoxName.jwt, c(jwt));
await AppInitializer().getKey();
}
}
}
Future<void> getLocationPermission() async {
var status = await Permission.locationAlways.status;
if (!status.isGranted) {
await Permission.locationAlways.request();
}
update();
}
String generateUniqueIdFromEmail(String email) {
// Step 1: Extract the local part of the email
String localPart = email.split('@')[0];
// Step 2: Replace invalid characters (if any)
String cleanLocalPart = localPart.replaceAll(RegExp(r'[^a-zA-Z0-9]'), '');
// Step 3: Ensure it does not exceed 24 characters
if (cleanLocalPart.length > 24) {
cleanLocalPart = cleanLocalPart.substring(0, 24);
}
// Step 4: Generate a random suffix if needed
String suffix = generateRandomSuffix(24 - cleanLocalPart.length);
return cleanLocalPart + suffix;
}
String generateRandomSuffix(int length) {
const String chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
Random random = Random();
return List.generate(length, (index) => chars[random.nextInt(chars.length)])
.join('');
}
loginWithGoogleCredential(String driverID, email) async {
isloading = true;
update();
await SecurityHelper.performSecurityChecks();
Log.print('(BoxName.emailDriver): ${box.read(BoxName.emailDriver)}');
var res = await CRUD().get(link: AppLink.loginFromGoogleCaptin, payload: {
'email': email ?? 'yet',
'id': driverID,
});
// print('res is $res');
if (res == 'failure') {
await isPhoneVerified();
// Get.snackbar('Failure', '', backgroundColor: Colors.red);
} else {
var jsonDecoeded = jsonDecode(res);
var d = jsonDecoeded['data'][0];
if (jsonDecoeded.isNotEmpty) {
if (jsonDecoeded['status'] == 'success' &&
d['is_verified'].toString() == '1') {
box.write(BoxName.emailDriver, d['email']);
box.write(BoxName.firstTimeLoadKey, 'false');
box.write(BoxName.driverID, (d['id']));
box.write(BoxName.isTest, '1');
box.write(BoxName.gender, (d['gender']));
box.write(BoxName.phoneVerified, d['is_verified'].toString());
box.write(BoxName.phoneDriver, (d['phone']));
box.write(BoxName.is_claimed, d['is_claimed']);
box.write(BoxName.isInstall, d['isInstall']);
// box.write(
// BoxName.isGiftToken, d['isGiftToken']);
box.write(BoxName.nameArabic, (d['name_arabic']));
box.write(BoxName.carYear, d['year']);
box.write(BoxName.bankCodeDriver, (d['bankCode']));
box.write(BoxName.accountBankNumberDriver, (d['accountBank']));
box.write(
BoxName.nameDriver,
'${(d['first_name'])}'
' ${(d['last_name'])}');
if (((d['model']).toString().contains('دراجه') ||
d['make'].toString().contains('دراجه '))) {
if ((d['gender']).toString() == 'Male') {
box.write(BoxName.carTypeOfDriver, 'Scooter');
} else {
box.write(BoxName.carTypeOfDriver, 'Pink Bike');
}
} else if (int.parse(d['year'].toString()) > 2016) {
if (d['gender'].toString() != 'Male') {
box.write(BoxName.carTypeOfDriver, 'Lady');
} else {
box.write(BoxName.carTypeOfDriver, 'Comfort');
}
} else if (int.parse(d['year'].toString()) > 2002 &&
int.parse(d['year'].toString()) < 2016) {
box.write(BoxName.carTypeOfDriver, 'Speed');
} else if (int.parse(d['year'].toString()) < 2002) {
box.write(BoxName.carTypeOfDriver, 'Awfar Car');
}
updateAppTester(AppInformation.appName);
var token = await CRUD().get(
link: AppLink.getDriverToken,
payload: {'captain_id': (box.read(BoxName.driverID)).toString()});
String fingerPrint = await DeviceHelper.getDeviceFingerprint();
await storage.write(
key: BoxName.fingerPrint, value: fingerPrint.toString());
print(jsonDecode(token)['data'][0]['token'].toString());
print(box.read(BoxName.tokenDriver).toString());
if (email == '962798583052@intaleqapp.com') {
} else {
if (token != 'failure') {
if ((jsonDecode(token)['data'][0]['token'].toString()) !=
box.read(BoxName.tokenDriver).toString()) {
await Get.defaultDialog(
title: 'Device Change Detected'.tr,
middleText: 'Please verify your identity'.tr,
textConfirm: 'Verify'.tr,
confirmTextColor: Colors.white,
onConfirm: () {
// Get.back();
// انتقل لصفحة OTP الجديدة
Get.to(
() => OtpVerificationPage(
phone: d['phone'].toString(),
deviceToken: fingerPrint.toString(),
token: token.toString(),
ptoken:
jsonDecode(token)['data'][0]['token'].toString(),
),
);
},
);
}
}
}
Get.off(() => HomeCaptain());
} else {
Get.offAll(() => PhoneNumberScreen());
isloading = false;
update();
}
} else {
mySnackbarSuccess('');
isloading = false;
update();
}
}
}
logintest(String driverID, email) async {
isloading = true;
update();
await SecurityHelper.performSecurityChecks();
Log.print('(BoxName.emailDriver): ${box.read(BoxName.emailDriver)}');
var res = await CRUD().get(link: AppLink.loginFromGoogleCaptin, payload: {
'email': email ?? 'yet',
'id': driverID,
});
// print('res is $res');
if (res == 'failure') {
await isPhoneVerified();
// Get.snackbar('Failure', '', backgroundColor: Colors.red);
} else {
var jsonDecoeded = jsonDecode(res);
var d = jsonDecoeded['data'][0];
if (jsonDecoeded.isNotEmpty) {
if (jsonDecoeded['status'] == 'success' &&
d['is_verified'].toString() == '1') {
box.write(BoxName.emailDriver, d['email']);
box.write(BoxName.firstTimeLoadKey, 'false');
box.write(BoxName.driverID, (d['id']));
box.write(BoxName.isTest, '1');
box.write(BoxName.gender, (d['gender']));
box.write(BoxName.phoneVerified, d['is_verified'].toString());
box.write(BoxName.phoneDriver, (d['phone']));
box.write(BoxName.is_claimed, d['is_claimed']);
box.write(BoxName.isInstall, d['isInstall']);
// box.write(
// BoxName.isGiftToken, d['isGiftToken']);
box.write(BoxName.nameArabic, (d['name_arabic']));
box.write(BoxName.carYear, d['year']);
box.write(BoxName.bankCodeDriver, (d['bankCode']));
box.write(BoxName.accountBankNumberDriver, (d['accountBank']));
box.write(
BoxName.nameDriver,
'${(d['first_name'])}'
' ${(d['last_name'])}');
if (((d['model']).toString().contains('دراجه') ||
d['make'].toString().contains('دراجه '))) {
if ((d['gender']).toString() == 'Male') {
box.write(BoxName.carTypeOfDriver, 'Scooter');
} else {
box.write(BoxName.carTypeOfDriver, 'Pink Bike');
}
} else if (int.parse(d['year'].toString()) > 2016) {
if (d['gender'].toString() != 'Male') {
box.write(BoxName.carTypeOfDriver, 'Lady');
} else {
box.write(BoxName.carTypeOfDriver, 'Comfort');
}
} else if (int.parse(d['year'].toString()) > 2002 &&
int.parse(d['year'].toString()) < 2016) {
box.write(BoxName.carTypeOfDriver, 'Speed');
} else if (int.parse(d['year'].toString()) < 2002) {
box.write(BoxName.carTypeOfDriver, 'Awfar Car');
}
updateAppTester(AppInformation.appName);
var token = await CRUD().get(
link: AppLink.getDriverToken,
payload: {'captain_id': (box.read(BoxName.driverID)).toString()});
String fingerPrint = await DeviceHelper.getDeviceFingerprint();
await storage.write(
key: BoxName.fingerPrint, value: fingerPrint.toString());
Get.off(() => HomeCaptain());
} else {
Get.offAll(() => PhoneNumberScreen());
isloading = false;
update();
}
} else {
mySnackbarSuccess('');
isloading = false;
update();
}
}
}
loginUsingCredentialsWithoutGoogle(String password, email) async {
isloading = true;
isGoogleLogin = true;
update();
var res = await CRUD()
.get(link: AppLink.loginUsingCredentialsWithoutGoogle, payload: {
'email': (email),
'password': password,
});
box.write(BoxName.emailDriver, (email).toString());
// print(res);
if (res == 'failure') {
//Failure
if (box.read(BoxName.phoneVerified).toString() == '1') {
Get.offAll(() => SyrianCardAI());
} else {
Get.offAll(() => SmsSignupEgypt());
}
isloading = false;
update();
} else {
var jsonDecoeded = jsonDecode(res);
var d = jsonDecoeded['data'][0];
if (jsonDecoeded.isNotEmpty) {
if (jsonDecoeded['status'] == 'success' &&
d['is_verified'].toString() == '1') {
box.write(BoxName.emailDriver, (d['email']));
box.write(BoxName.driverID, (d['id']));
box.write(BoxName.isTest, '1');
box.write(BoxName.gender, (d['gender']));
box.write(BoxName.phoneVerified, d['is_verified'].toString());
box.write(BoxName.phoneDriver, (d['phone']));
box.write(BoxName.nameArabic, (d['name_arabic']));
box.write(BoxName.bankCodeDriver, (d['bankCode']));
box.write(BoxName.accountBankNumberDriver, d['accountBank']);
box.write(
BoxName.nameDriver,
'${(d['first_name'])}'
' ${(d['last_name'])}');
if ((d['model'].toString().contains('دراجه') ||
d['make'].toString().contains('دراجه '))) {
if ((d['gender']).toString() == 'Male') {
box.write(BoxName.carTypeOfDriver, 'Scooter');
} else {
box.write(BoxName.carTypeOfDriver, 'Pink Bike');
}
} else if (int.parse(d['year'].toString()) > 2017) {
if ((d['gender']).toString() != 'Male') {
box.write(BoxName.carTypeOfDriver, 'Lady');
} else {
box.write(BoxName.carTypeOfDriver, 'Comfort');
}
} else if (int.parse(d['year'].toString()) > 2002 &&
int.parse(d['year'].toString()) < 2017) {
box.write(BoxName.carTypeOfDriver, 'Speed');
} else if (int.parse(d['year'].toString()) < 2002) {
box.write(BoxName.carTypeOfDriver, 'Awfar Car');
}
updateAppTester(AppInformation.appName);
var fingerPrint = DeviceHelper.getDeviceFingerprint().toString();
await storage.write(key: BoxName.fingerPrint, value: fingerPrint);
var token = await CRUD().get(
link: AppLink.getDriverToken,
payload: {'captain_id': box.read(BoxName.driverID).toString()});
if (token != 'failure') {
if ((jsonDecode(token)['data'][0]['token']) !=
(box.read(BoxName.tokenDriver))) {
Get.put(FirebaseMessagesController()).sendNotificationToDriverMAP(
'token change'.tr,
'change device'.tr,
(jsonDecode(token)['data'][0]['token']).toString(),
[],
'ding.wav');
Get.defaultDialog(
title: 'you will use this device?'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () async {
await CRUD()
.post(link: AppLink.addTokensDriver, payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString(),
'fingerPrint': (fingerPrint).toString()
});
await CRUD().post(
link:
"${AppLink.seferAlexandriaServer}/ride/firebase/addDriver.php",
payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id':
box.read(BoxName.driverID).toString(),
'fingerPrint': (fingerPrint).toString()
});
await CRUD().post(
link:
"${AppLink.seferGizaServer}/ride/firebase/addDriver.php",
payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id':
box.read(BoxName.driverID).toString(),
'fingerPrint': (fingerPrint).toString()
});
Get.back();
}));
}
}
Get.off(() => HomeCaptain());
// Get.off(() => LoginCaptin());
} else {
Get.offAll(() => SmsSignupEgypt());
isloading = false;
update();
}
} else {
mySnackeBarError('');
isloading = false;
update();
}
}
}
void loginByBoxData() async {
Get.to(() => HomeCaptain());
await CRUD().post(link: AppLink.addTokensDriver, payload: {
'token': box.read(BoxName.tokenDriver).toString(),
'captain_id': box.read(BoxName.driverID).toString()
});
CRUD().post(
link: "${AppLink.seferAlexandriaServer}/ride/firebase/addDriver.php",
payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString()
});
CRUD().post(
link: "${AppLink.seferGizaServer}/ride/firebase/addDriver.php",
payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString()
});
}
}

View File

@@ -0,0 +1,93 @@
import 'dart:io';
import 'package:get/get.dart';
// import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/controller/functions/llama_ai.dart';
// class CarRegistrationRecognizerController extends GetxController {
// @override
// void onInit() {
// // scanText();
// super.onInit();
// }
// // The ImagePicker instance
// final ImagePicker _imagePicker = ImagePicker();
// // The GoogleMlKit TextRecognizer instance
// // final TextRecognizer _textRecognizer = TextRecognizer();
// // The scanned text
// String? scannedText;
// String? jsonOutput;
// final List<Map<String, dynamic>> lines = [];
// Map extracted = {};
// XFile? image;
// CroppedFile? croppedFile;
// // Picks an image from the camera or gallery and extracts the text
// final List<Map<String, dynamic>> extractedTextWithCoordinates = [];
// Future<void> scanText() async {
// // Pick an image from the camera or gallery
// image = await _imagePicker.pickImage(source: ImageSource.gallery);
// update();
// // If no image was picked, return
// if (image == null) {
// return;
// }
// // Crop the image
// croppedFile = await ImageCropper().cropImage(
// sourcePath: image!.path,
// //
// uiSettings: [
// AndroidUiSettings(
// toolbarTitle: 'Cropper'.tr,
// toolbarColor: AppColor.blueColor,
// toolbarWidgetColor: AppColor.yellowColor,
// initAspectRatio: CropAspectRatioPreset.original,
// lockAspectRatio: false),
// IOSUiSettings(
// title: 'Cropper'.tr,
// ),
// ],
// );
// // If no cropped image was obtained, return
// if (croppedFile == null) {
// return;
// }
// // Convert the cropped file to an InputImage object
// final InputImage inputImage = InputImage.fromFile(File(croppedFile!.path));
// // Recognize the text in the image
// final RecognizedText recognizedText =
// await _textRecognizer.processImage(inputImage);
// scannedText = recognizedText.text;
// // Extract the scanned text line by line
// final List<Map<String, dynamic>> lines = [];
// for (var i = 0; i < recognizedText.blocks.length; i++) {
// lines.add({
// i.toString(): recognizedText.blocks[i].text,
// });
// }
// String result = lines.map((map) => map.values.first.toString()).join(' ');
// if (result.length > 2200) {
// result = result.substring(0, 2200);
// }
// Map result2 = await LlamaAi().getCarRegistrationData(result,
// 'vin,make,made,year,expiration_date,color,owner,registration_date'); //
// // Assign the result to the extracted variable
// extracted = result2;
// update();
// }
// }

View File

@@ -0,0 +1,108 @@
import 'dart:async';
import 'package:get/get.dart';
import 'package:sefer_driver/views/home/Captin/home_captain/home_captin.dart';
import '../../../constant/box_name.dart';
import '../../../constant/links.dart';
import '../../../main.dart';
import '../../firebase/firbase_messge.dart';
import '../../functions/crud.dart';
class OtpVerificationController extends GetxController {
final String phone;
final String deviceToken;
final String token;
final otpCode = ''.obs;
final isLoading = false.obs;
final isVerifying = false.obs;
var canResend = false.obs;
var countdown = 120.obs;
Timer? _timer;
OtpVerificationController({
required this.phone,
required this.deviceToken,
required this.token,
});
@override
void onInit() {
super.onInit();
sendOtp(); // ترسل تلقائيًا عند فتح الصفحة
startCountdown();
}
void startCountdown() {
canResend.value = false;
countdown.value = 120;
_timer?.cancel();
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (countdown.value > 0) {
countdown.value--;
} else {
canResend.value = true;
timer.cancel();
}
});
}
Future<void> sendOtp() async {
isLoading.value = true;
try {
final response = await CRUD().post(
link:
'${AppLink.server}/auth/token_passenger/driver/send_otp_driver.php',
payload: {
'receiver': phone,
// 'device_token': deviceToken,
},
);
if (response != 'failure') {
// بإمكانك عرض رسالة نجاح هنا
} else {
// Get.snackbar('Error', 'Failed to send OTP');
}
} catch (e) {
Get.snackbar('Error', e.toString());
} finally {
isLoading.value = false;
}
}
Future<void> verifyOtp(String ptoken) async {
isVerifying.value = true;
var finger = await storage.read(key: BoxName.fingerPrint);
try {
final response = await CRUD().post(
link:
'${AppLink.server}/auth/token_passenger/driver/verify_otp_driver/.php',
payload: {
'phone_number': phone,
'otp': otpCode.value,
'token': box.read(BoxName.tokenDriver).toString(),
'fingerPrint': finger.toString(),
},
);
if (response != 'failure' && response['status'] == 'success') {
Get.back(); // توجه إلى الصفحة التالية
Get.put(FirebaseMessagesController()).sendNotificationToDriverMAP(
'token change',
'change device'.tr,
ptoken.toString(),
[],
'cancel.wav',
);
Get.offAll(() => HomeCaptain());
} else {
Get.snackbar('Verification Failed', 'OTP is incorrect or expired');
}
} catch (e) {
Get.snackbar('Error', e.toString());
} finally {
isVerifying.value = false;
}
}
}

View File

@@ -0,0 +1,142 @@
import 'package:get/get.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/views/auth/captin/cards/syrian_card_a_i.dart';
import 'package:sefer_driver/views/home/on_boarding_page.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import '../../../constant/box_name.dart';
import '../../../constant/links.dart';
import '../../../main.dart';
import '../../../print.dart';
import '../../../views/auth/captin/otp_page.dart';
// --- Helper Class for Phone Authentication ---
class PhoneAuthHelper {
// Define your server URLs
static final String _baseUrl = '${AppLink.server}/auth/syria/driver/';
static final String _sendOtpUrl = '${_baseUrl}sendWhatsAppDriver.php';
static final String _verifyOtpUrl = '${_baseUrl}verifyOtp.php';
static final String _registerUrl = '${_baseUrl}register_driver.php';
/// Sends an OTP to the provided phone number.
static Future<bool> sendOtp(String phoneNumber) async {
try {
final response = await CRUD().post(
link: _sendOtpUrl,
payload: {'receiver': phoneNumber},
);
Log.print('response: ${response}');
if (response != 'failure') {
final data = (response);
// if (data['status'] == 'success') {
mySnackbarSuccess('An OTP has been sent to your WhatsApp number.'.tr);
return true;
// } else {
// mySnackeBarError(data['message'] ?? 'Failed to send OTP.');
// return false;
// }
} else {
mySnackeBarError('Server error. Please try again.'.tr);
return false;
}
} catch (e) {
Log.print('e: ${e}');
// mySnackeBarError('An error occurred: $e');
return false;
}
}
/// Verifies the OTP and logs the user in.
static Future<void> verifyOtp(String phoneNumber, String otp) async {
try {
final response = await CRUD().post(
link: _verifyOtpUrl,
payload: {'phone_number': phoneNumber, 'otp': otp},
);
if (response != 'failure') {
final data = response;
if (data['status'] == 'success') {
final isRegistered = data['message']['isRegistered'] ?? false;
Log.print('isRegistered: ${isRegistered}');
box.write(BoxName.phoneVerified, true);
box.write(BoxName.phoneDriver, phoneNumber);
box.write(BoxName.driverID, data['message']['driverID']);
Log.print('BoxName.driverID: ${box.read(BoxName.driverID)}');
if (isRegistered) {
// ✅ السائق مسجل مسبقًا - سجل دخوله واذهب إلى الصفحة الرئيسية
final driver = data['message']['driver'];
// mySnackbarSuccess('Welcome back, ${driver['first_name']}!');
Log.print('Welcome: }');
// حفظ بيانات السائق إذا أردت:
box.write(BoxName.driverID, driver['id']);
box.write(BoxName.emailDriver, driver['email']);
await Get.find<LoginDriverController>().loginWithGoogleCredential(
driver['id'].toString(), driver['email'].toString());
} else {
// ✅ رقم الهاتف تم التحقق منه لكن السائق غير مسجل
// mySnackbarSuccess('Phone verified. Please complete registration.');
Get.to(() => SyrianCardAI());
}
} else {
mySnackeBarError(data['message'] ?? 'Verification failed.');
}
} else {
mySnackeBarError('Server error. Please try again.');
}
} catch (e) {
mySnackeBarError('An error occurred: $e');
Log.print('e: ${e}');
}
}
static Future<void> registerUser({
required String phoneNumber,
required String firstName,
required String lastName,
String? email,
}) async {
try {
final response = await CRUD().post(
link: _registerUrl,
payload: {
'phone_number': phoneNumber,
'first_name': firstName,
'last_name': lastName,
'email': email ?? '', // Send empty string if null
},
);
final data = (response);
if (data != 'failure') {
// Registration successful, log user in
await _handleSuccessfulLogin(data['message']);
} else {
mySnackeBarError(
"User with this phone number or email already exists.".tr);
}
} catch (e) {
Log.print('e: ${e}');
mySnackeBarError('An error occurred: $e');
}
}
static Future<void> _handleSuccessfulLogin(
Map<String, dynamic> userData) async {
mySnackbarSuccess('Welcome, ${userData['first_name']}!');
// Save user data to local storage (Hive box) using new keys
box.write(BoxName.passengerID, userData['id']);
box.write(BoxName.nameDriver, userData['first_name']);
box.write(BoxName.lastNameDriver, userData['last_name']);
box.write(BoxName.emailDriver, userData['email']);
box.write(BoxName.phoneDriver, userData['phone']);
Get.offAll(() => OnBoardingPage()); // Navigate to home
}
}

View File

@@ -0,0 +1,420 @@
import 'dart:convert';
import 'dart:math';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/views/auth/captin/cards/syrian_card_a_i.dart';
import 'package:sefer_driver/views/auth/captin/register_captin.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.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/controller/functions/crud.dart';
import 'package:sefer_driver/controller/functions/ocr_controller.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/auth/captin/login_captin.dart';
import 'package:sefer_driver/views/auth/captin/verify_email_captain.dart';
import '../../../constant/colors.dart';
import '../../../views/auth/captin/ai_page.dart';
import '../../../views/auth/captin/car_license_page.dart';
import '../../../views/home/Captin/home_captain/home_captin.dart';
import '../../functions/encrypt_decrypt.dart';
import '../../functions/sms_egypt_controller.dart';
class RegisterCaptainController extends GetxController {
final formKey = GlobalKey<FormState>();
final formKey3 = GlobalKey<FormState>();
TextEditingController emailController = TextEditingController();
TextEditingController phoneController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController verifyCode = TextEditingController();
String birthDate = 'Birth Date'.tr;
String gender = 'Male'.tr;
bool isLoading = false;
bool isSent = false;
late String name;
late String licenseClass;
late String documentNo;
late String address;
late String height;
late String postalCode;
late String sex;
late String stateCode;
late String expireDate;
late String dob;
getBirthDate() {
Get.defaultDialog(
title: 'Select Date'.tr,
content: SizedBox(
width: 300,
child: CalendarDatePicker(
initialDate: DateTime.now().subtract(const Duration(days: 18 * 365)),
firstDate: DateTime.parse('1940-06-01'),
lastDate: DateTime.now().subtract(const Duration(days: 18 * 365)),
onDateChanged: (date) {
// Get the selected date and convert it to a DateTime object
DateTime dateTime = date;
// Call the getOrders() function from the controller
birthDate = dateTime.toString().split(' ')[0];
update();
Get.back();
},
// onDateChanged: (DateTime value) {},
),
),
);
}
@override
void onInit() {
// Get.put(SmsEgyptController());
super.onInit();
}
void changeGender(String value) {
gender = value;
update();
}
bool isValidEgyptianPhoneNumber(String phoneNumber) {
// Remove any non-digit characters (spaces, dashes, etc.)
phoneNumber = phoneNumber.replaceAll(RegExp(r'\D+'), '');
// Check if the phone number has exactly 11 digits
if (phoneNumber.length != 11) {
return false;
}
// Check if the phone number starts with 010, 011, 012, or 015
RegExp validPrefixes = RegExp(r'^01[0125]\d{8}$');
return validPrefixes.hasMatch(phoneNumber);
}
sendOtpMessage() async {
SmsEgyptController smsEgyptController = Get.put(SmsEgyptController());
isLoading = true;
update();
isLoading = true;
update();
if (formKey3.currentState!.validate()) {
if (box.read(BoxName.countryCode) == 'Egypt') {
if (isValidEgyptianPhoneNumber(phoneController.text)) {
var responseCheker = await CRUD()
.post(link: AppLink.checkPhoneNumberISVerfiedDriver, payload: {
'phone_number': ('+2${phoneController.text}'),
});
if (responseCheker != 'failure') {
var d = jsonDecode(responseCheker);
if (d['message'][0]['is_verified'].toString() == '1') {
Get.snackbar('Phone number is verified before'.tr, '',
backgroundColor: AppColor.greenColor);
box.write(BoxName.phoneVerified, '1');
box.write(BoxName.phone, ('+2${phoneController.text}'));
await Get.put(LoginDriverController()).loginWithGoogleCredential(
box.read(BoxName.driverID).toString(),
(box.read(BoxName.emailDriver).toString()),
);
} else {
await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
'phone_number': ('+2${phoneController.text}'),
"driverId": box.read(BoxName.driverID),
"email": (box.read(BoxName.emailDriver)),
});
isSent = true;
isLoading = false;
update();
}
} else {
await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: {
'phone_number': ('+2${phoneController.text}'),
"driverId": box.read(BoxName.driverID),
"email": box.read(BoxName.emailDriver),
});
isSent = true;
isLoading = false;
update();
}
} else {
mySnackeBarError(
'Phone Number wrong'.tr,
);
}
}
}
isLoading = false;
update();
}
DateTime? lastOtpSentTime; // Store the last OTP sent time
int otpResendInterval = 300; // 5 minutes in seconds
// Main function to handle OTP sending
// sendOtpMessage() async {
// if (_isOtpResendAllowed()) {
// isLoading = true;
// update();
// if (formKey3.currentState!.validate()) {
// String countryCode = box.read(BoxName.countryCode);
// String phoneNumber = phoneController.text;
// if (countryCode == 'Egypt' && isValidEgyptianPhoneNumber(phoneNumber)) {
// await _checkAndSendOtp(phoneNumber);
// } else {
// _showErrorMessage('Phone Number is not Egypt phone '.tr);
// }
// }
// isLoading = false;
// update();
// } else {
// _showCooldownMessage();
// }
// }
// Check if the resend OTP request is allowed (5 minutes cooldown)
// bool _isOtpResendAllowed() {
// if (lastOtpSentTime == null) return true;
// final int elapsedTime =
// DateTime.now().difference(lastOtpSentTime!).inSeconds;
// return elapsedTime >= otpResendInterval;
// }
// // Show message when user tries to resend OTP too soon
// void _showCooldownMessage() {
// int remainingTime = otpResendInterval -
// DateTime.now().difference(lastOtpSentTime!).inSeconds;
// Get.snackbar(
// 'Please wait ${remainingTime ~/ 60}:${(remainingTime % 60).toString().padLeft(2, '0')} minutes before requesting again',
// '',
// backgroundColor: AppColor.redColor,
// );
// }
// // Check if the phone number has been verified, and send OTP if not verified
// _checkAndSendOtp(String phoneNumber) async {
// var responseChecker = await CRUD().post(
// link: AppLink.checkPhoneNumberISVerfiedDriver,
// payload: {
// 'phone_number': '+2$phoneNumber',
// },
// );
// if (responseChecker != 'failure') {
// var responseData = jsonDecode(responseChecker);
// if (_isPhoneVerified(responseData)) {
// _handleAlreadyVerified();
// } else {
// await _sendOtpAndSms(phoneNumber);
// }
// } else {
// await _sendOtpAndSms(phoneNumber);
// }
// }
// Check if the phone number is already verified
bool _isPhoneVerified(dynamic responseData) {
return responseData['message'][0]['is_verified'].toString() == '1';
}
// Handle case where phone number is already verified
_handleAlreadyVerified() {
mySnackbarSuccess('Phone number is already verified'.tr);
box.write(BoxName.phoneVerified, '1');
box.write(BoxName.phone, ('+2${phoneController.text}'));
Get.put(LoginDriverController()).loginWithGoogleCredential(
box.read(BoxName.driverID).toString(),
box.read(BoxName.emailDriver).toString(),
);
}
// Send OTP and SMS
_sendOtpAndSms(String phoneNumber) async {
SmsEgyptController smsEgyptController = Get.put(SmsEgyptController());
int randomNumber = Random().nextInt(100000) + 1;
await CRUD().post(
link: AppLink.sendVerifyOtpMessage,
payload: {
'phone_number': ('+2$phoneNumber'),
'token_code': (randomNumber.toString()),
'driverId': box.read(BoxName.driverID),
'email': box.read(BoxName.emailDriver),
},
);
await smsEgyptController.sendSmsEgypt(phoneNumber);
lastOtpSentTime = DateTime.now(); // Update the last OTP sent time
isSent = true;
isLoading = false;
update();
}
verifySMSCode() async {
// var loginDriverController = Get.put(LoginDriverController());
if (formKey3.currentState!.validate()) {
var res = await CRUD().post(link: AppLink.verifyOtpDriver, payload: {
'phone_number': ('+2${phoneController.text}'),
'token_code': (verifyCode.text.toString()),
});
if (res != 'failure') {
// var dec = jsonDecode(res);
box.write(BoxName.phoneDriver, ('+2${phoneController.text}'));
box.write(BoxName.phoneVerified, '1');
// loginDriverController.isGoogleLogin == true
// ? await loginDriverController.loginUsingCredentialsWithoutGoogle(
// loginDriverController.passwordController.text.toString(),
// box.read(BoxName.emailDriver).toString(),
// )
// : await loginDriverController.loginUsingCredentials(
// box.read(BoxName.driverID).toString(),
// box.read(BoxName.emailDriver).toString(),
// );
Get.to(SyrianCardAI());
// } else {
// Get.snackbar('title', 'message');
// }
}
} else {
mySnackeBarError('you must insert token code '.tr);
}
}
sendVerifications() async {
var res = await CRUD().post(link: AppLink.verifyEmail, payload: {
'email': emailController.text.isEmpty
? (Get.find<LoginDriverController>().emailController.text.toString())
: (emailController.text),
'token': (verifyCode.text),
});
if (res != 'failure') {
if (Get.find<LoginDriverController>().emailController.text.toString() !=
'') {
Get.offAll(() => HomeCaptain());
} else {
// Get.to(() => CarLicensePage());
}
}
}
void nextToAIDetection() async {
//Todo dont forget this
if (formKey.currentState!.validate()) {
isLoading = true;
update();
Get.to(() => AiPage());
}
}
Map<String, dynamic> payloadLisence = {};
void getFromController() {
name = Get.find<ScanDocumentsByApi>().name;
licenseClass = Get.find<ScanDocumentsByApi>().licenseClass.toString();
documentNo = Get.find<ScanDocumentsByApi>().documentNo.toString();
address = Get.find<ScanDocumentsByApi>().address.toString();
height = Get.find<ScanDocumentsByApi>().height.toString();
postalCode = Get.find<ScanDocumentsByApi>().address.toString();
sex = Get.find<ScanDocumentsByApi>().sex.toString();
stateCode = Get.find<ScanDocumentsByApi>().postalCode.toString();
expireDate = Get.find<ScanDocumentsByApi>().expireDate.toString();
dob = Get.find<ScanDocumentsByApi>().dob.toString();
update();
}
Future addLisence() async {
getFromController();
var res = await CRUD().post(link: AppLink.addLicense, payload: {
'name': name,
'licenseClass': licenseClass,
'documentNo': documentNo,
'address': address,
'height': height,
'postalCode': postalCode,
'sex': sex,
'stateCode': stateCode,
'expireDate': expireDate,
'dateOfBirth': dob,
});
isLoading = false;
update();
if (jsonDecode(res)['status'] == 'success') {
// Get.to(() => AiPage()); //todo rplace this
}
}
void addRegisrationCarForDriver(String vin, make, model, year, color, owner,
expirationDate, registrationDate) async {
getFromController();
var res = await CRUD().post(link: AppLink.addRegisrationCar, payload: {
'vin': vin,
'make': make,
'model': model,
'year': year,
'expirationDate': expirationDate,
'color': color,
'owner': owner,
'registrationDate': registrationDate,
});
box.write(BoxName.vin, vin);
box.write(BoxName.make, make);
box.write(BoxName.model, model);
box.write(BoxName.year, year);
box.write(BoxName.expirationDate, expirationDate);
box.write(BoxName.color, color);
box.write(BoxName.owner, owner);
box.write(BoxName.registrationDate, registrationDate);
isLoading = false;
update();
if (jsonDecode(res)['status'] == 'success') {
Get.offAll(() => LoginCaptin()); //todo replace this
}
}
Future register() async {
getFromController();
if (formKey.currentState!.validate()) {
isLoading = true;
update();
var res = await CRUD().post(link: AppLink.signUpCaptin, payload: {
'first_name': name.split(' ')[1],
'last_name': name.split(' ')[0],
'email': emailController.text,
'phone': phoneController.text,
'password': passwordController.text,
'gender': sex,
'site': address,
'birthdate': dob,
});
isLoading = false;
update();
if (jsonDecode(res)['status'] == 'success') {
box.write(BoxName.driverID, jsonDecode(res)['message']);
box.write(BoxName.dobDriver, dob);
box.write(BoxName.sexDriver, sex);
box.write(BoxName.phoneDriver, phoneController.text);
box.write(BoxName.lastNameDriver, name.split(' ')[0]);
int randomNumber = Random().nextInt(100000) + 1;
await CRUD().post(link: AppLink.sendVerifyEmail, payload: {
'email': emailController.text,
'token': randomNumber.toString(),
});
Get.to(() => VerifyEmailCaptainPage());
}
}
}
}

View File

@@ -0,0 +1,30 @@
// import 'package:firebase_auth/firebase_auth.dart';
// import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
// class FacebookSignIn {
// Future<UserCredential?> signInWithFacebook() async {
// final LoginResult result = await FacebookAuth.instance.login();
// if (result.status == LoginStatus.success) {
// // Create a credential from the access token
// final OAuthCredential credential =
// FacebookAuthProvider.credential(result.accessToken!.tokenString);
// // Once signed in, return the UserCredential
// return await FirebaseAuth.instance.signInWithCredential(credential);
// }
// return null;
// }
// Future<void> signOut() async {
// try {
// await FacebookAuth.instance.logOut();
// print('Facebook Sign Out Successful');
// } catch (e) {
// print('Error during Facebook Sign Out: $e');
// }
// }
// Future<bool> isSignedIn() async {
// final accessToken = await FacebookAuth.instance.accessToken;
// return accessToken != null;
// }
// }

View File

@@ -0,0 +1,293 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/auth/captin/cards/sms_signup.dart';
import 'package:sefer_driver/views/home/on_boarding_page.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:get/get.dart';
import 'package:google_sign_in/google_sign_in.dart';
import '../../views/auth/captin/ai_page.dart';
import '../functions/add_error.dart';
import '../functions/encrypt_decrypt.dart';
class GoogleSignInHelper {
static final GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'profile',
],
);
// Method to handle Google Sign-In
static Future<GoogleSignInAccount?> signIn() async {
try {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser != null) {
await _handleSignUp(googleUser);
if (box.read(BoxName.countryCode) == 'Egypt') {
Get.to(() => SmsSignupEgypt());
} else if (box.read(BoxName.countryCode) == 'Jordan') {
Get.to(() => AiPage());
}
}
return googleUser;
} catch (error) {
return null;
}
}
Future<GoogleSignInAccount?> signInFromLogin() async {
try {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
if (googleUser != null) {
// Handle sign-up and store user information
await _handleSignUp(googleUser);
// Retrieve driverID and emailDriver with added validation
final driverID =
(box.read(BoxName.driverID)!.toString()) ?? 'Unknown ID';
final emailDriver =
(box.read(BoxName.emailDriver)!.toString()) ?? 'Unknown Email';
// Debug print statements
print('Driver ID: $driverID');
print('Driver Email: $emailDriver');
// Check if driverID is a valid numeric string
// if (driverID != 'Unknown ID' && int.tryParse(driverID) != null) {
await Get.find<LoginDriverController>()
.loginWithGoogleCredential(driverID, emailDriver);
// }
// else {
// print('Invalid driverID format: $driverID');
// Get.snackbar('Login Error', 'Invalid driver ID format.',
// backgroundColor: AppColor.redColor);
// }
}
return googleUser;
} catch (error) {
mySnackeBarError('$error');
addError(error.toString(), 'GoogleSignInAccount?> signInFromLogin()');
return null;
}
}
static Future<void> _handleSignUp(GoogleSignInAccount user) async {
// Store driver information
box.write(BoxName.driverID,
(user.id) ?? 'Unknown ID'); // Ensure there's a fallback value
box.write(BoxName.emailDriver, (user.email) ?? 'Unknown Email');
}
// Method to handle Google Sign-Out
static Future<void> signOut() async {
try {
await _googleSignIn.signOut();
await _handleSignOut();
} catch (error) {}
}
static Future<void> _handleSignOut() async {
// Clear stored driver information
box.remove(BoxName.driverID);
box.remove(BoxName.emailDriver);
box.remove(BoxName.lang);
box.remove(BoxName.nameDriver);
box.remove(BoxName.passengerID);
box.remove(BoxName.phoneDriver);
box.remove(BoxName.tokenFCM);
box.remove(BoxName.tokens);
box.remove(BoxName.carPlate);
box.remove(BoxName.lastNameDriver);
box.remove(BoxName.agreeTerms);
box.remove(BoxName.tokenDriver);
box.remove(BoxName.countryCode);
box.remove(BoxName.accountIdStripeConnect);
box.remove(BoxName.phoneVerified);
Get.offAll(OnBoardingPage());
// Perform any additional sign-out tasks or API calls here
// For example, you can notify your server about the user sign-out
}
// Method to get the current signed-in user
static GoogleSignInAccount? getCurrentUser() {
return _googleSignIn.currentUser;
}
}
// import 'dart:async';
// import 'dart:async';
// import 'dart:convert';
// import 'package:flutter/material.dart';
// import 'package:get/get.dart';
// import 'package:http/http.dart' as http;
// import 'package:sefer_driver/constant/box_name.dart';
// import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
// import 'package:sefer_driver/main.dart';
// import 'package:sefer_driver/views/auth/captin/ai_page.dart';
// import 'package:sefer_driver/views/auth/captin/cards/sms_signup.dart';
// import 'package:sefer_driver/views/home/on_boarding_page.dart';
// import 'package:sefer_driver/views/widgets/error_snakbar.dart';
// import 'package:url_launcher/url_launcher.dart';
// import '../functions/add_error.dart';
// /// Helper class to manage Google Sign-In via an external browser and polling.
// class GoogleSignInHelper {
// // URLs for your server endpoints
// static const String _startLoginUrl =
// 'https://api.tripz-egypt.com/tripz/auth/google_auth/login.php';
// static const String _checkStatusUrl =
// 'https://api.tripz-egypt.com/tripz/auth/google_auth/check_status.php';
// static Future<void> _initiateSignIn(
// Function(Map<String, dynamic> userData) onSignInSuccess) async {
// try {
// // Show a loading dialog to the user
// Get.dialog(
// const Center(
// child: Material(
// color: Colors.transparent,
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// CircularProgressIndicator(),
// SizedBox(height: 16),
// Text(
// "Waiting for browser sign-in...",
// style: TextStyle(color: Colors.white, fontSize: 16),
// ),
// ],
// ),
// ),
// ),
// barrierDismissible: false,
// );
// // 1. Get the auth URL and login token from the server
// final startResponse = await http.get(Uri.parse(_startLoginUrl));
// if (startResponse.statusCode != 200) {
// throw Exception('Failed to start login process.');
// }
// final startData = jsonDecode(startResponse.body);
// final String authUrl = startData['authUrl'];
// final String loginToken = startData['loginToken'];
// // 2. Launch the URL in an external browser
// if (!await launchUrl(Uri.parse(authUrl),
// mode: LaunchMode.externalApplication)) {
// throw Exception('Could not launch browser.');
// }
// // 3. Start polling the server for status
// await _startPolling(loginToken, onSignInSuccess);
// } catch (e) {
// addError(e.toString(), '_initiateSignIn');
// mySnackeBarError('Sign-in failed: ${e.toString()}');
// // Close the loading dialog on error
// if (Get.isDialogOpen ?? false) {
// Get.back();
// }
// }
// }
// static Future<void> _startPolling(String loginToken,
// Function(Map<String, dynamic> userData) onSignInSuccess) async {
// Timer? poller;
// const int maxAttempts = 30; // Poll for 60 seconds (30 attempts * 2s)
// int attempts = 0;
// poller = Timer.periodic(const Duration(seconds: 2), (timer) async {
// if (attempts >= maxAttempts) {
// timer.cancel();
// if (Get.isDialogOpen ?? false) Get.back();
// mySnackeBarError('Sign-in timed out. Please try again.');
// return;
// }
// attempts++;
// try {
// final statusResponse = await http.post(
// Uri.parse(_checkStatusUrl),
// headers: {'Content-Type': 'application/json'},
// body: jsonEncode({'loginToken': loginToken}),
// );
// if (statusResponse.statusCode == 200) {
// final statusData = jsonDecode(statusResponse.body);
// if (statusData['status'] == 'success') {
// timer.cancel();
// if (Get.isDialogOpen ?? false) Get.back();
// // Success!
// onSignInSuccess(statusData['userData']);
// }
// // If status is 'pending', do nothing and wait for the next poll.
// }
// } catch (e) {
// // Handle polling errors silently or log them
// debugPrint("Polling error: $e");
// }
// });
// }
// /// Triggers the sign-in process for a new user.
// static Future<void> signIn() async {
// await _initiateSignIn((userData) async {
// debugPrint('Sign-in success data: $userData');
// await _handleSignUp(userData);
// if (box.read(BoxName.countryCode) == 'Egypt') {
// Get.offAll(() => SmsSignupEgypt());
// } else if (box.read(BoxName.countryCode) == 'Jordan') {
// Get.offAll(() => AiPage());
// }
// });
// }
// /// Triggers the sign-in process for an existing user.
// static Future<void> signInFromLogin() async {
// await _initiateSignIn((userData) async {
// debugPrint('Sign-in from login success data: $userData');
// await _handleSignUp(userData);
// final driverID = userData['id']?.toString() ?? 'Unknown ID';
// final emailDriver = userData['email']?.toString() ?? 'Unknown Email';
// debugPrint('Driver ID from server: $driverID');
// debugPrint('Driver Email from server: $emailDriver');
// await Get.find<LoginDriverController>()
// .loginWithGoogleCredential(driverID, emailDriver);
// });
// }
// /// Stores user information received from the server.
// static Future<void> _handleSignUp(Map<String, dynamic> userData) async {
// box.write(BoxName.driverID, userData['id'] ?? 'Unknown ID');
// box.write(BoxName.emailDriver, userData['email'] ?? 'Unknown Email');
// }
// /// Clears local data.
// static Future<void> signOut() async {
// box.remove(BoxName.driverID);
// box.remove(BoxName.emailDriver);
// box.remove(BoxName.lang);
// box.remove(BoxName.nameDriver);
// box.remove(BoxName.passengerID);
// box.remove(BoxName.phoneDriver);
// box.remove(BoxName.tokenFCM);
// box.remove(BoxName.tokens);
// box.remove(BoxName.carPlate);
// box.remove(BoxName.lastNameDriver);
// box.remove(BoxName.agreeTerms);
// box.remove(BoxName.tokenDriver);
// box.remove(BoxName.countryCode);
// box.remove(BoxName.accountIdStripeConnect);
// box.remove(BoxName.phoneVerified);
// Get.offAll(() => OnBoardingPage());
// }
// }

View File

@@ -0,0 +1,117 @@
import 'dart:convert';
import 'dart:math';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.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/controller/functions/crud.dart';
import 'package:sefer_driver/controller/functions/secure_storage.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/auth/verify_email_page.dart';
import '../functions/encrypt_decrypt.dart';
class LoginController extends GetxController {
final formKey = GlobalKey<FormState>();
final formKeyAdmin = GlobalKey<FormState>();
TextEditingController emailController = TextEditingController();
TextEditingController phoneController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController adminPasswordController = TextEditingController();
TextEditingController adminNameController = TextEditingController();
bool isAgreeTerms = false;
bool isloading = false;
final FlutterSecureStorage _storage = const FlutterSecureStorage();
void changeAgreeTerm() {
isAgreeTerms = !isAgreeTerms;
update();
}
void saveAgreementTerms() {
box.write(BoxName.agreeTerms, 'agreed');
update();
}
void saveCountryCode(String countryCode) {
box.write(BoxName.countryCode, countryCode);
update();
}
void login() async {
isloading = true;
update();
var res = await CRUD().get(link: AppLink.login, payload: {
'email': emailController.text,
'phone': phoneController.text,
'password': passwordController.text
});
isloading = false;
update();
if (res == 'failure') {
//Failure
mySnackeBarError('');
} else {
var jsonDecoeded = jsonDecode(res);
if (jsonDecoeded.isNotEmpty) {
if (jsonDecoeded['status'] == 'success') {
if (jsonDecoeded['data'][0]['verified'] == 1) {
box.write(BoxName.driverID, jsonDecoeded['data'][0]['id']);
box.write(BoxName.emailDriver, (jsonDecoeded['data'][0]['email']));
box.write(
BoxName.nameDriver,
jsonDecoeded['data'][0]['first_name'] +
' ' +
jsonDecoeded['data'][0]['last_name']);
box.write(BoxName.phone, jsonDecoeded['data'][0]['phone']);
SecureStorage().saveData(BoxName.password, passwordController.text);
// Get.offAll(() => const MapPagePassenger());
isloading = false;
update();
await CRUD().post(link: AppLink.addTokens, payload: {
'token': box.read(BoxName.tokenFCM),
'passengerID': box.read(BoxName.passengerID).toString()
});
} else {
isloading = false;
update();
Get.defaultDialog(
title: 'You must Verify email !.'.tr,
middleText: '',
backgroundColor: Colors.yellow[300],
onConfirm: () async {
int randomNumber = Random().nextInt(100000) + 1;
await CRUD().post(link: AppLink.sendVerifyEmail, payload: {
'email': emailController.text,
'token': randomNumber.toString(),
});
Get.to(() => const VerifyEmailPage());
},
);
}
} else if (jsonDecoeded['status'] == 'Failure') {
mySnackeBarError(jsonDecoeded['data']);
isloading = false;
update();
}
} else {
isloading = false;
update();
}
}
}
goToMapPage() {
if (box.read(BoxName.email) != null) {
// Get.offAll(() => const MapPagePassenger());
}
}
@override
void onInit() {
super.onInit();
}
}

View File

@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/main.dart';
import '../../models/model/onboarding_model.dart';
import '../../views/auth/captin/login_captin.dart';
abstract class OnBoardingController extends GetxController {
next();
onPageChanged(int index);
}
class OnBoardingControllerImp extends OnBoardingController {
late PageController pageController;
int currentPage = 0;
@override
next() {
currentPage++;
if (currentPage > onBoardingList.length - 1) {
box.write(BoxName.onBoarding, 'yes');
Get.offAll(() => LoginCaptin());
} else {
pageController.animateToPage(currentPage,
duration: const Duration(milliseconds: 900), curve: Curves.easeInOut);
}
}
@override
onPageChanged(int index) {
currentPage = index;
update();
}
@override
void onInit() {
pageController = PageController();
super.onInit();
}
}

View File

@@ -0,0 +1,95 @@
import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:get/get.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/views/widgets/elevated_btn.dart';
import '../../views/auth/captin/login_captin.dart';
import '../../views/auth/verify_email_page.dart';
class RegisterController extends GetxController {
final formKey = GlobalKey<FormState>();
TextEditingController firstNameController = TextEditingController();
TextEditingController lastNameController = TextEditingController();
TextEditingController emailController = TextEditingController();
TextEditingController phoneController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController siteController = TextEditingController();
TextEditingController verfyCode = TextEditingController();
String birthDate = 'Birth Date'.tr;
String gender = 'Male'.tr;
@override
void onInit() {
super.onInit();
}
getBirthDate() {
Get.defaultDialog(
title: 'Select Date'.tr,
titleStyle: AppStyle.title,
content: SizedBox(
width: 300,
child: CalendarDatePicker(
initialDate:
DateTime.now().subtract(const Duration(days: 14 * 365)),
firstDate: DateTime.parse('1940-06-01'),
lastDate: DateTime.now().subtract(const Duration(days: 14 * 365)),
onDateChanged: (date) {
// Get the selected date and convert it to a DateTime object
DateTime dateTime = date;
// Call the getOrders() function from the controller
birthDate = dateTime.toString().split(' ')[0];
update();
},
// onDateChanged: (DateTime value) {},
),
),
confirm: MyElevatedButton(title: 'Ok'.tr, onPressed: () => Get.back()));
}
void changeGender(String value) {
gender = value;
update();
}
sendVerifications() async {
var res = await CRUD().post(link: AppLink.verifyEmail, payload: {
'email': emailController.text,
'token': verfyCode.text,
});
var dec = jsonDecode(res);
if (dec['status'] == 'success') {
Get.offAll(() => LoginCaptin());
}
}
void register() async {
if (formKey.currentState!.validate()) {
var res = await CRUD().post(link: AppLink.signUp, payload: {
'first_name': firstNameController.text.toString(),
'last_name': lastNameController.text.toString(),
'email': emailController.text.toString(),
'phone': phoneController.text.toString(),
'password': passwordController.text.toString(),
'gender': 'yet',
'site': siteController.text,
'birthdate': birthDate,
});
if (jsonDecode(res)['status'] == 'success') {
int randomNumber = Random().nextInt(100000) + 1;
await CRUD().post(link: AppLink.sendVerifyEmail, payload: {
'email': emailController.text,
'token': randomNumber.toString(),
});
Get.to(() => const VerifyEmailPage());
}
}
}
}

View File

@@ -0,0 +1,38 @@
import 'dart:convert';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
class TokenController extends GetxController {
bool isloading = false;
Future addToken() async {
String? basicAuthCredentials =
await storage.read(key: BoxName.basicAuthCredentials);
isloading = true;
update();
var res = await http.post(
Uri.parse(AppLink.addTokens),
headers: {
'Authorization':
'Basic ${base64Encode(utf8.encode(basicAuthCredentials.toString()))}',
},
body: {
'token': box.read(BoxName.tokenFCM.toString()),
'passengerID': box.read(BoxName.passengerID).toString()
},
);
isloading = false;
update();
var jsonToken = jsonDecode(res.body);
if (jsonToken['status'] == 'The token has been updated successfully.') {
mySnackbarSuccess('token updated'.tr);
}
}
}

View File

@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
class VerifyEmailController extends GetxController {
TextEditingController verfyCode = TextEditingController();
@override
void onInit() async {
super.onInit();
}
sendverfications() async {
await CRUD().post(link: AppLink.sendVerifyEmail);
}
}

View File

@@ -0,0 +1,53 @@
import 'dart:convert';
import 'package:googleapis_auth/auth_io.dart';
import '../../print.dart';
class AccessTokenManager {
static final AccessTokenManager _instance = AccessTokenManager._internal();
late final String serviceAccountJsonKey;
AccessToken? _accessToken;
DateTime? _expiryDate;
AccessTokenManager._internal();
factory AccessTokenManager(String jsonKey) {
if (_instance._isServiceAccountKeyInitialized()) {
// Prevent re-initialization
return _instance;
}
_instance.serviceAccountJsonKey = jsonKey;
return _instance;
}
bool _isServiceAccountKeyInitialized() {
try {
serviceAccountJsonKey; // Access to check if initialized
return true;
} catch (e) {
return false;
}
}
Future<String> getAccessToken() async {
if (_accessToken != null && DateTime.now().isBefore(_expiryDate!)) {
return _accessToken!.data;
}
try {
final serviceAccountCredentials = ServiceAccountCredentials.fromJson(
json.decode(serviceAccountJsonKey));
final client = await clientViaServiceAccount(
serviceAccountCredentials,
['https://www.googleapis.com/auth/firebase.messaging'],
);
_accessToken = client.credentials.accessToken;
_expiryDate = client.credentials.accessToken.expiry;
client.close();
// Log.print('_accessToken!.data: ${_accessToken!.data}');
return _accessToken!.data;
} catch (e) {
throw Exception('Failed to obtain access token');
}
}
}

View File

@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class AppLifecycleManager {
static const platform = MethodChannel('com.sefer_driver/app_lifecycle');
static Future<void> bringAppToForeground() async {
try {
debugPrint('Attempting to bring app to foreground');
await platform.invokeMethod('bringAppToForeground');
debugPrint('Method invocation completed');
} on PlatformException catch (e) {
debugPrint("Failed to bring app to foreground: '${e.message}'.");
} catch (e) {
debugPrint("Unexpected error: $e");
}
}
}

View File

@@ -0,0 +1,777 @@
import 'dart:convert';
import 'dart:io';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/controller/home/captin/home_captain_controller.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../constant/style.dart';
import '../../env/env.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/auth/captin/criminal_documents_page.dart';
import '../../views/home/Captin/home_captain/home_captin.dart';
import '../../views/home/Captin/orderCaptin/order_speed_request.dart';
import '../../views/home/Captin/orderCaptin/order_request_page.dart';
import '../../views/home/Captin/orderCaptin/vip_order_page.dart';
import '../auth/google_sign.dart';
import '../functions/encrypt_decrypt.dart';
import '../functions/face_detect.dart';
import 'access_token.dart';
import 'local_notification.dart';
class FirebaseMessagesController extends GetxController {
final fcmToken = FirebaseMessaging.instance;
List<String> tokens = [];
List dataTokens = [];
late String driverID;
late String driverToken;
NotificationSettings? notificationSettings;
NotificationController notificationController =
Get.put(NotificationController());
Future<void> getNotificationSettings() async {
// Get the current notification settings
NotificationSettings? notificationSettings =
await FirebaseMessaging.instance.getNotificationSettings();
'Notification authorization status: ${notificationSettings.authorizationStatus}';
// Call the update function if needed
update();
}
Future<void> requestFirebaseMessagingPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
// Check if the platform is Android
if (Platform.isAndroid) {
// Request permission for Android
await messaging.requestPermission();
} else if (Platform.isIOS) {
// Request permission for iOS
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: true,
badge: true,
carPlay: true,
criticalAlert: true,
provisional: false,
sound: true,
);
messaging.setForegroundNotificationPresentationOptions(
alert: true, badge: true, sound: true);
}
}
Future getToken() async {
fcmToken.getToken().then((token) {
Log.print('token: ${token}');
box.write(BoxName.tokenDriver, (token!));
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
// If the app is in the background or terminated, show a system tray message
RemoteNotification? notification = message.notification;
AndroidNotification? android = notification?.android;
// if (notification != null && android != null) {
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
FirebaseMessaging.onBackgroundMessage((RemoteMessage message) async {});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
if (message.data.isNotEmpty && message.notification != null) {
fireBaseTitles(message);
}
});
}
Future<void> fireBaseTitles(RemoteMessage message) async {
if (message.notification!.title! == 'Order') {
if (Platform.isAndroid) {
notificationController.showNotification(
message.notification!.title.toString(),
message.notification!.body.toString(),
'tone1',
'');
}
// await FirebaseMessagesController().showOverlayNotification(message);
var myListString = message.data['DriverList'];
// var points = message.data['PolylineJson'];
var myList = jsonDecode(myListString) as List<dynamic>;
// var myPoints = jsonDecode(points) as List<dynamic>;
driverToken = myList[14].toString();
// This is for location using and uploading status
Get.put(HomeCaptainController()).changeRideId();
update();
Get.to(() => OrderRequestPage(), arguments: {
// Get.to(() => OrderRequestPage(), arguments: {
'myListString': myListString,
'DriverList': myList,
// 'PolylineJson': myPoints,
'body': message.notification!.body
});
} else if (message.notification!.title == 'OrderVIP') {
var myListString = message.data['DriverList'];
var myList = jsonDecode(myListString) as List<dynamic>;
// driverToken = myList[10].toString();
if (Platform.isAndroid) {
notificationController.showNotification(
'OrderVIP'.tr, 'OrderVIP'.tr, 'order', '');
}
Get.to(VipOrderPage(), arguments: {
'myListString': myListString,
'DriverList': myList,
// 'PolylineJson': myPoints,
'body': message.notification!.body
});
} else if (message.notification!.title == 'Cancel Trip'.tr) {
if (Platform.isAndroid) {
notificationController.showNotification(
'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', '');
}
cancelTripDialog();
} else if (message.notification!.title == 'VIP Order') {
var myListString = message.data['DriverList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
if (Platform.isAndroid) {
notificationController.showNotification(
'VIP Order'.tr, '', 'order', '');
}
MyDialog().getDialog('VIP Order'.tr, 'midTitle', () {
sendNotificationToPassengerToken(
'VIP Order Accepted'.tr,
'The driver accepted your trip'.tr,
driverList[0],
[driverList[1]],
'order');
});
// Get.to(const VipOrderPage());
} else if (message.notification!.title == 'message From passenger') {
if (Platform.isAndroid) {
notificationController.showNotification(
'message From passenger'.tr, ''.tr, 'ding', '');
}
MyDialog().getDialog(
'message From passenger'.tr, message.notification!.body!, () {
Get.back();
});
} else if (message.notification!.title == 'Cancel') {
if (Platform.isAndroid) {
notificationController.showNotification(
'Cancel'.tr, ''.tr, 'cancel', '');
}
MyDialog().getDialog(
'Passenger Cancel Trip'.tr,
'Trip Cancelled. The cost of the trip will be added to your wallet.'
.tr, () {
box.write(BoxName.rideStatus, 'Cancel');
Log.print('rideStatus from 184 : ${box.read(BoxName.rideStatus)}');
Get.offAll(HomeCaptain());
});
// cancelTripDialog1();
} else if (message.notification!.title! == 'token change') {
// notificationController
// .showNotification('token change'.tr, 'token change', 'cancel');
// GoogleSignInHelper.signOut();
GoogleSignInHelper.signOut();
} else if (message.notification!.title! == 'face detect') {
if (Platform.isAndroid) {
notificationController.showNotification(
'face detect'.tr, ''.tr, 'tone2', '');
}
String result0 = await faceDetector();
// Handle the result here, e.g., show a dialog or update the UI
var result = jsonDecode(result0);
MyDialogContent().getDialog(
'Face Detection Result'.tr,
Text(
result['similar'].toString() == 'true'
? 'similar'.tr
: 'not similar'.tr,
style: AppStyle.title,
),
() {
Get.back();
},
);
update();
} else if (message.notification!.title! == 'Hi ,I will go now') {
if (Platform.isAndroid) {
notificationController.showNotification(
'Passenger come to you'.tr, 'Hi ,I will go now'.tr, 'tone2', '');
}
update();
} else if (message.notification!.title! == 'Call Income'.tr) {
try {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
// if (Platform.isAndroid) {
if (Platform.isAndroid) {
notificationController.showNotification('Call Income'.tr,
message.notification!.body!, 'iphone_ringtone', '');
}
// }
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.to(() => PassengerCallPage(
// channelName: driverList[1].toString(),
// token: driverList[0].toString(),
// remoteID: driverList[2].toString(),
// ));
} catch (e) {}
} else if (message.notification!.title! ==
'Call Income from Passenger'.tr) {
try {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
// if (Platform.isAndroid) {
if (Platform.isAndroid) {
notificationController.showNotification('Call Income'.tr,
message.notification!.body!, 'iphone_ringtone', '');
}
// }
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.to(() => CallPage(
// // channelName: driverList[1].toString(),
// // token: driverList[0].toString(),
// // remoteID: driverList[2].toString(),
// ));
} catch (e) {}
} else if (message.notification!.title! ==
"Criminal Document Required".tr) {
if (Platform.isAndroid) {
notificationController.showNotification("Criminal Document Required".tr,
message.notification!.body!, 'tone2', '');
}
MyDialog().getDialog(
"Criminal Document Required".tr, 'You should have upload it .'.tr,
() {
Get.to(() => const CriminalDocumemtPage());
});
Get.to(() => const CriminalDocumemtPage());
} else if (message.notification!.title! == 'Call End'.tr) {
try {
var myListString = message.data['passengerList'];
var driverList = jsonDecode(myListString) as List<dynamic>;
if (Platform.isAndroid) {
notificationController.showNotification(
'Call End'.tr, message.notification!.body!, 'tone2', '');
}
// Assuming GetMaterialApp is initialized and context is valid for navigation
// Get.off(const CallPage());
} catch (e) {}
} else if (message.notification!.title! == 'Order Applied'.tr) {
mySnackbarSuccess("The order has been accepted by another driver.".tr);
} else if (message.notification!.title! == 'Order') {
if (Platform.isAndroid) {
notificationController.showNotification(
message.notification!.title.toString(),
message.notification!.body.toString(),
'order',
'');
}
var myListString = message.data['DriverList'];
// var points = message.data['PolylineJson'];
var myList = jsonDecode(myListString) as List<dynamic>;
// var myPoints = jsonDecode(points) as List<dynamic>;
driverToken = myList[14].toString();
Get.put(HomeCaptainController()).changeRideId();
update();
Get.to(() => OrderSpeedRequest(), arguments: {
'myListString': myListString,
'DriverList': myList,
// 'PolylineJson': myPoints,
'body': message.notification!.body
});
} else if (message.notification!.title! == 'Order Applied'.tr) {
if (Platform.isAndroid) {
notificationController.showNotification(
'The order Accepted by another Driver'.tr,
'We regret to inform you that another driver has accepted this order.'
.tr,
'order',
'');
}
}
}
SnackbarController driverAppliedTripSnakBar() {
return Get.snackbar(
'Driver Applied the Ride for You'.tr,
'',
colorText: AppColor.greenColor,
duration: const Duration(seconds: 3),
snackPosition: SnackPosition.TOP,
titleText: Text(
'Applied'.tr,
style: const TextStyle(color: AppColor.redColor),
),
messageText: Text(
'Driver Applied the Ride for You'.tr,
style: AppStyle.title,
),
icon: const Icon(Icons.approval),
shouldIconPulse: true,
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
);
}
Future<dynamic> cancelTripDialog() {
return Get.defaultDialog(
barrierDismissible: false,
title: 'Passenger Cancel Trip'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
box.write(BoxName.rideStatus, 'Cancel');
Log.print(
'rideStatus from 347 : ${box.read(BoxName.rideStatus)}');
Get.offAll(HomeCaptain());
}));
}
Future<dynamic> cancelTripDialog1() {
return Get.defaultDialog(
barrierDismissible: false,
title: 'Passenger Cancel Trip'.tr,
middleText:
'Trip Cancelled. The cost of the trip will be added to your wallet.'
.tr,
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
box.write(BoxName.rideStatus, 'Cancel');
Log.print(
'rideStatus from 364 : ${box.read(BoxName.rideStatus)}');
Get.offAll(HomeCaptain());
}));
}
// Future<dynamic> driverArrivePassengerDialoge() {
// return Get.defaultDialog(
// barrierDismissible: false,
// title: 'Hi ,I Arrive your site'.tr,
// middleText: 'Please go to Car Driver'.tr,
// confirm: MyElevatedButton(
// title: 'Ok I will go now.'.tr,
// onPressed: () {
// FirebaseMessagesController().sendNotificationToPassengerToken(
// 'Hi ,I will go now'.tr,
// 'I will go now'.tr,
// Get.find<MapDriverController>().driverToken, []);
// Get.find<MapPassengerController>()
// .startTimerDriverWaitPassenger5Minute();
// Get.back();
// }));
// }
Future<dynamic> passengerDialog(String message) {
return Get.defaultDialog(
barrierDismissible: false,
title: 'message From passenger'.tr,
titleStyle: AppStyle.title,
middleTextStyle: AppStyle.title,
middleText: message.tr,
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () {
// FirebaseMessagesController().sendNotificationToPassengerToken(
// 'Hi ,I will go now'.tr,
// 'I will go now'.tr,
// Get.find<MapPassengerController>().driverToken, []);
// Get.find<MapPassengerController>()
// .startTimerDriverWaitPassenger5Minute();
Get.back();
}));
}
late String serviceAccountKeyJson;
@override
Future<void> onInit() async {
super.onInit();
try {
var encryptedKey = Env.privateKeyFCM;
// Log.print('encryptedKey: ${encryptedKey}');
serviceAccountKeyJson =
EncryptionHelper.instance.decryptData(encryptedKey);
// Log.print('serviceAccountKeyJson: ${serviceAccountKeyJson}');
} catch (e) {
print('🔴 Error decrypting FCM key: $e');
}
}
void sendNotificationAll(String title, body, tone) async {
// Get the token you want to subtract.
String token = box.read(BoxName.tokenFCM);
tokens = box.read(BoxName.tokens);
// Subtract the token from the list of tokens.
tokens.remove(token);
// Save the list of tokens back to the box.
// box.write(BoxName.tokens, tokens);
tokens = box.read(BoxName.tokens);
for (var i = 0; i < tokens.length; i++) {
if (serviceAccountKeyJson.isEmpty) {
print("🔴 Error: Service Account Key is empty");
return;
}
// Initialize AccessTokenManager
final accessTokenManager = AccessTokenManager(serviceAccountKeyJson);
// Obtain an OAuth 2.0 access token
final accessToken = await accessTokenManager.getAccessToken();
// Log.print('accessToken: ${accessToken}');
// Send the notification
final response = await http
.post(
Uri.parse(
'https://fcm.googleapis.com/v1/projects/ride-b1bd8/messages:send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken',
},
body: jsonEncode({
'message': {
'token': token,
'notification': {
'title': title,
'body': body,
},
// 'data': {
// 'DriverList': jsonEncode(data),
// },
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
},
},
},
},
}),
)
.whenComplete(() {})
.catchError((e) {});
}
}
void sendNotificationToPassengerToken(
String title, body, token, List<String> map, String tone,
{int retryCount = 2}) async {
try {
if (serviceAccountKeyJson.isEmpty) {
print("🔴 Error: Service Account Key is empty");
return;
}
// Initialize AccessTokenManager
final accessTokenManager = AccessTokenManager(serviceAccountKeyJson);
// Obtain an OAuth 2.0 access token
final accessToken = await accessTokenManager.getAccessToken();
// Log.print('accessToken: ${accessToken}');
// Send the notification
final response = await http.post(
Uri.parse(
'https://fcm.googleapis.com/v1/projects/ride-b1bd8/messages:send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken',
},
body: jsonEncode({
'message': {
'token': token,
'notification': {
'title': title,
'body': body,
},
'data': {
'passengerList': jsonEncode(map),
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
},
},
},
},
}),
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
const Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToPassengerToken(title, body, token, map, tone,
retryCount: retryCount - 1);
}
}
} catch (e) {
print('Error sending notification: $e');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
const Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToPassengerToken(title, body, token, map, tone,
retryCount: retryCount - 1);
}
}
}
void sendNotificationToPassengerTokenCALL(
String title, body, token, List<String> map, String tone,
{int retryCount = 2}) async {
try {
if (serviceAccountKeyJson.isEmpty) {
print("🔴 Error: Service Account Key is empty");
return;
}
// Initialize AccessTokenManager
final accessTokenManager = AccessTokenManager(serviceAccountKeyJson);
// Obtain an OAuth 2.0 access token
final accessToken = await accessTokenManager.getAccessToken();
// Log.print('accessToken: ${accessToken}');
// Send the notification
final response = await http.post(
Uri.parse(
'https://fcm.googleapis.com/v1/projects/ride-b1bd8/messages:send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken',
},
body: jsonEncode({
'message': {
'token': token,
'notification': {
'title': title,
'body': body,
},
'data': {
'passengerList': jsonEncode(map),
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
},
},
},
},
}),
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
const Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToPassengerTokenCALL(
title, body, token, map, tone,
retryCount: retryCount - 1);
}
}
} catch (e) {
print('Error sending notification: $e');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
const Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToPassengerTokenCALL(
title, body, token, map, tone,
retryCount: retryCount - 1);
}
}
}
Future<void> sendNotificationToDriverMAP(
String title, String body, String token, List<String> data, String tone,
{int retryCount = 2}) async {
try {
if (serviceAccountKeyJson.isEmpty) {
print("🔴 Error: Service Account Key is empty");
return;
}
// Initialize AccessTokenManager
final accessTokenManager = AccessTokenManager(serviceAccountKeyJson);
Log.print(
'accessTokenManager: ${accessTokenManager.serviceAccountJsonKey}');
// Obtain an OAuth 2.0 access token
final accessToken = await accessTokenManager.getAccessToken();
// Log.print('accessToken: ${accessToken}');
// Send the notification
final response = await http.post(
Uri.parse(
'https://fcm.googleapis.com/v1/projects/intaleq-d48a7/messages:send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'Bearer $accessToken',
},
body: jsonEncode({
'message': {
'token': token,
'notification': {
'title': title,
'body': body,
},
'data': {
'DriverList': jsonEncode(data),
},
'android': {
'priority': 'high', // Set priority to high
'notification': {
'sound': tone,
},
},
'apns': {
'headers': {
'apns-priority': '10', // Set APNs priority to 10
},
'payload': {
'aps': {
'sound': tone,
},
},
},
},
}),
);
if (response.statusCode == 200) {
print(
'Notification sent successfully. Status code: ${response.statusCode}');
// print('Response token: ${token}');
} else {
print(
'Failed to send notification. Status code: ${response.statusCode}');
print('Response body: ${response.body}');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToDriverMAP(title, body, token, data, tone,
retryCount: retryCount - 1);
}
}
} catch (e) {
print('Error sending notification: $e');
if (retryCount > 0) {
print('Retrying... Attempts remaining: $retryCount');
await Future.delayed(
Duration(seconds: 2)); // Optional delay before retrying
return sendNotificationToDriverMAP(title, body, token, data, tone,
retryCount: retryCount - 1);
}
}
}
Future<void> removeInvalidToken(String token) async {
// Remove token from your database/storage
// This prevents future attempts to send to invalid tokens
print('Removing invalid token from database: $token');
// Your database cleanup logic here
}
}
class OverlayContent extends StatelessWidget {
final String title;
final String body;
OverlayContent(this.title, this.body);
@override
Widget build(BuildContext context) {
return Material(
child: Container(
padding: const EdgeInsets.all(16.0),
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8.0),
Text(
body,
style: const TextStyle(fontSize: 16),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,591 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_request_page.dart';
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_speed_request.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:timezone/data/latest.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import '../../constant/box_name.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/notification/notification_captain.dart';
import '../home/captin/home_captain_controller.dart';
class NotificationController extends GetxController {
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Future<void> initNotifications() async {
const AndroidInitializationSettings android =
AndroidInitializationSettings('@mipmap/launcher_icon');
DarwinInitializationSettings ios = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
// onDidReceiveLocalNotification:
// (int id, String? title, String? body, String? payload) async {},
);
InitializationSettings initializationSettings =
InitializationSettings(android: android, iOS: ios);
tz.initializeTimeZones();
print('Notifications initialized');
await _flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: onDidReceiveNotificationResponse,
onDidReceiveBackgroundNotificationResponse: notificationTapBackground,
);
// Create a notification channel
const AndroidNotificationChannel channel = AndroidNotificationChannel(
'high_importance_channel', // Use the same ID as in strings.xml
'High Importance Notifications',
description: 'This channel is used for important notifications.',
importance: Importance.high,
);
// Register the channel with the system
await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
}
// Displays a notification with the given title and message
void showNotification(
String title, String message, String tone, String payLoad) async {
BigTextStyleInformation bigTextStyleInformation = BigTextStyleInformation(
message,
contentTitle: title.tr,
htmlFormatContent: true,
htmlFormatContentTitle: true,
);
AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
sound: RawResourceAndroidNotificationSound(tone),
);
// AndroidNotificationDetails android = AndroidNotificationDetails(
// 'high_importance_channel', // Use the same ID as before
// 'High Importance Notifications',
// importance: Importance.high,
// priority: Priority.high,
// styleInformation: bigTextStyleInformation,
// playSound: true,
// sound: RawResourceAndroidNotificationSound(tone),
// // audioAttributesUsage: AudioAttributesUsage.alarm,
// visibility: NotificationVisibility.public,
// autoCancel: false,
// color: AppColor.primaryColor,
// showProgress: true,
// showWhen: true,
// ongoing: true,
// enableVibration: true,
// vibrationPattern: Int64List.fromList([0, 1000, 500, 1000]),
// timeoutAfter: 14500,
// setAsGroupSummary: true,
// subText: message, fullScreenIntent: true,
// actions: [
// AndroidNotificationAction(
// allowGeneratedReplies: true,
// 'id',
// title.tr,
// titleColor: AppColor.blueColor,
// showsUserInterface: true,
// )
// ],
// category: AndroidNotificationCategory.message,
// );
DarwinNotificationDetails ios = const DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
await _flutterLocalNotificationsPlugin.show(0, title, message, details,
payload: jsonEncode({'title': title, 'data': payLoad}));
}
void scheduleNotificationAtSpecificTime(
String title, String message, String tone, int hour, int minute) async {
// Initialize and set Cairo time zone
tz.initializeTimeZones();
var cairoLocation;
if (box.read(BoxName.countryCode).toString() == 'Egypt') {
cairoLocation = tz.getLocation('Africa/Cairo');
} else {} // todo get for location country
final AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
sound: RawResourceAndroidNotificationSound(tone),
);
const DarwinNotificationDetails ios = DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
final NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
final now =
tz.TZDateTime.now(cairoLocation); // Use Cairo timezone for current time
tz.TZDateTime scheduledTime = tz.TZDateTime(
cairoLocation, now.year, now.month, now.day, hour, minute);
// If the scheduled time has already passed for today, schedule it for the next day
if (scheduledTime.isBefore(now)) {
scheduledTime = scheduledTime.add(const Duration(days: 1));
}
if (Platform.isAndroid) {
if (await Permission.scheduleExactAlarm.isDenied) {
if (await Permission.scheduleExactAlarm.request().isGranted) {
print('SCHEDULE_EXACT_ALARM permission granted');
} else {
print('SCHEDULE_EXACT_ALARM permission denied');
return;
}
}
}
print('Current time: $now');
print('Scheduling notification for: $scheduledTime');
await _flutterLocalNotificationsPlugin.zonedSchedule(
0,
title,
message,
scheduledTime,
details,
// androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
androidScheduleMode:
AndroidScheduleMode.alarmClock, // Triggers daily at the same time
);
print('Notification scheduled successfully');
}
void scheduleNotificationAfter1Minute(
String title, String message, String tone) async {
final AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
sound: RawResourceAndroidNotificationSound(tone),
);
const DarwinNotificationDetails ios = DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
final NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
// Schedule the notification to be shown after 1 minute
Timer.periodic(const Duration(seconds: 15), (timer) async {
final now = tz.TZDateTime.now(tz.local);
final scheduledTime = now.add(const Duration(seconds: 10));
Log.print('scheduledTime: ${scheduledTime}');
if (Platform.isAndroid) {
if (await Permission.scheduleExactAlarm.isDenied) {
if (await Permission.scheduleExactAlarm.request().isGranted) {
print('SCHEDULE_EXACT_ALARM permission granted');
} else {
print('SCHEDULE_EXACT_ALARM permission denied');
return;
}
}
}
print('Scheduling notification for: $scheduledTime');
await _flutterLocalNotificationsPlugin.zonedSchedule(
0,
title,
message,
scheduledTime,
details,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
androidScheduleMode: AndroidScheduleMode.alarmClock,
);
print('Notification scheduled successfully');
});
}
void scheduleNotificationsForSevenDays(
String title, String message, String tone) async {
final AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
sound: RawResourceAndroidNotificationSound(tone),
);
const DarwinNotificationDetails ios = DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
final NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
// Check for the exact alarm permission on Android 12 and above
if (Platform.isAndroid) {
if (await Permission.scheduleExactAlarm.isDenied) {
if (await Permission.scheduleExactAlarm.request().isGranted) {
print('SCHEDULE_EXACT_ALARM permission granted');
} else {
print('SCHEDULE_EXACT_ALARM permission denied');
return;
}
}
}
// Schedule notifications for the next 7 days
for (int day = 0; day < 7; day++) {
// List of notification times
final notificationTimes = [
{'hour': 8, 'minute': 0, 'id': day * 1000 + 1}, // 8:00 AM
{'hour': 15, 'minute': 0, 'id': day * 1000 + 2}, // 3:00 PM
{'hour': 20, 'minute': 0, 'id': day * 1000 + 3}, // 8:00 PM
];
for (var time in notificationTimes) {
final notificationId = time['id'] as int;
// Check if this notification ID is already stored
bool isScheduled = box.read('notification_$notificationId') ?? false;
if (!isScheduled) {
// Schedule the notification if not already scheduled
await _scheduleNotificationForTime(
day,
time['hour'] as int,
time['minute'] as int,
title,
message,
details,
notificationId,
);
// Mark this notification ID as scheduled in GetStorage
box.write('notification_$notificationId', true);
} else {
print('Notification with ID $notificationId is already scheduled.');
}
}
}
print('Notifications scheduled successfully for the next 7 days');
}
Future<void> _scheduleNotificationForTime(
int dayOffset,
int hour,
int minute,
String title,
String message,
NotificationDetails details,
int notificationId,
) async {
// Initialize and set Cairo timezone
tz.initializeTimeZones();
var cairoLocation = tz.getLocation('Africa/Cairo');
final now = tz.TZDateTime.now(cairoLocation);
tz.TZDateTime scheduledDate = tz.TZDateTime(
cairoLocation,
now.year,
now.month,
now.day + dayOffset, // Add offset to schedule for the next days
hour,
minute,
);
// If the scheduled time is in the past, move it to the next day
if (scheduledDate.isBefore(now)) {
scheduledDate = scheduledDate.add(Duration(days: 1));
}
print('Current time (Cairo): $now');
print('Scheduling notification for: $scheduledDate');
await _flutterLocalNotificationsPlugin.zonedSchedule(
notificationId, // Unique ID for each notification
title,
message,
scheduledDate,
details,
androidScheduleMode: AndroidScheduleMode.exact,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents:
null, // Don't repeat automatically; we handle 7 days manually
);
print('Notification scheduled successfully for: $scheduledDate');
}
void scheduleNotificationEvery10Hours(
String title, String message, String tone) async {
final AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
sound: RawResourceAndroidNotificationSound(tone),
);
const DarwinNotificationDetails ios = DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
final NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
if (Platform.isAndroid) {
if (await Permission.scheduleExactAlarm.isDenied) {
if (await Permission.scheduleExactAlarm.request().isGranted) {
print('SCHEDULE_EXACT_ALARM permission granted');
} else {
print('SCHEDULE_EXACT_ALARM permission denied');
return;
}
}
}
Timer.periodic(const Duration(hours: 10), (timer) async {
final now = tz.TZDateTime.now(tz.local);
final scheduledTime = now.add(const Duration(minutes: 10));
print('Scheduling notification for: $scheduledTime');
await _flutterLocalNotificationsPlugin.zonedSchedule(
0,
title.tr,
message.tr,
scheduledTime,
details,
// androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
matchDateTimeComponents: DateTimeComponents.time,
androidScheduleMode: AndroidScheduleMode.alarmClock,
);
});
print('Notifications scheduled every 5 seconds');
}
void showTimerNotification(String title, String message, String tone) async {
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
// Setup Android notification
final AndroidNotificationDetails android = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
sound: RawResourceAndroidNotificationSound(
tone), // tone without the file extension
);
// Setup iOS notification
const DarwinNotificationDetails ios = DarwinNotificationDetails(
sound: 'default',
presentAlert: true,
presentBadge: true,
presentSound: true,
);
final NotificationDetails details =
NotificationDetails(android: android, iOS: ios);
// Request permission on Android
if (Platform.isAndroid) {
if (await Permission.scheduleExactAlarm.isDenied) {
if (await Permission.scheduleExactAlarm.request().isGranted) {
print('SCHEDULE_EXACT_ALARM permission granted');
} else {
print('SCHEDULE_EXACT_ALARM permission denied');
return;
}
}
}
// Timer duration (e.g., 120 seconds countdown)
int countdown = 12;
// Display the notification initially with the full countdown time
// Timer to update the notification every second
Timer.periodic(const Duration(seconds: 1), (timer) async {
// if (countdown > 0) {
// Update the existing notification with the updated countdown
// Decrease the countdown by 1
countdown--;
// } else {
// // Cancel the timer when the countdown reaches zero
// timer.cancel();
// }
});
await flutterLocalNotificationsPlugin.show(
0,
title,
'$message Remaining: $countdown seconds', // Initial message
details,
);
print('Notification will update every second');
}
// Callback when the notification is tapped
void onDidReceiveNotificationResponse(NotificationResponse response) {
handleNotificationResponse(response);
}
// Callback when the notification is tapped while the app is in the background
void onDidReceiveBackgroundNotificationResponse(
NotificationResponse response) {
handleNotificationResponse(response);
}
// Handle notification response for both foreground and background
void handleNotificationResponse(NotificationResponse response) {
print('Notification tapped!');
Log.print('response.payload: ${response.payload}');
if (response.payload != null) {
print('Notification payload: ${response.payload}');
var payloadData = jsonDecode(response.payload.toString());
if (payloadData is Map<String, dynamic>) {
String title = payloadData['title'];
var data = payloadData['data'];
switch (title) {
case 'Order':
_handleOrderNotification(data);
break;
case 'OrderSpeed':
_handleOrderSpeedNotification(data);
break;
case 'ADS':
_handleADSNotification();
break;
default:
Log.print('Unknown notification type');
}
} else {
Log.print('Invalid payload format');
}
} else {
Log.print('Payload is null');
}
}
void _handleOrderNotification(dynamic data) {
if (data is String) {
var orderData = jsonDecode(data);
if (orderData is List && orderData.length == 34) {
//closeOverLay();
Get.put(HomeCaptainController()).changeRideId();
Get.to(() => OrderRequestPage(), arguments: {'myListString': data});
} else {
Log.print('Invalid order data');
}
} else {
Log.print('Invalid order payload');
}
}
void _handleOrderSpeedNotification(dynamic data) {
if (data is String) {
var orderData = jsonDecode(data);
if (orderData is List && orderData.length == 34) {
//closeOverLay();
Get.put(HomeCaptainController()).changeRideId();
Get.to(() => OrderRequestPage(), arguments: {'myListString': data});
} else {
Log.print('Invalid order data');
}
} else {
Log.print('Invalid order payload');
}
}
void _handleADSNotification() {
// var orderData = jsonDecode(data);
//closeOverLay();
Get.to(
() => const NotificationCaptain(),
);
}
void onDidReceiveLocalNotification(
int id, String? title, String? body, String? payload) async {
// display a dialog with the notification details, tap ok to go to another page
}
}
class NotificationController1 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, String payLoad) 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

@@ -0,0 +1,35 @@
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/views/home/Captin/home_captain/home_captin.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:flutter/material.dart';
class OverlayContent1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Material(
child: Container(
padding: EdgeInsets.all(16.0),
color: Colors.white,
child: MyElevatedButton(
title: 'go to order',
onPressed: () async {
var res = await CRUD().post(
link: AppLink.addFeedBack,
payload: {
"passengerId": 'dddddd',
"feedBack": "eeeee",
},
);
print(res);
if (res != 'failure') {
Navigator.push(
context, MaterialPageRoute(builder: (cont) => HomeCaptain()));
// Get.to(OrderRequestPage());
}
},
),
),
);
}
}

View File

@@ -0,0 +1,19 @@
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
import 'crud.dart';
addError(String error, where) async {
CRUD().post(link: AppLink.addError, payload: {
'error': error.toString(), // Example error description
'userId': box.read(BoxName.driverID) ??
box.read(BoxName.passengerID), // Example user ID
'userType': box.read(BoxName.driverID) != null
? 'Driver'
: 'passenger', // Example user type
'phone': box.read(BoxName.phone) ??
box.read(BoxName.phoneDriver), // Example phone number
'device': where
});
}

View File

@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:get/get.dart';
class AudioController extends GetxController {
final AudioPlayer _audioPlayer = AudioPlayer();
Future<void> playAudio() async {
// Check if the platform is Android
if (Theme.of(Get.context!).platform == TargetPlatform.android) {
try {
// Load the audio file from the raw resources
await _audioPlayer.setAsset(
'assets/order1.wav'); // Adjust the path based on your project structure
_audioPlayer.play();
} catch (e) {
// Handle errors, such as file not found
print('Error playing audio: $e');
}
}
}
Future<void> playAudio1(String path) async {
// Check if the platform is Android
// if (Theme.of(Get.context!).platform == TargetPlatform.android) {
try {
// Load the audio file from the raw resources
await _audioPlayer
.setAsset(path); // Adjust the path based on your project structure
_audioPlayer.play();
} catch (e) {
// Handle errors, such as file not found
print('Error playing audio: $e');
}
// }
}
@override
void onClose() {
// Release resources when done
_audioPlayer.dispose();
super.onClose();
}
}

View File

@@ -0,0 +1,129 @@
// import 'package:SEFER/constant/api_key.dart';
// import 'package:SEFER/controller/functions/crud.dart';
// // import 'package:agora_rtc_engine/agora_rtc_engine.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
// import '../../constant/box_name.dart';
// import '../firebase/firbase_messge.dart';
// import '../home/captin/map_driver_controller.dart';
// import '../../main.dart';
// class CallController extends GetxController {
// String channelName = ''; // Get.find<MapDriverController>().rideId;
// String token = '';
// // int uid = int.parse(box.read(BoxName.phoneDriver)); // uid of the local user
// int uid = 0;
// int? remoteUid; // uid of the remote user
// bool _isJoined = false; // Indicates if the local user has joined the channel
// String status = '';
// // late RtcEngine agoraEngine; // Agora engine instance
// @override
// void onInit() {
// super.onInit();
// channelName = Get.find<MapDriverController>().rideId; // 'sefer300'; //
// remoteUid = int.parse(Get.find<MapDriverController>().passengerPhone);
// uid = int.parse(box.read(BoxName.phoneDriver));
// initAgoraFull();
// }
// initAgoraFull() async {
// await fetchToken();
// // Set up an instance of Agora engine
// setupVoiceSDKEngine();
// // join();
// FirebaseMessagesController().sendNotificationToPassengerTokenCALL(
// 'Call Income',
// '${'You have call from driver'.tr} ${box.read(BoxName.nameDriver)}',
// Get.find<MapDriverController>().tokenPassenger,
// [
// token,
// channelName,
// uid.toString(),
// remoteUid.toString(),
// ],
// );
// join();
// }
// @override
// void onClose() {
// // agoraEngine.leaveChannel();
// super.onClose();
// }
// // Future<void> setupVoiceSDKEngine() async {
// // // retrieve or request microphone permission
// // await [Permission.microphone].request();
// // //create an instance of the Agora engine
// // agoraEngine = createAgoraRtcEngine();
// // await agoraEngine.initialize(RtcEngineContext(appId: AK.agoraAppId));
// // // Register the event handler
// // agoraEngine.registerEventHandler(
// // RtcEngineEventHandler(
// // onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
// // // Get.snackbar(
// // // "Local user uid:${connection.localUid} joined the channel", '');
// // status = 'joined'.tr;
// // _isJoined = true;
// // update();
// // },
// // onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
// // // Get.snackbar("Remote user uid:$remoteUid joined the channel", '');
// // status = '${Get.find<MapDriverController>().passengerName} '
// // 'joined'
// // .tr;
// // remoteUid = remoteUid;
// // update();
// // },
// // onUserOffline: (RtcConnection connection, int? remoteUid,
// // UserOfflineReasonType reason) {
// // // Get.snackbar("Remote user uid:$remoteUid left the channel", '');
// // status = 'Call Left'.tr;
// // remoteUid = null;
// // update();
// // },
// // ),
// // );
// // }
// // void join() async {
// // // Set channel options including the client role and channel profile
// // ChannelMediaOptions options = const ChannelMediaOptions(
// // clientRoleType: ClientRoleType.clientRoleBroadcaster,
// // channelProfile: ChannelProfileType.channelProfileCommunication,
// // );
// // await agoraEngine.joinChannel(
// // token: token,
// // channelId: channelName,
// // options: options,
// // uid: uid,
// // );
// // }
// // void leave() {
// // _isJoined = false;
// // remoteUid = null;
// // update();
// // agoraEngine.leaveChannel();
// // }
// // // Clean up the resources when you leave
// // @override
// // void dispose() async {
// // await agoraEngine.leaveChannel();
// // super.dispose();
// // }
// fetchToken() async {
// var res = await CRUD()
// .getAgoraToken(channelName: channelName, uid: uid.toString());
// token = res;
// update();
// }
// }

View File

@@ -0,0 +1,236 @@
import 'dart:convert';
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:get/get.dart';
// import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:path_provider/path_provider.dart' as path_provider;
import 'package:path/path.dart' as path;
import 'package:http/http.dart' as http;
import '../../main.dart';
class CameraClassController extends GetxController {
late CameraController cameraController;
late List<CameraDescription> cameras;
bool isCameraInitialized = false;
// final TextRecognizer _textRecognizer = TextRecognizer();
String? scannedText;
bool isloading = false;
@override
void onInit() {
super.onInit();
initializeCamera();
}
Future<void> initializeCamera() async {
try {
cameras = await availableCameras();
//update();
cameraController = CameraController(
cameras[0],
ResolutionPreset.medium,
enableAudio: false,
);
await cameraController.initialize();
isCameraInitialized = true;
update();
} catch (e) {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
Get.defaultDialog(
title: 'Camera Access Denied.'.tr,
middleText: '',
confirm:
MyElevatedButton(title: 'Open Settings'.tr, onPressed: () {}),
);
break;
default:
// Handle other errors here.
break;
}
}
}
}
var imgUrl = '';
Future extractCardId() async {
// Construct the path for the image file
final directory = await path_provider.getTemporaryDirectory();
final imagePath =
path.join(directory.path, '${box.read(BoxName.driverID)}.png');
// Capture the image and save it to the specified path
final XFile capturedImage = await cameraController.takePicture();
// Move the captured image to the desired path
await capturedImage.saveTo(imagePath);
await uploadImage(File(capturedImage.path));
extractByAPI('${AppLink.server}/card_image/' + box.read(BoxName.driverID));
}
Future extractByAPI(String imgUrl) async {
var headers = {'apikey': 'K89368168788957'};
var request = http.MultipartRequest(
'POST', Uri.parse('https://api.ocr.space/parse/image'));
request.fields.addAll({
'language': 'ara',
'isOverlayRequired': 'false',
'url': imgUrl,
'iscreatesearchablepdf': 'false',
'issearchablepdfhidetextlayer': 'false'
});
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
} else {}
}
Future<String> uploadImage(File imageFile) async {
String? basicAuthCredentials =
await storage.read(key: BoxName.basicAuthCredentials);
var request = http.MultipartRequest(
'POST',
Uri.parse(AppLink.uploadImage),
);
// Attach the image file to the request
request.files.add(
await http.MultipartFile.fromPath('image', imageFile.path),
); // Add the headers to the request
request.headers.addAll({
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(basicAuthCredentials.toString()))}',
});
// Add the driverID to the request
request.fields['driverID'] = box.read(BoxName.driverID);
// Send the request
var response = await request.send();
// Read the response
var responseData = await response.stream.toBytes();
var responseString = String.fromCharCodes(responseData);
scannedText = responseString;
update();
// Return the link received from the server
return responseString;
}
// Future<void> takePictureAndMLGoogleScan() async {
// try {
// // Construct the path for the image file
// final directory = await path_provider.getTemporaryDirectory();
// final imagePath =
// path.join(directory.path, '${box.read(BoxName.driverID)}.png');
// // Capture the image and save it to the specified path
// final XFile capturedImage = await cameraController.takePicture();
// // Move the captured image to the desired path
// await capturedImage.saveTo(imagePath);
// // Recognize the text in the image
// final InputImage inputImage =
// InputImage.fromFile(File(capturedImage.path));
// final RecognizedText recognizedText =
// await _textRecognizer.processImage(inputImage);
// scannedText = recognizedText.text;
// // Extract the scanned text line by line
// final List<Map<String, dynamic>> lines = [];
// for (var i = 0; i < recognizedText.blocks.length; i++) {
// lines.add({
// 'line_number': i,
// 'text': recognizedText.blocks[i].text,
// });
// }
// // Convert the list of lines to a JSON string
// final String jsonOutput = jsonEncode(lines);
// update();
// // Print the JSON output
// // Get.back();
// } catch (e) {}
// }
String getTextAsJSON(String text) {
final lines = text.split('\n');
final jsonList = lines.map((line) {
return {
'line_text': line,
'num_words': line.trim().split(' ').length,
};
}).toList();
final json = {
'lines': jsonList,
'num_lines': lines.length,
};
return jsonEncode(json);
}
List<String> getTextBlocks(String text) {
return text.split('\n');
}
// Future<void> takePictureAndTesseractScan() async {
// try {
// // Construct the path for the image file
// final directory = await path_provider.getTemporaryDirectory();
// final imagePath =
// path.join(directory.path, '${box.read(BoxName.driverID)}.png');
// // Capture the image and save it to the specified path
// final XFile capturedImage = await cameraController.takePicture();
// // Move the captured image to the desired path
// await capturedImage.saveTo(imagePath);
// // Recognize the text in the image
// final languages = [
// 'eng',
// 'ara'
// ]; // Specify the languages you want to use for text extraction
// final text = await FlutterTesseractOcr.extractText(imagePath,
// language: languages.join('+'), // Combine multiple languages with '+'
// args: {
// "psm": "4",
// "preserve_interword_spaces": "1",
// // "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
// } // Additional options if needed
// );
// isloading = false;
// final jsonText = getTextAsJSON(text);
// final textBlocks = getTextBlocks(text);
// update();
// scannedText =
// textBlocks.toString(); // Convert the extracted text to JSON.
// // Print the JSON to the console.
// update();
// } catch (e) {
// scannedText = '';
// }
// }
@override
void onClose() {
cameraController.dispose();
super.onClose();
}
}

View File

@@ -0,0 +1,624 @@
import 'dart:convert';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/main.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:sefer_driver/env/env.dart';
import '../../constant/api_key.dart';
import '../../constant/char_map.dart';
import '../../constant/info.dart';
import '../../print.dart';
import 'gemeni.dart';
import 'upload_image.dart';
class CRUD {
Future<dynamic> get({
required String link,
Map<String, dynamic>? payload,
}) async {
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
// Log.print('isTokenExpired: ${isTokenExpired}');
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
// await Get.put(LoginDriverController()).getJWT();
var url = Uri.parse(
link,
);
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
},
);
print(response.request);
Log.print('response.body: ${response.body}');
print(payload);
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return response.body;
}
return jsonData['status'];
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
await Get.put(LoginDriverController()).getJWT();
// mySnackbarSuccess('please order now'.tr);
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
// addError('Non-200 response code: ${response.statusCode}',
// 'crud().post - Other');
return 'failure';
}
}
Future<dynamic> getWallet({
required String link,
Map<String, dynamic>? payload,
}) async {
var s = await LoginDriverController().getJwtWallet();
final hmac = box.read(BoxName.hmac);
// Log.print('hmac: ${hmac}');
var url = Uri.parse(
link,
);
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $s',
'X-HMAC-Auth': hmac.toString(),
},
);
Log.print('response.request: ${response.request}');
Log.print('response.body: ${response.body}');
print(payload);
if (response.statusCode == 200) {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return response.body;
}
return jsonData['status'];
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
// await Get.put(LoginDriverController()).getJwtWallet();
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
// addError('Non-200 response code: ${response.statusCode}',
// 'crud().post - Other');
return 'failure';
}
}
Future<dynamic> postWallet(
{required String link, Map<String, dynamic>? payload}) async {
var s = await LoginDriverController().getJwtWallet();
// Log.print('jwt: ${s}');
final hmac = box.read(BoxName.hmac);
// Log.print('hmac: ${hmac}');
var url = Uri.parse(link);
// Log.print('url: ${url}');
try {
// await LoginDriverController().getJWT();
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer $s',
'X-HMAC-Auth': hmac.toString(),
},
);
Log.print('response.request:${response.request}');
Log.print('response.body: ${response.body}');
Log.print('payload:$payload');
if (response.statusCode == 200) {
try {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return jsonData;
} else {
return jsonData['status'];
}
} catch (e) {
// addError(e.toString(), 'crud().post - JSON decoding');
return 'failure';
}
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
// addError('Non-200 response code: ${response.statusCode}',
// 'crud().post - Other');
return 'failure';
}
} catch (e) {
// addError('HTTP request error: $e', 'crud().post - HTTP');
return 'failure';
}
}
Future<dynamic> post(
{required String link, Map<String, dynamic>? payload}) async {
var url = Uri.parse(link);
try {
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
},
);
print(response.request);
Log.print('response.body: ${response.body}');
print(payload);
if (response.statusCode == 200) {
try {
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'success') {
return jsonData;
} else {
return jsonData['status'];
}
} catch (e) {
// addError(e.toString(), url);
return 'failure';
}
} else if (response.statusCode == 401) {
// Specifically handle 401 Unauthorized
var jsonData = jsonDecode(response.body);
if (jsonData['error'] == 'Token expired') {
// Show snackbar prompting to re-login
// await Get.put(LoginDriverController()).getJWT();
// MyDialog().getDialog(
// 'Session expired. Please log in again.'.tr,
// '',
// () {
// Get.put(LoginController()).loginUsingCredentials(
// box.read(BoxName.passengerID), box.read(BoxName.email));
// Get.back();
// },
// );
return 'token_expired'; // Return a specific value for token expiration
} else {
// Other 401 errors
// addError('Unauthorized: ${jsonData['error']}', 'crud().post - 401');
return 'failure';
}
} else {
// addError('Non-200 response code: ${response.statusCode}',
// 'crud().post - Other');
return 'failure';
}
} catch (e) {
// addError('HTTP request error: $e', 'crud().post - HTTP');
return 'failure';
}
}
Future<dynamic> getAgoraToken({
required String channelName,
required String uid,
}) async {
var uid = box.read(BoxName.phone) ?? box.read(BoxName.phoneDriver);
var res = await http.get(Uri.parse(
// 'https://repulsive-pig-rugby-shirt.cyclic.app/token?channelName=$channelName'),
'https://orca-app-b2i85.ondigitalocean.app/token?channelName=$channelName'),
headers: {'Authorization': 'Bearer ${AK.agoraAppCertificate}'});
if (res.statusCode == 200) {
var response = jsonDecode(res.body);
return response['token'];
} else {}
}
Future<dynamic> getLlama({
required String link,
required String payload,
required String prompt,
}) async {
var url = Uri.parse(
link,
);
var headers = {
'Content-Type': 'application/json',
'Authorization':
'Bearer LL-X5lJ0Px9CzKK0HTuVZ3u2u4v3tGWkImLTG7okGRk4t25zrsLqJ0qNoUzZ2x4ciPy'
// 'Authorization': 'Bearer ${Env.llamaKey}'
};
var data = json.encode({
"model": "Llama-3-70b-Inst-FW",
// "model": "llama-13b-chat",
"messages": [
{
"role": "user",
"content":
"Extract the desired information from the following passage as json decoded like $prompt just in this:\n\n$payload"
}
],
"temperature": 0.9
});
var response = await http.post(
url,
body: data,
headers: headers,
);
if (response.statusCode == 200) {
return response.body;
}
return response.statusCode;
}
Future allMethodForAI(String prompt, linkPHP, imagePath) async {
await ImageController().choosImage(linkPHP, imagePath);
Future.delayed(const Duration(seconds: 2));
var extractedString =
await arabicTextExtractByVisionAndAI(imagePath: imagePath);
var json = jsonDecode(extractedString);
var textValues = extractTextFromLines(json);
// await Get.put(AI()).geminiAiExtraction(prompt, textValues);
await Get.put(AI()).anthropicAI(textValues, prompt, imagePath);
}
String extractTextFromLines(Map<String, dynamic> jsonData) {
final readResult = jsonData['readResult'];
final blocks = readResult['blocks'];
final StringBuffer buffer = StringBuffer();
for (final block in blocks) {
final lines = block['lines'];
for (final line in lines) {
final text = line['text'];
buffer.write(text);
buffer.write('\n');
}
}
return buffer.toString().trim();
}
Future<dynamic> arabicTextExtractByVisionAndAI({
required String imagePath,
}) async {
var headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': AK.ocpApimSubscriptionKey
};
String imagePathFull =
'${AppLink.server}/card_image/$imagePath-${box.read(BoxName.driverID)}.jpg';
var request = http.Request('POST', Uri.parse(
// 'https://ocrhamza.cognitiveservices.azure.com/vision/v2.1/ocr?language=ar'));
// 'https://eastus.api.cognitive.microsoft.com/vision/v3.2/ocr'
'https://eastus.api.cognitive.microsoft.com/computervision/imageanalysis:analyze?features=caption,read&model-version=latest&language=en&api-version=2024-02-01'));
request.body = json.encode({"url": imagePathFull});
// request.body = json.encode({"url": imagePathFull});
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
// 'response.stream.bytesToString(): ${await response.stream.bytesToString()}');
return await response.stream.bytesToString();
} else {}
}
Future<dynamic> getChatGPT({
required String link,
required String payload,
}) async {
var url = Uri.parse(
link,
);
var headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ${Env.chatGPTkeySeferNew}'
};
var data = json.encode({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content":
"Extract the desired information from the following passage as json decoded like vin,make,made,year,expiration_date,color,owner,registration_date just in this:\n\n$payload"
}
],
"temperature": 0.9
});
var response = await http.post(
url,
body: data,
headers: headers,
);
if (response.statusCode == 200) {
return response.body;
}
return response.statusCode;
}
Future<dynamic> postStripe({
required String link,
Map<String, dynamic>? payload,
}) async {
// String? secretKey = await storage.read(key: BoxName.secretKey);
var url = Uri.parse(
link,
);
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization': 'Bearer ${AK.secretKeyStripe}',
},
);
if (response.statusCode == 200) {
return response.body;
} else {}
}
Future<dynamic> postPayMob({
required String link,
Map<String, dynamic>? payload,
}) async {
// String? basicAuthCredentials =
// await storage.read(key: BoxName.basicAuthCredentials);
var url = Uri.parse(
link,
);
var response = await http.post(url,
body: payload, headers: {'Content-Type': 'application/json'});
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {
if (jsonData['status'] == 'success') {
return response.body;
} else {
return (jsonData['status']);
}
} else {
return response.statusCode;
}
}
Future<void> sendEmail(String link, Map<String, String>? payload) async {
// التحقق من صلاحية التوكن
String rawJwt = box.read(BoxName.jwt);
String token = X
.r(X.r(X.r(rawJwt, cn), cC), cs)
.toString()
.split(AppInformation.addd)[0];
bool isTokenExpired = JwtDecoder.isExpired(token);
if (isTokenExpired) {
await LoginDriverController().getJWT();
rawJwt = box.read(BoxName.jwt); // تحديث التوكن بعد التجديد
token = X
.r(X.r(X.r(rawJwt, cn), cC), cs)
.toString()
.split(AppInformation.addd)[0];
}
// إعداد الهيدر
final headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer $token",
};
// إعداد الطلب
final request = http.Request('POST', Uri.parse(link));
request.bodyFields = payload ?? {};
request.headers.addAll(headers);
// إرسال الطلب
final response = await request.send();
// التحقق من النتيجة
if (response.statusCode == 200) {
print("✅ Email sent successfully.");
} else {
print("❌ Failed to send email. Status: ${response.statusCode}");
final responseBody = await response.stream.bytesToString();
print("Response body: $responseBody");
}
}
Future<dynamic> postFromDialogue({
required String link,
Map<String, dynamic>? payload,
}) async {
// String? basicAuthCredentials =
// await storage.read(key: BoxName.basicAuthCredentials);
var url = Uri.parse(
link,
);
var response = await http.post(
url,
body: payload,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
},
);
if (response.body.isNotEmpty) {
var jsonData = jsonDecode(response.body);
if (response.statusCode == 200) {
if (jsonData['status'] == 'success') {
Get.back();
// Get.snackbar(
// jsonData['status'],
// jsonData['message'],
// );
return response.body;
}
}
return (jsonData['status']);
}
}
Future<void> sendVerificationRequest(String phoneNumber) async {
final accountSid = AK.accountSIDTwillo;
final authToken = AK.authTokenTwillo;
final verifySid = AK.twilloRecoveryCode;
final Uri verificationUri = Uri.parse(
'https://verify.twilio.com/v2/Services/$verifySid/Verifications');
// Send the verification request
final response = await http.post(
verificationUri,
headers: {
'Authorization':
'Basic ' + base64Encode(utf8.encode('$accountSid:$authToken')),
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
'To': phoneNumber,
'Channel': 'sms',
},
);
if (response.statusCode == 201) {
} else {}
// Prompt the user to enter the OTP
final otpCode = "123456"; // Replace with user input
// Check the verification code
final checkUri = Uri.parse(
'https://verify.twilio.com/v2/Services/$verifySid/VerificationCheck');
final checkResponse = await http.post(
checkUri,
headers: {
'Authorization':
'Basic ' + base64Encode(utf8.encode('$accountSid:$authToken')),
'Content-Type': 'application/x-www-form-urlencoded',
},
body: {
'To': phoneNumber,
'Code': otpCode,
},
);
if (checkResponse.statusCode == 201) {
} else {}
}
Future<dynamic> getGoogleApi({
required String link,
Map<String, dynamic>? payload,
}) async {
var url = Uri.parse(
link,
);
var response = await http.post(
url,
body: payload,
);
var jsonData = jsonDecode(response.body);
if (jsonData['status'] == 'OK') {
return jsonData;
}
return (jsonData['status']);
}
Future<dynamic> update({
required String endpoint,
required Map<String, dynamic> data,
required String id,
}) async {
// String? basicAuthCredentials =
// await storage.read(key: BoxName.basicAuthCredentials);
var url = Uri.parse('$endpoint/$id');
var response = await http.put(
url,
body: json.encode(data),
headers: {
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
},
);
return json.decode(response.body);
}
Future<dynamic> delete({
required String endpoint,
required String id,
}) async {
// String? basicAuthCredentials =
// await storage.read(key: BoxName.basicAuthCredentials);
var url = Uri.parse('$endpoint/$id');
var response = await http.delete(
url,
headers: {
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
},
);
return json.decode(response.body);
}
}

View File

@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
class LineChartPainter extends CustomPainter {
final List<double> data;
LineChartPainter(this.data);
@override
void paint(Canvas canvas, Size size) {
// Calculate the scale factor.
final scaleFactor = size.height / 240;
// Draw the line chart.
for (var i = 0; i < data.length - 1; i++) {
final x1 = i * size.width / data.length;
final y1 = data[i] * scaleFactor;
final x2 = (i + 1) * size.width / data.length;
final y2 = data[i + 1] * scaleFactor;
canvas.drawLine(Offset(x1, y1), Offset(x2, y2), Paint());
}
}
@override
bool shouldRepaint(LineChartPainter oldDelegate) => false;
}

View File

@@ -0,0 +1,80 @@
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:get_storage/get_storage.dart';
import '../../constant/box_name.dart';
class DeviceInfo {
final String? manufacturer;
final String? model;
final String? deviceId;
final String? osVersion;
final String? platform;
final String? deviceName;
final bool? isPhysicalDevice;
DeviceInfo({
this.manufacturer,
this.model,
this.deviceId,
this.osVersion,
this.platform,
this.deviceName,
this.isPhysicalDevice,
});
Map<String, dynamic> toJson() => {
'manufacturer': manufacturer,
'model': model,
'deviceId': deviceId,
'osVersion': osVersion,
'platform': platform,
'deviceName': deviceName,
'isPhysicalDevice': isPhysicalDevice,
};
}
class DeviceController {
final box = GetStorage();
final _deviceInfo = DeviceInfoPlugin();
Future<DeviceInfo> getDeviceInfo() async {
if (Platform.isAndroid) {
return await _getAndroidDeviceInfo();
} else if (Platform.isIOS) {
return await _getIosDeviceInfo();
}
throw UnsupportedError('Unsupported platform');
}
Future<DeviceInfo> _getAndroidDeviceInfo() async {
final androidInfo = await _deviceInfo.androidInfo;
final deviceInfo = DeviceInfo(
manufacturer: androidInfo.manufacturer,
model: androidInfo.model,
deviceId: androidInfo.serialNumber,
osVersion: androidInfo.version.release,
platform: 'Android',
deviceName: androidInfo.device,
isPhysicalDevice: androidInfo.isPhysicalDevice,
);
box.write(BoxName.deviceInfo, deviceInfo.toJson());
return deviceInfo;
}
Future<DeviceInfo> _getIosDeviceInfo() async {
final iosInfo = await _deviceInfo.iosInfo;
final deviceInfo = DeviceInfo(
manufacturer: 'Apple',
model: iosInfo.model,
deviceId: iosInfo.identifierForVendor,
osVersion: iosInfo.systemVersion,
platform: 'iOS',
deviceName: iosInfo.name,
isPhysicalDevice: iosInfo.isPhysicalDevice,
);
box.write(BoxName.deviceInfo, deviceInfo.toJson());
return deviceInfo;
}
}

View File

@@ -0,0 +1,42 @@
import 'package:flutter/services.dart';
class DigitObscuringFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
final maskedText = maskDigits(newValue.text);
return newValue.copyWith(
text: maskedText,
selection: updateCursorPosition(maskedText, newValue.selection));
}
String maskDigits(String text) {
final totalDigits = text.length;
final visibleDigits = 4;
final hiddenDigits = totalDigits - visibleDigits * 2;
final firstVisibleDigits = text.substring(0, visibleDigits);
final lastVisibleDigits = text.substring(totalDigits - visibleDigits);
final maskedDigits = List.filled(hiddenDigits, '*').join();
return '$firstVisibleDigits$maskedDigits$lastVisibleDigits';
}
TextSelection updateCursorPosition(
String maskedText, TextSelection currentSelection) {
final cursorPosition = currentSelection.baseOffset;
final cursorOffset =
currentSelection.extentOffset - currentSelection.baseOffset;
final totalDigits = maskedText.length;
const visibleDigits = 4;
final hiddenDigits = totalDigits - visibleDigits * 2;
final updatedPosition = cursorPosition <= visibleDigits
? cursorPosition
: hiddenDigits + visibleDigits + (cursorPosition - visibleDigits);
return TextSelection.collapsed(
offset: updatedPosition, affinity: currentSelection.affinity);
}
}

View File

@@ -0,0 +1,41 @@
// import 'dart:io';
//
// import 'package:get/get.dart';
// import 'package:image_picker/image_picker.dart';
// import 'package:google_ml_kit/google_ml_kit.dart';
//
// class ImagePickerController extends GetxController {
// RxBool textScanning = false.obs;
// RxString scannedText = ''.obs;
//
// Future<void> getImage(ImageSource source) async {
// try {
// final pickedImage = await ImagePicker().pickImage(source: source);
// if (pickedImage != null) {
// textScanning.value = true;
// final imageFile = File(pickedImage.path);
// getRecognisedText(imageFile);
// }
// } catch (e) {
// textScanning.value = false;
// scannedText.value = "Error occurred while scanning";
// }
// }
//
// Future<void> getRecognisedText(File image) async {
// final inputImage = InputImage.fromFilePath(image.path);
// final textDetector = GoogleMlKit.vision.textRecognizer();
// final RecognizedText recognisedText =
// await textDetector.processImage(inputImage);
// await textDetector.close();
//
// scannedText.value = '';
// for (TextBlock block in recognisedText.blocks) {
// for (TextLine line in block.lines) {
// scannedText.value += line.text + '\n';
// }
// }
//
// textScanning.value = false;
// }
// }

View File

@@ -0,0 +1,32 @@
import 'dart:convert';
import 'package:encrypt/encrypt.dart' as encrypt;
import '../../constant/api_key.dart';
class KeyEncryption {
// استخدم مفتاح بطول 32 حرفًا
static final _key = encrypt.Key.fromUtf8(AK.keyOfApp);
static final _iv =
encrypt.IV.fromLength(16); // توليد تهيئة عشوائية بطول 16 بايت
static String encryptKey(String key) {
final encrypter =
encrypt.Encrypter(encrypt.AES(_key, mode: encrypt.AESMode.cbc));
final encrypted = encrypter.encrypt(key, iv: _iv);
final result = _iv.bytes + encrypted.bytes; // تضمين التهيئة مع النص المشفر
return base64Encode(result);
}
static String decryptKey(String encryptedKey) {
print('encryptedKey: ${AK.keyOfApp}');
final decoded = base64Decode(encryptedKey);
print('encryptedKey: $encryptedKey');
final iv = encrypt.IV(decoded.sublist(0, 16)); // استخراج التهيئة
final encrypted =
encrypt.Encrypted(decoded.sublist(16)); // استخراج النص المشفر
final encrypter =
encrypt.Encrypter(encrypt.AES(_key, mode: encrypt.AESMode.cbc));
return encrypter.decrypt(encrypted, iv: iv);
}
}

View File

@@ -0,0 +1,79 @@
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:flutter/foundation.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import '../../constant/box_name.dart';
import '../../constant/char_map.dart';
import '../../env/env.dart';
import '../../main.dart';
class EncryptionHelper {
static EncryptionHelper? _instance;
late final encrypt.Key key;
late final encrypt.IV iv;
EncryptionHelper._(this.key, this.iv);
static EncryptionHelper get instance {
if (_instance == null) {
throw Exception(
"EncryptionHelper is not initialized. Call `await EncryptionHelper.initialize()` in main.");
}
return _instance!;
}
/// Initializes and stores the instance globally
static Future<void> initialize() async {
if (_instance != null) {
debugPrint("EncryptionHelper is already initialized.");
return; // Prevent re-initialization
}
debugPrint("Initializing EncryptionHelper...");
// Read stored keys
var keyOfApp = r(Env.keyOfApp).toString().split(Env.addd)[0];
var initializationVector =
r(Env.initializationVector).toString().split(Env.addd)[0];
// Log.print('initializationVector: ${initializationVector}');
// Set the global instance
_instance = EncryptionHelper._(
encrypt.Key.fromUtf8(keyOfApp),
encrypt.IV.fromUtf8(initializationVector),
);
debugPrint("EncryptionHelper initialized successfully.");
}
/// Encrypts a string
String encryptData(String plainText) {
try {
final encrypter = encrypt.Encrypter(
encrypt.AES(key, mode: encrypt.AESMode.cbc)); // AES-GCM
final encrypted = encrypter.encrypt(plainText, iv: iv);
return encrypted.base64;
} catch (e) {
debugPrint('Encryption Error: $e');
return '';
}
}
/// Decrypts a string
String decryptData(String encryptedText) {
try {
final encrypter =
encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));
final encrypted = encrypt.Encrypted.fromBase64(encryptedText);
return encrypter.decrypt(encrypted, iv: iv);
} catch (e) {
debugPrint('Decryption Error: $e');
return '';
}
}
}
r(String string) {
return X.r(X.r(X.r(string, cn), cC), cs).toString();
}
c(String string) {
return X.c(X.c(X.c(string, cn), cC), cs).toString();
}

View File

@@ -0,0 +1,95 @@
import 'dart:convert';
import 'dart:io';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/main.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';
import '../../constant/links.dart';
import 'encrypt_decrypt.dart';
import 'upload_image.dart';
Future<String> faceDetector() async {
await ImageController().choosFace(AppLink.uploadEgypt, 'face_detect');
await Future.delayed(const Duration(seconds: 2));
var headers = {
// 'Authorization': 'Basic ${AK.basicCompareFaces}',
'Authorization': 'Basic hamza:12345678',
'Content-Type': 'application/json'
};
// var request = http.Request('POST', Uri.parse(//Todo
// 'https://face-detect-f6924392c4c7.herokuapp.com/compare_faces'));
var request = http.Request(
'POST', Uri.parse('https://mohkh.online:5000/compare_faces'));
request.body = json.encode({
"url1":
"${AppLink.seferCairoServer}/card_image/id_front-${(box.read(BoxName.driverID))}.jpg",
"url2":
"https://api.sefer.live/sefer/card_image/face_detect-${(box.read(BoxName.driverID))}.jpg"
});
print('request.body: ${request.body}');
request.headers.addAll(headers);
try {
http.Client client = await createHttpClient();
http.StreamedResponse response = await client.send(request);
// http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
String result = await response.stream.bytesToString();
print('result: ${result}');
return result;
} else {
print('Error: ${response.reasonPhrase}');
return 'Error: ${response.reasonPhrase}';
}
} catch (e) {
print('Exception occurred: $e');
return 'Error: $e';
}
}
Future<http.Client> createHttpClient() async {
final SecurityContext securityContext = SecurityContext();
HttpClient httpClient = HttpClient(context: securityContext);
httpClient.badCertificateCallback =
(X509Certificate cert, String host, int port) => true; // Bypass SSL
return IOClient(httpClient);
}
Future<String> faceDetector2(String url1, String url2) async {
var headers = {
'Authorization': 'Basic hamza:12345678',
'Content-Type': 'application/json'
};
var request = http.Request(
'POST', Uri.parse('https://mohkh.online:5000/compare_faces'));
request.body = json.encode({"url1": url1, "url2": url2});
request.headers.addAll(headers);
try {
http.Client client = await createHttpClient(); // Use custom client
DateTime startTime = DateTime.now();
http.StreamedResponse response = await client.send(request);
DateTime endTime = DateTime.now();
Duration duration = endTime.difference(startTime);
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
print(duration.inSeconds);
return await response.stream.bytesToString();
} else {
print(await response.stream.bytesToString());
return 'Error: ${response.reasonPhrase}';
}
} catch (e) {
return 'Exception: $e';
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
import 'package:geolocator/geolocator.dart';
class GeoLocation {
Future<Position> getCurrentLocation() async {
bool serviceEnabled;
LocationPermission permission;
// Check if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
// Location services are not enabled, so we request the user to enable it.
return Future.error('Location services are disabled.');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
// Permissions are denied, we cannot fetch the location.
return Future.error('Location permissions are denied');
}
}
if (permission == LocationPermission.deniedForever) {
// Permissions are denied forever, we cannot request permissions.
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}
// When we reach here, permissions are granted and we can fetch the location.
return await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
}

View File

@@ -0,0 +1,76 @@
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';
void showInBrowser(String url) async {
if (await canLaunchUrl(Uri.parse(url))) {
launchUrl(Uri.parse(url));
} else {}
}
Future<void> makePhoneCall(String phoneNumber) async {
final Uri launchUri = Uri(
scheme: 'tel',
path: phoneNumber,
);
await launchUrl(launchUri);
}
void launchCommunication(
String method, String contactInfo, String message) async {
String url;
if (Platform.isIOS) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
break;
case 'email':
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
return;
}
} else if (Platform.isAndroid) {
switch (method) {
case 'phone':
url = 'tel:$contactInfo';
break;
case 'sms':
url = 'sms:$contactInfo?body=${Uri.encodeComponent(message)}';
break;
case 'whatsapp':
// Check if WhatsApp is installed
final bool whatsappInstalled =
await canLaunchUrl(Uri.parse('whatsapp://'));
if (whatsappInstalled) {
url =
'whatsapp://send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
} else {
// Provide an alternative action, such as opening the WhatsApp Web API
url =
'https://api.whatsapp.com/send?phone=$contactInfo&text=${Uri.encodeComponent(message)}';
}
break;
case 'email':
url =
'mailto:$contactInfo?subject=Subject&body=${Uri.encodeComponent(message)}';
break;
default:
return;
}
} else {
return;
}
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
} else {}
}

View File

@@ -0,0 +1,37 @@
import 'dart:convert';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/controller/functions/gemeni.dart';
class LlamaAi {
Future<Map> getCarRegistrationData(String input, prompt) async {
Map exrtatDataFinal = {};
String oneLine = input.replaceAll('\n', ' ');
// var res = await CRUD().getLlama(link: AppLink.gemini, payload: oneLine);
var res = await CRUD()
.getLlama(link: AppLink.llama, payload: oneLine, prompt: prompt);
var decod = jsonDecode(res.toString());
// exrtatDataFinal = jsonDecode(extractDataFromJsonString(decod['choices']));
extractDataFromJsonString(decod['choices'][0]['message']['content']);
return exrtatDataFinal;
}
String extractDataFromJsonString(String jsonString) {
// Remove any leading or trailing whitespace from the string
jsonString = jsonString.trim();
// Extract the JSON substring from the given string
final startIndex = jsonString.indexOf('{');
final endIndex = jsonString.lastIndexOf('}');
final jsonSubstring = jsonString.substring(startIndex, endIndex + 1);
// Parse the JSON substring into a Map
final jsonData = jsonDecode(jsonSubstring);
// Return the extracted data
return jsonEncode(jsonData);
}
}

View File

@@ -0,0 +1,54 @@
// import 'dart:async';
// import 'package:background_location/background_location.dart';
// import 'package:get/get.dart';
// import 'package:permission_handler/permission_handler.dart';
// class LocationBackgroundController extends GetxController {
// @override
// void onInit() {
// super.onInit();
// requestLocationPermission();
// configureBackgroundLocation();
// }
// Future<void> requestLocationPermission() async {
// var status = await Permission.locationAlways.status;
// if (!status.isGranted) {
// await Permission.locationAlways.request();
// }
// }
// Future<void> configureBackgroundLocation() async {
// await BackgroundLocation.setAndroidNotification(
// title: 'Location Tracking Active'.tr,
// message: 'Your location is being tracked in the background.'.tr,
// icon: '@mipmap/launcher_icon',
// );
// BackgroundLocation.setAndroidConfiguration(3000);
// BackgroundLocation.startLocationService();
// BackgroundLocation.getLocationUpdates((location) {
// // Handle location updates here
// });
// }
// startBackLocation() async {
// Timer.periodic(const Duration(seconds: 3), (timer) {
// getBackgroundLocation();
// });
// }
// getBackgroundLocation() async {
// var status = await Permission.locationAlways.status;
// if (status.isGranted) {
// await BackgroundLocation.startLocationService(
// distanceFilter: 20, forceAndroidLocationManager: true);
// BackgroundLocation.setAndroidConfiguration(
// Duration.microsecondsPerSecond); // Set interval to 5 seconds
// BackgroundLocation.getLocationUpdates((location1) {});
// } else {
// await Permission.locationAlways.request();
// }
// }
// }

View File

@@ -0,0 +1,230 @@
import 'dart:async';
import 'dart:math';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart';
import 'package:sefer_driver/constant/table_names.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import '../home/captin/home_captain_controller.dart';
import '../home/payment/captain_wallet_controller.dart';
import 'crud.dart';
import 'encrypt_decrypt.dart';
class LocationController extends GetxController {
LocationData? _currentLocation;
late Location location = Location();
bool isLoading = false;
late double heading = 0;
late double previousTime = 0;
late double latitude;
late double totalDistance = 0;
late double longitude;
late DateTime time;
late double speed = 0;
bool isActive = false;
late LatLng myLocation = LatLng(0, 0);
String totalPoints = '0';
LocationData? get currentLocation => _currentLocation;
Timer? _locationTimer;
LatLng? _lastSavedPosition;
@override
void onInit() async {
super.onInit();
location = Location();
await location.changeSettings(
accuracy: LocationAccuracy.high, interval: 5000, distanceFilter: 0);
location.enableBackgroundMode(enable: true);
await getLocation();
await startLocationUpdates();
totalPoints = Get.put(CaptainWalletController()).totalPoints.toString();
isActive = Get.put(HomeCaptainController()).isActive;
}
String getLocationArea(double latitude, double longitude) {
final locations = box.read(BoxName.locationName) ?? [];
for (final location in locations) {
final locationData = location as Map<String, dynamic>;
final minLatitude =
double.tryParse(locationData['min_latitude'].toString()) ?? 0.0;
final maxLatitude =
double.tryParse(locationData['max_latitude'].toString()) ?? 0.0;
final minLongitude =
double.tryParse(locationData['min_longitude'].toString()) ?? 0.0;
final maxLongitude =
double.tryParse(locationData['max_longitude'].toString()) ?? 0.0;
if (latitude >= minLatitude &&
latitude <= maxLatitude &&
longitude >= minLongitude &&
longitude <= maxLongitude) {
box.write(BoxName.serverChosen, (locationData['server_link']));
return locationData['name'];
}
}
box.write(BoxName.serverChosen, AppLink.seferCairoServer);
return 'Cairo';
}
int _insertCounter = 0;
double? _lastSpeed;
DateTime? _lastSpeedTime;
Future<void> startLocationUpdates() async {
if (box.read(BoxName.driverID) != null) {
_locationTimer =
Timer.periodic(const Duration(seconds: 5), (timer) async {
try {
totalPoints =
Get.find<CaptainWalletController>().totalPoints.toString();
isActive = Get.find<HomeCaptainController>().isActive;
if (isActive && double.parse(totalPoints) > -300) {
await getLocation();
if (myLocation.latitude == 0 && myLocation.longitude == 0) return;
String area =
getLocationArea(myLocation.latitude, myLocation.longitude);
final payload = {
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude.toString(),
'longitude': myLocation.longitude.toString(),
'heading': heading.toString(),
'speed': (speed * 3.6).toStringAsFixed(1),
'distance': totalDistance.toStringAsFixed(2),
'status': box.read(BoxName.statusDriverLocation) ?? 'off',
};
// ✅ تحديث للسيرفر
await CRUD().post(
link:
box.read(BoxName.serverChosen) + '/ride/location/update.php',
payload: payload,
);
// ✅ تخزين في SQLite فقط إذا الرحلة On + تحرك أكثر من 10 متر
if ((box.read(BoxName.statusDriverLocation) ?? 'off') == 'on') {
if (_lastSavedPosition == null ||
_calculateDistanceInMeters(_lastSavedPosition!, myLocation) >=
10) {
double currentSpeed = speed; // m/s
double? acceleration = _calculateAcceleration(currentSpeed);
await sql.insertData({
'driver_id': box.read(BoxName.driverID).toString(),
'latitude': myLocation.latitude,
'longitude': myLocation.longitude,
'acceleration': acceleration ?? 0.0,
'created_at': DateTime.now().toIso8601String(),
'updated_at': DateTime.now().toIso8601String(),
}, TableName.behavior);
_lastSavedPosition = myLocation;
}
}
// ✅ إدخال للسيرفر كل دقيقة
_insertCounter++;
// Log.print('_insertCounter: ${_insertCounter}');
if (_insertCounter == 12) {
_insertCounter = 0;
await CRUD().post(
link: box.read(BoxName.serverChosen) + '/ride/location/add.php',
payload: payload,
);
}
// ✅ تحديث الكاميرا
Get.find<HomeCaptainController>()
.mapHomeCaptainController
?.animateCamera(
CameraUpdate.newLatLng(
LatLng(
myLocation.latitude,
myLocation.longitude,
),
),
);
}
} catch (e) {
print('Location update error: $e');
}
});
}
}
void stopLocationUpdates() {
_locationTimer?.cancel();
}
Future<void> getLocation() async {
bool serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) return;
}
PermissionStatus permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) return;
}
Future.delayed(Duration(milliseconds: 500), () async {
try {
LocationData _locationData = await location.getLocation();
if (_locationData.latitude != null && _locationData.longitude != null) {
myLocation =
LatLng(_locationData.latitude!, _locationData.longitude!);
} else {
myLocation = LatLng(0, 0);
}
speed = _locationData.speed ?? 0;
heading = _locationData.heading ?? 0;
update();
} catch (e) {
print("Error getting location: $e");
}
});
}
double _calculateDistanceInMeters(LatLng start, LatLng end) {
const p = 0.017453292519943295;
final a = 0.5 -
cos((end.latitude - start.latitude) * p) / 2 +
cos(start.latitude * p) *
cos(end.latitude * p) *
(1 - cos((end.longitude - start.longitude) * p)) /
2;
return 12742 * 1000 * asin(sqrt(a)); // meters
}
double? _calculateAcceleration(double currentSpeed) {
final now = DateTime.now();
if (_lastSpeed != null && _lastSpeedTime != null) {
final deltaTime =
now.difference(_lastSpeedTime!).inMilliseconds / 1000.0; // seconds
if (deltaTime > 0) {
final acceleration = (currentSpeed - _lastSpeed!) / deltaTime;
_lastSpeed = currentSpeed;
_lastSpeedTime = now;
return double.parse(acceleration.toStringAsFixed(2));
}
}
_lastSpeed = currentSpeed;
_lastSpeedTime = now;
return null;
}
}

View File

@@ -0,0 +1,60 @@
import 'package:get/get.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../constant/box_name.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/widgets/mydialoug.dart';
import '../auth/captin/login_captin_controller.dart';
class LocationPermissions {
// late Location location;
// Future locationPermissions() async {
// location = Location();
// var permissionStatus = await location.requestPermission();
// if (permissionStatus == PermissionStatus.denied) {
// // The user denied the location permission.
// Get.defaultDialog(title: 'GPS Required Allow !.'.tr, middleText: '');
// return null;
// }
// }
}
Future<void> getPermissionLocation() async {
final PermissionStatus status = await Permission.locationAlways.status;
if (!await Permission.locationAlways.serviceStatus.isEnabled) {
Log.print('status.isGranted: ${status.isGranted}');
// box.write(BoxName.locationPermission, 'true');
await Permission.locationAlways.request();
Get.put(LoginDriverController()).update();
MyDialog().getDialog(
'Enable Location Permission'.tr, // {en:ar}
'Allowing location access will help us display orders near you. Please enable it now.'
.tr, // {en:ar}
() async {
Get.back();
box.write(BoxName.locationPermission, 'true');
await Permission.locationAlways.request();
},
);
}
}
Future<void> getPermissionLocation1() async {
PermissionStatus status = await Permission.locationWhenInUse.request();
if (status.isGranted) {
// After granting when in use, request "always" location permission
status = await Permission.locationAlways.request();
if (status.isGranted) {
print("Background location permission granted");
} else {
print("Background location permission denied");
}
} else {
print("Location permission denied");
await openAppSettings();
}
}

View File

@@ -0,0 +1,161 @@
import 'dart:io';
import 'package:sefer_driver/views/home/on_boarding_page.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
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/main.dart';
import 'package:sefer_driver/onbording_page.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/my_textField.dart';
import '../../constant/style.dart';
import 'encrypt_decrypt.dart';
class LogOutController extends GetxController {
TextEditingController checkTxtController = TextEditingController();
final formKey = GlobalKey<FormState>();
final formKey1 = GlobalKey<FormState>();
final emailTextController = TextEditingController();
Future deleteMyAccountDriver(String id) async {
await CRUD().post(link: AppLink.removeUser, payload: {'id': id}).then(
(value) => Get.snackbar('Deleted'.tr, 'Your Account is Deleted',
backgroundColor: AppColor.redColor));
}
checkBeforeDelete() async {
var res = await CRUD().post(
link: AppLink.deletecaptainAccounr,
payload: {'id': box.read(BoxName.driverID)});
return res['message'][0]['id'];
}
deletecaptainAccount() {
Get.defaultDialog(
backgroundColor: AppColor.yellowColor,
title: 'Are you sure to delete your account?'.tr,
middleText:
'Your data will be erased after 2 weeks\nAnd you will can\'t return to use app after 1 month ',
titleStyle: AppStyle.title,
content: Column(
children: [
Container(
width: Get.width,
decoration: AppStyle.boxDecoration,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Your data will be erased after 2 weeks\nAnd you will can\'t return to use app after 1 month'
.tr,
style: AppStyle.title.copyWith(color: AppColor.redColor),
),
),
),
const SizedBox(
height: 20,
),
Form(
key: formKey,
child: SizedBox(
width: Get.width,
child: MyTextForm(
controller: checkTxtController,
label: 'Enter Your First Name'.tr,
hint: 'Enter Your First Name'.tr,
type: TextInputType.name,
),
))
],
),
confirm: MyElevatedButton(
title: 'Delete'.tr,
onPressed: () async {
if (checkTxtController.text == (box.read(BoxName.nameDriver))) {
// deletecaptainAccount();
var id = await checkBeforeDelete();
deleteMyAccountDriver(id);
} else {
mySnackeBarError('Your Name is Wrong'.tr);
}
}));
}
Future logOutPassenger() async {
Get.defaultDialog(
title: 'Are you Sure to LogOut?'.tr,
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
MyElevatedButton(
title: 'Cancel'.tr,
onPressed: () => Get.back(),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(AppColor.redColor),
),
onPressed: () async {
// box.remove(BoxName.agreeTerms);
await box.erase();
await storage.deleteAll();
Get.offAll(OnBoardingPage());
},
child: Text(
'Sign Out'.tr,
style:
AppStyle.title.copyWith(color: AppColor.secondaryColor),
))
],
));
}
Future logOutCaptain() async {
Get.defaultDialog(
title: 'Are you Sure to LogOut?'.tr,
titleStyle: AppStyle.title,
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
MyElevatedButton(
title: 'Cancel'.tr,
onPressed: () => Get.back(),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(AppColor.redColor),
),
onPressed: () async {
// box.remove(BoxName.agreeTerms);
await box.erase();
await storage.deleteAll();
Get.offAll(OnBoardingPage());
},
child: Text(
'Sign Out'.tr,
style:
AppStyle.title.copyWith(color: AppColor.secondaryColor),
))
],
));
}
deletePassengerAccount() async {
if (formKey1.currentState!.validate()) {
if (box.read(BoxName.email).toString() == emailTextController.text) {
await CRUD().post(link: AppLink.passengerRemovedAccountEmail, payload: {
'email': box.read(BoxName.email),
});
} else {
mySnackeBarError(
'Email you inserted is Wrong.'.tr,
);
}
}
}
}

View File

@@ -0,0 +1,651 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:http/http.dart' as http;
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/constant/info.dart';
import 'package:sefer_driver/constant/style.dart';
import 'package:sefer_driver/constant/table_names.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../auth/captin/register_captin_controller.dart';
import 'launch.dart';
//
// class TextExtractionController extends GetxController {
// String extractedText = '';
// bool isloading = false;
// File? _scannedImage;
// // Convert the extracted text to JSON
// // Convert the extracted text to JSON
// String getTextAsJSON(String text) {
// final lines = text.split('\n');
// final jsonList = lines.map((line) {
// return {
// 'line_text': line,
// 'num_words': line.trim().split(' ').length,
// };
// }).toList();
//
// final json = {
// 'lines': jsonList,
// 'num_lines': lines.length,
// };
//
// return jsonEncode(json);
// }
//
// // Convert the extracted text to blocks by line
// List<String> getTextBlocks(String text) {
// return text.split('\n');
// }
//
// // Future<void> pickAndExtractText() async {
// // final pickedImage = await ImagePicker().pickImage(
// // source: ImageSource.camera,
// // preferredCameraDevice: CameraDevice.rear,
// // maxHeight: Get.height * .3,
// // maxWidth: Get.width * .8,
// // imageQuality: 99,
// // );
// // if (pickedImage != null) {
// // isloading = true;
// // update();
// // final imagePath = pickedImage.path;
// // final languages = [
// // 'eng',
// // 'ara'
// // ]; // Specify the languages you want to use for text extraction
//
// // try {
// // final text = await FlutterTesseractOcr.extractText(imagePath,
// // language:
// // languages.join('+'), // Combine multiple languages with '+'
// // args: {
// // "psm": "4",
// // "preserve_interword_spaces": "1",
// // // "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
// // } // Additional options if needed
// // );
// // isloading = false;
// // final jsonText = getTextAsJSON(text);
// // final textBlocks = getTextBlocks(text);
// // update();
// // extractedText =
// // textBlocks.toString(); // Convert the extracted text to JSON.
//
// // // Print the JSON to the console.
// // update();
// // } catch (e) {
// // extractedText = '';
// // }
// // }
// // }
// }
// class TextMLGoogleRecognizerController extends GetxController {
// @override
// void onInit() {
// scanText();
// super.onInit();
// }
//
// // The ImagePicker instance
// final ImagePicker _imagePicker = ImagePicker();
//
// // The GoogleMlKit TextRecognizer instance
// final TextRecognizer _textRecognizer = TextRecognizer();
//
// // The scanned text
// String? scannedText;
// String? jsonOutput;
// final List<Map<String, dynamic>> lines = [];
//
// Map decode = {};
//
// Future<void> scanText() async {
// // Pick an image from the camera or gallery
// final XFile? image =
// await _imagePicker.pickImage(source: ImageSource.gallery);
//
// // If no image was picked, return
// if (image == null) {
// return;
// }
//
// // Convert the XFile object to an InputImage object
// final InputImage inputImage = InputImage.fromFile(File(image.path));
//
// // Recognize the text in the image
// final RecognizedText recognizedText =
// await _textRecognizer.processImage(inputImage);
// scannedText = recognizedText.text;
// Map extractedData = {};
// // Extract the scanned text line by line
// for (var i = 0; i < recognizedText.blocks.length; i++) {
// final block = recognizedText.blocks[i];
// for (final line in block.lines) {
// final lineText = line.text;
//
// if (lineText.contains('DL')) {
// final dlNumber = lineText.split('DL')[1].trim();
// extractedData['dl_number'] = dlNumber;
// }
// if (lineText.contains('USA')) {
// final usa = lineText.split('USA')[1].trim();
// extractedData['USA'] = usa;
// }
// if (lineText.contains('DRIVER LICENSE')) {
// final driverl = lineText;
// extractedData['DRIVER_LICENSE'] = driverl;
// }
//
// if (lineText.contains('EXP')) {
// final expiryDate = lineText.split('EXP')[1].trim();
// extractedData['expiry_date'] = expiryDate;
// }
//
// if (lineText.contains('DOB')) {
// final dob = lineText.split('DOB')[1].trim();
// extractedData['dob'] = dob;
// }
//
// if (lineText.contains("LN")) {
// if ((lineText.indexOf("LN") == 0)) {
// final lastName = lineText.split('LN')[1].trim();
// extractedData['lastName'] = lastName;
// }
// }
// if (lineText.contains("FN")) {
// final firstName = lineText.split('FN')[1].trim();
// extractedData['firstName'] = firstName;
// }
// if (lineText.contains("RSTR")) {
// final rstr = lineText.split('RSTR')[1].trim();
// extractedData['rstr'] = rstr;
// }
// if (lineText.contains("CLASS")) {
// final class1 = lineText.split('CLASS')[1].trim();
// extractedData['class'] = class1;
// }
// if (lineText.contains("END")) {
// final end = lineText.split('END')[1].trim();
// extractedData['end'] = end;
// }
// if (lineText.contains("DD")) {
// final dd = lineText.split('DD')[1].trim();
// extractedData['dd'] = dd;
// }
// if (lineText.contains("EYES")) {
// final eyes = lineText.split('EYES')[1].trim();
// extractedData['eyes'] = eyes;
// }
// if (lineText.contains("SEX")) {
// final parts = lineText.split("SEX ")[1];
// extractedData['sex'] = parts[0];
// }
// if (lineText.contains("HAIR")) {
// final hair = lineText.split('HAIR')[1].trim();
// extractedData['hair'] = hair;
// }
//
// if (lineText.contains('STREET') || lineText.contains(',')) {
// final address = lineText;
// extractedData['address'] = address;
// }
//
// // Repeat this process for other relevant data fields
// }
// }
//
// // Convert the list of lines to a JSON string
// jsonOutput = jsonEncode(extractedData);
// decode = jsonDecode(jsonOutput!);
//
// update();
// }
// }
class ScanDocumentsByApi extends GetxController {
bool isLoading = false;
Map<String, dynamic> responseMap = {};
final ImagePicker imagePicker = ImagePicker();
late Uint8List imagePortrait;
late Uint8List imageSignature;
late Uint8List imageDocumentFrontSide;
XFile? image;
XFile? imagePortraitFile;
XFile? imageFace;
late File tempFile;
late String imagePath;
DateTime now = DateTime.now();
late String name;
late String licenseClass;
late String documentNo;
late String address;
late String stateCode;
late String height;
late String sex;
late String postalCode;
late String dob;
late String expireDate;
// ///////////////////////
// late CameraController cameraController;
// late List<CameraDescription> cameras;
// bool isCameraInitialized = false;
// // final TextRecognizer _textRecognizer = TextRecognizer();
// String? scannedText;
// Future<void> initializeCamera(int cameraID) async {
// try {
// cameras = await availableCameras();
// //update();
// cameraController = CameraController(
// cameras[cameraID],
// ResolutionPreset.medium,
// enableAudio: false,
// );
// await cameraController.initialize();
// isCameraInitialized = true;
// update();
// } catch (e) {
// if (e is CameraException) {
// switch (e.code) {
// case 'CameraAccessDenied':
// Get.defaultDialog(
// title: 'Camera Access Denied.'.tr,
// middleText: '',
// confirm:
// MyElevatedButton(title: 'Open Settings', onPressed: () {}),
// );
// break;
// default:
// // Handle other errors here.
// break;
// }
// }
// }
// }
///
Future<void> scanDocumentsByApi() async {
// String? visionApi = await storage.read(key: BoxName.visionApi);
// String? visionApi = AK.visionApi;
// Pick an image from the camera or gallery
image = await imagePicker.pickImage(source: ImageSource.camera); //
// If no image was picked, return
if (image == null) {
return;
}
isLoading = true;
update();
var headers = {'X-BLOBR-KEY': AK.visionApi};
var request = http.MultipartRequest('POST',
Uri.parse('https://api.faceonlive.com/j2y3q25y1b6maif1/api/iddoc'));
request.files.add(await http.MultipartFile.fromPath('image', image!.path));
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
String responseString = await response.stream.bytesToString();
responseMap = jsonDecode(responseString);
var ocrData = responseMap['data']['ocr'];
name = ocrData['name'].toString();
licenseClass = ocrData['dlClass'].toString();
documentNo = ocrData['documentNumber'].toString();
address = ocrData['address'].toString();
height = ocrData['height'].toString();
postalCode = ocrData['addressPostalCode'].toString();
sex = ocrData['sex'].toString();
stateCode = ocrData['addressJurisdictionCode'].toString();
expireDate = ocrData['dateOfExpiry'].toString();
dob = ocrData['dateOfBirth'].toString();
if (responseMap['data'] != null &&
responseMap['data']['image'] != null &&
responseMap['data']['image']['portrait'] != null) {
imagePortrait = base64Decode(responseMap['data']['image']['portrait']);
String tempPath = Directory.systemTemp.path;
tempFile = File('$tempPath/image.jpg');
await tempFile.writeAsBytes(imagePortrait);
imagePath = tempFile.path;
// imagePortraitFile=File(imagePath) ;
update();
} else {
// Handle error or provide a default value
}
if (responseMap['data']['image']['signature'] != null) {
imageSignature =
base64Decode(responseMap['data']['image']['signature']);
} else {
imageSignature = imagePortrait;
// Handle error or provide a default value
}
if (responseMap['data'] != null &&
responseMap['data']['image'] != null &&
responseMap['data']['image']['documentFrontSide'] != null) {
imageDocumentFrontSide =
base64Decode(responseMap['data']['image']['documentFrontSide']);
} else {
// Handle error or provide a default value
}
isLoading = false;
update();
} else {}
}
late int times;
Future checkMatchFaceApi() async {
sql.getAllData(TableName.faceDetectTimes).then((value) {
if (value.isEmpty || value == null) {
sql.insertData({'faceDetectTimes': 1}, TableName.faceDetectTimes);
sql.getAllData(TableName.faceDetectTimes).then((value) {
times = value[0]['faceDetectTimes'];
update();
});
} else {
if (times < 4) {
times++;
matchFaceApi();
sql.updateData(
{'faceDetectTimes': times}, TableName.faceDetectTimes, 1);
} else {
Get.defaultDialog(
barrierDismissible: false,
title: 'You have finished all times '.tr,
titleStyle: AppStyle.title,
middleText: 'if you want help you can email us here'.tr,
middleTextStyle: AppStyle.title,
cancel: MyElevatedButton(
title: 'Thanks'.tr,
kolor: AppColor.greenColor,
onPressed: () => Get.back(),
),
confirm: MyElevatedButton(
title: 'Email Us'.tr,
kolor: AppColor.yellowColor, //
onPressed: () {
launchCommunication('email', 'support@mobile-app.store',
'${'Hi'.tr} ${AppInformation.appName}\n${'I cant register in your app in face detection '.tr}');
Get.back();
},
));
}
}
});
}
Map res = {};
Future matchFaceApi() async {
// String? visionApi = await storage.read(key: BoxName.visionApi);
imageFace = await imagePicker.pickImage(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.front,
);
// If no image was picked, return
if (image == null) {
return;
}
final imageFile = File(imageFace!.path);
// Uint8List imageBytes = await imageFile.readAsBytes();
var headers = {'X-BLOBR-KEY': AK.visionApi};
var request = http.MultipartRequest(
'POST',
Uri.parse(
'https://api.faceonlive.com/sntzbspfsdupgid1/api/face_compare'));
request.files
.add(await http.MultipartFile.fromPath('image1', imageFile.path));
request.files.add(await http.MultipartFile.fromPath('image2', imagePath));
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
res = jsonDecode(await response.stream.bytesToString());
update();
res['data']['result'].toString().contains('No face detected in image')
? Get.defaultDialog(
barrierDismissible: false,
title: 'No face detected'.tr,
middleText: ''.tr,
titleStyle: AppStyle.title,
confirm: MyElevatedButton(
kolor: AppColor.yellowColor,
title: 'Back'.tr,
onPressed: () {
Get.back();
},
)) //
: Get.defaultDialog(
// barrierDismissible: false,
title: 'Image detecting result is '.tr,
titleStyle: AppStyle.title,
content: Column(
children: [
Text(
res['data']['result'].toString(),
style: res['data']['result'].toString() == 'Different'
? AppStyle.title.copyWith(color: AppColor.redColor)
: AppStyle.title.copyWith(color: AppColor.greenColor),
),
res['data']['result'].toString() == 'Different'
? Text(
'${'Be sure for take accurate images please\nYou have'.tr} $times ${'from 3 times Take Attention'.tr}',
style: AppStyle.title,
)
: Text(
'image verified'.tr,
style: AppStyle.title,
)
],
),
confirm: res['data']['result'].toString() == 'Different'
? MyElevatedButton(
title: 'Back'.tr,
onPressed: () => Get.back(),
kolor: AppColor.redColor,
)
: MyElevatedButton(
title: 'Next'.tr,
onPressed: () async {
RegisterCaptainController registerCaptainController =
Get.put(RegisterCaptainController());
await registerCaptainController.register();
await registerCaptainController.addLisence();
await uploadImagePortrate();
// Get.to(() => CarLicensePage());
},
// {
// await uploadImage(
// tempFile, AppLink.uploadImagePortrate);
// Get.to(() => CarLicensePage());
// },
kolor: AppColor.greenColor,
));
} else {}
}
// Todo upload images and fields
Future<String> uploadImagePortrate() async {
isLoading = true;
update();
var request = http.MultipartRequest(
'POST',
Uri.parse(AppLink.uploadImagePortrate),
);
request.files.add(
http.MultipartFile.fromBytes('image', imagePortrait),
);
request.headers.addAll({
"Content-Type": "multipart/form-data",
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
});
request.fields['driverID'] = box.read(BoxName.driverID).toString();
var response = await request.send();
var responseData = await response.stream.toBytes();
var responseString = String.fromCharCodes(responseData);
isLoading = false;
update();
// Print the response string
return responseString;
}
@override
void onInit() {
// scanDocumentsByApi();
// initializeCamera(0);
sql.getAllData(TableName.faceDetectTimes).then((value) {
if (value.isEmpty) {
times = 0;
update();
// sql.insertData({'faceDetectTimes': 1}, TableName.faceDetectTimes);
} else {
times = value[0]['faceDetectTimes'];
}
});
super.onInit();
}
}
// class PassportDataExtractor extends GetxController {
// @override
// void onInit() {
// extractPassportData();
// super.onInit();
// }
//
// final ImagePicker _imagePicker = ImagePicker();
// late final XFile? image;
// final TextRecognizer _textRecognizer = TextRecognizer();
//
// Future<Map<String, dynamic>> extractPassportData() async {
// image = await _imagePicker.pickImage(source: ImageSource.gallery);
// update();
// if (image == null) {
// throw Exception('No image picked');
// }
//
// final InputImage inputImage = InputImage.fromFile(File(image!.path));
// final RecognizedText recognisedText =
// await _textRecognizer.processImage(inputImage);
//
// final Map<String, dynamic> extractedData = {};
// final List<Map<String, dynamic>> extractedTextWithCoordinates = [];
//
// for (TextBlock block in recognisedText.blocks) {
// for (TextLine line in block.lines) {
// final String lineText = line.text;
// final Rect lineBoundingBox = line.boundingBox!;
//
// extractedTextWithCoordinates.add({
// 'text': lineText,
// 'boundingBox': {
// 'left': lineBoundingBox.left,
// 'top': lineBoundingBox.top,
// 'width': lineBoundingBox.width,
// 'height': lineBoundingBox.height,
// },
// });
//
// // if (lineText.contains('Passport Number')) {
// // final String passportNumber =
// // lineText.split('Passport Number')[1].trim();
// // extractedData['passportNumber'] = passportNumber;
// // }
// // if (lineText.contains('Given Names')) {
// // final String givenNames = lineText.split('Given Names')[1].trim();
// // extractedData['givenNames'] = givenNames;
// // }
// // if (lineText.contains('Surname')) {
// // final String surname = lineText.split('Surname')[1].trim();
// // extractedData['surname'] = surname;
// // }
// // if (lineText.contains('Nationality')) {
// // final String nationality = lineText.split('Nationality')[1].trim();
// // extractedData['nationality'] = nationality;
// // }
// // if (lineText.contains('Date of Birth')) {
// // final String dob = lineText.split('Date of Birth')[1].trim();
// // extractedData['dateOfBirth'] = dob;
// // }
// // Add more field extraction conditions as needed
// }
// }
//
// extractedData['extractedTextWithCoordinates'] =
// extractedTextWithCoordinates;
// return extractedData;
// }
// }
//
// class PassportDataController extends GetxController {
// PassportDataExtractor passportDataExtractor = PassportDataExtractor();
// List<Map<String, dynamic>> extractedTextWithCoordinates = [];
//
// Future<void> extractDataAndDrawBoundingBoxes() async {
// try {
// Map<String, dynamic> extractedData =
// await passportDataExtractor.extractPassportData();
// extractedTextWithCoordinates =
// extractedData['extractedTextWithCoordinates'];
// update(); // Notify GetX that the state has changed
// } catch (e) {
// }
// }
// }
//
// class BoundingBoxPainter extends CustomPainter {
// final List<Map<String, dynamic>> boundingBoxes;
//
// BoundingBoxPainter(this.boundingBoxes);
//
// @override
// void paint(Canvas canvas, Size size) {
// final Paint paint = Paint()
// ..color = Colors.red
// ..style = PaintingStyle.stroke
// ..strokeWidth = 2.0;
//
// for (Map<String, dynamic> boundingBox in boundingBoxes) {
// double left = boundingBox['left'];
// double top = boundingBox['top'];
// double width = boundingBox['width'];
// double height = boundingBox['height'];
//
// Rect rect = Rect.fromLTWH(left, top, width, height);
// canvas.drawRect(rect, paint);
// }
// }
//
// @override
// bool shouldRepaint(covariant CustomPainter oldDelegate) {
// return false;
// }
// }

View File

@@ -0,0 +1,114 @@
import 'dart:io';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import 'package:flutter/material.dart';
import 'package:flutter_confetti/flutter_confetti.dart';
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
import 'package:get/get.dart';
import 'package:location/location.dart';
import '../../constant/box_name.dart';
import '../../main.dart';
import '../auth/captin/login_captin_controller.dart';
import '../home/payment/captain_wallet_controller.dart';
Future<void> getPermissionOverlay() async {
if (Platform.isAndroid) {
final bool status = await FlutterOverlayWindow.isPermissionGranted();
if (status == false) {
MyDialog().getDialog(
'Allow overlay permission'.tr,
'To display orders instantly, please grant permission to draw over other apps.'
.tr,
() async {
Get.back();
await FlutterOverlayWindow.requestPermission();
},
);
}
}
}
Future<void> showDriverGiftClaim(BuildContext context) async {
if (box.read(BoxName.is_claimed).toString() == '0' ||
box.read(BoxName.is_claimed) == null) {
MyDialog().getDialog(
'You have gift 300 L.E'.tr, 'This for new registration'.tr, () async {
var res = await CRUD().post(link: AppLink.updateDriverClaim, payload: {
'driverId': box.read(BoxName.driverID),
});
if (res != 'failure') {
Get.find<CaptainWalletController>()
.addDriverWallet('new driver', '300', '300');
Confetti.launch(
context,
options:
const ConfettiOptions(particleCount: 100, spread: 70, y: 0.6),
);
box.write(BoxName.is_claimed, '1');
}
Get.back();
});
}
}
Future<void> closeOverlayIfFound() async {
if (Platform.isAndroid) {
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
}
}
final location = Location();
Future<void> getLocationPermission() async {
bool serviceEnabled;
PermissionStatus permissionGranted;
// Check if location services are enabled
serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) {
// Location services are still not enabled, handle the error
return;
}
}
// Check if the app has permission to access location
permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) {
// Location permission is still not granted, handle the error
permissionGranted = await location.requestPermission();
return;
}
}
if (permissionGranted.toString() == 'PermissionStatus.granted') {
box.write(BoxName.locationPermission, 'true');
Get.find<LoginDriverController>().update();
}
// update();
}
Future<void> getOverLay(String myListString) async {
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
await FlutterOverlayWindow.showOverlay(
enableDrag: true,
flag: OverlayFlag.focusPointer,
visibility: NotificationVisibility.visibilityPublic,
positionGravity: PositionGravity.auto,
height: 700,
width: WindowSize.matchParent,
startPosition: const OverlayPosition(0, -150),
);
await FlutterOverlayWindow.shareData(myListString);
}

View File

@@ -0,0 +1,360 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:ui';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:jailbreak_root_detection/jailbreak_root_detection.dart';
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:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../constant/info.dart';
import '../../main.dart';
import 'encrypt_decrypt.dart';
Future<void> checkForUpdate(BuildContext context) async {
final packageInfo = await PackageInfo.fromPlatform();
final currentVersion = packageInfo.buildNumber;
final version = packageInfo.version;
// print('currentVersion is : $currentVersion');
// Fetch the latest version from your server
String latestVersion = await getPackageInfo();
box.write(BoxName.packagInfo, version);
if (latestVersion.isNotEmpty && latestVersion != currentVersion) {
showUpdateDialog(context);
}
}
Future<String> getPackageInfo() async {
final response = await CRUD().get(link: AppLink.packageInfo, payload: {
"platform": Platform.isAndroid ? 'android' : 'ios',
"appName": AppInformation.appVersion,
});
if (response != 'failure') {
return jsonDecode(response)['message'][0]['version'];
}
return '';
}
void showUpdateDialog(BuildContext context) {
final String storeUrl = Platform.isAndroid
? 'https://play.google.com/store/apps/details?id=com.sefer_driver'
: 'https://apps.apple.com/ae/app/sefer-driver/id6502189302';
showGeneralDialog(
context: context,
barrierDismissible: false,
barrierColor: Colors.black.withOpacity(0.5),
pageBuilder: (_, __, ___) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Center(
child: AlertDialog(
// Using AlertDialog for a more Material Design look
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(16)), // More rounded corners
elevation: 4, // Add a bit more elevation
contentPadding: EdgeInsets.zero, // Remove default content padding
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Image.asset(
'assets/images/logo.png',
height: 72, // Slightly larger logo
width: 72,
),
),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Text(
'Update Available'.tr,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
// Use theme's title style
fontWeight: FontWeight.bold,
),
),
),
Padding(
padding: const EdgeInsets.all(24.0),
child: Text(
'A new version of the app is available. Please update to the latest version.'
.tr, // More encouraging message
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
// Use theme's body style
color: Colors.black87,
),
),
),
const Divider(height: 0),
Row(
children: [
Expanded(
child: TextButton(
// Using TextButton for "Cancel"
onPressed: () => Navigator.pop(context),
style: TextButton.styleFrom(
foregroundColor: Colors.grey,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(16),
),
),
),
child: Text('Cancel'.tr),
),
),
const SizedBox(
height: 48,
child: VerticalDivider(width: 0), // Using VerticalDivider
),
Expanded(
child: ElevatedButton(
// Using ElevatedButton for "Update"
onPressed: () async {
if (await canLaunchUrl(Uri.parse(storeUrl))) {
await launchUrl(Uri.parse(storeUrl));
}
if (context.mounted) Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColor
.primaryColor, // Use theme's primary color
foregroundColor: Theme.of(context)
.colorScheme
.onPrimary, // Use theme's onPrimary color
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(16),
),
),
),
child: Text('Update'.tr),
),
),
],
),
],
),
),
),
);
},
transitionBuilder: (_, animation, __, child) {
return ScaleTransition(
scale: CurvedAnimation(
parent: animation,
curve: Curves.easeOutCubic, // More natural curve
),
child: child,
);
},
);
}
class DeviceHelper {
static Future<String> getDeviceFingerprint() async {
final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
var deviceData;
try {
if (Platform.isAndroid) {
// Fetch Android-specific device information
AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo;
deviceData = androidInfo.toMap(); // Convert to a map for easier access
// Log.print('deviceData: ${jsonEncode(deviceData)}');
} else if (Platform.isIOS) {
// Fetch iOS-specific device information
IosDeviceInfo iosInfo = await deviceInfoPlugin.iosInfo;
deviceData = iosInfo.toMap(); // Convert to a map for easier access
} else {
throw UnsupportedError('Unsupported platform');
}
// Extract relevant device information
final String deviceId = Platform.isAndroid
? deviceData['androidId'] ?? deviceData['serialNumber'] ?? 'unknown'
: deviceData['identifierForVendor'] ?? 'unknown';
final String deviceModel = deviceData['model'] ?? 'unknown';
final String osVersion = Platform.isAndroid
? deviceData['version']['release'] ?? 'unknown'
: deviceData['systemVersion'] ?? 'unknown';
// Log the extracted information
// Generate and return the encrypted fingerprint
final String fingerprint = '${deviceId}_${deviceModel}_$osVersion';
// print(EncryptionHelper.instance.encryptData(fingerprint));
return (fingerprint);
} catch (e) {
throw Exception('Failed to generate device fingerprint');
}
}
}
class SecurityHelper {
/// Performs security checks and handles potential risks
static Future<void> performSecurityChecks() async {
bool isNotTrust = false;
bool isJailBroken = false;
bool isRealDevice = true;
bool isOnExternalStorage = false;
bool checkForIssues = false;
bool isDevMode = false;
bool isTampered = false;
String bundleId = "";
try {
isNotTrust = await JailbreakRootDetection.instance.isNotTrust;
isJailBroken = await JailbreakRootDetection.instance.isJailBroken;
isRealDevice = await JailbreakRootDetection.instance.isRealDevice;
isOnExternalStorage =
await JailbreakRootDetection.instance.isOnExternalStorage;
List<JailbreakIssue> issues =
await JailbreakRootDetection.instance.checkForIssues;
checkForIssues = issues.isNotEmpty;
isDevMode = await JailbreakRootDetection.instance.isDevMode;
// Get Bundle ID
PackageInfo packageInfo = await PackageInfo.fromPlatform();
bundleId = packageInfo.packageName;
if (bundleId.isNotEmpty) {
// Pass the CORRECT bundle ID to isTampered
isTampered = await JailbreakRootDetection.instance.isTampered(bundleId);
}
} catch (e) {
debugPrint("Error during security checks: $e");
// Consider handling specific exceptions, not just general errors.
}
// Save values to storage (using GetStorage)
await box.write('isNotTrust', isNotTrust); // Use await for write operations
await box.write('isTampered', isTampered); // Use await
await box.write('isJailBroken', isJailBroken); // Use await
// debugPrint("Security Check Results:");
// debugPrint("isNotTrust: $isNotTrust");
// debugPrint("isJailBroken: $isJailBroken");
// debugPrint("isRealDevice: $isRealDevice");
// debugPrint("isOnExternalStorage: $isOnExternalStorage");
// debugPrint("checkForIssues: $checkForIssues");
// debugPrint("isDevMode: $isDevMode");
// debugPrint("isTampered: $isTampered");
// debugPrint("Bundle ID: $bundleId"); // Print the bundle ID
// Check for security risks and potentially show a warning
if (isJailBroken || isRealDevice == false || isTampered) {
// print("security_warning".tr); //using easy_localization
// Use a more robust approach to show a warning, like a dialog:
_showSecurityWarning();
}
}
/// Deletes all app data
static Future<void> clearAllData() async {
//await storage.deleteAll(); // What's 'storage'? Be specific. Likely GetStorage as well.
await box.erase(); // Clear GetStorage data
exit(0); // This will terminate the app. Be VERY careful with this.
}
// static void _showSecurityWarning() {
// // Show a dialog, navigate to an error screen, etc.
// // Example using Get.dialog (if you use GetX):
//
// Get.dialog(
// AlertDialog(
// title: Text("Security Warning".tr), // Or use localized string
// content: Text(
// "Potential security risks detected. The application may not function correctly."
// .tr), //Or use localized string
// actions: [
// TextButton(
// onPressed: () async {
// await storage.deleteAll();
// await box.erase();
// Get.back(); // Close the dialog
// // Or, if you really must, exit the app (but give the user a chance!)
// exit(0);
// },
// child: Text("OK"), // Or use a localized string
// ),
// ],
// ),
// barrierDismissible: false, // Prevent closing by tapping outside
// );
// }
static void _showSecurityWarning() {
// Use an RxInt to track the remaining seconds. This is the KEY!
RxInt secondsRemaining = 10.obs;
Get.dialog(
CupertinoAlertDialog(
title: Text("Security Warning".tr),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Obx(() => Text(
"Potential security risks detected. The application will close in @seconds seconds."
.trParams({
// Use trParams for placeholders
'seconds': secondsRemaining.value.toString(),
}),
// Wrap the Text widget in Obx
)),
SizedBox(height: 24), // More spacing before the progress bar
Obx(() => SizedBox(
width: double.infinity, // Make progress bar full width
child: CupertinoActivityIndicator(
// in case of loading
radius: 15,
animating: true,
))),
SizedBox(height: 8),
Obx(() => ClipRRect(
borderRadius: BorderRadius.circular(8), // Rounded corners
child: LinearProgressIndicator(
value: secondsRemaining.value / 10,
backgroundColor: Colors.grey.shade300, // Lighter background
valueColor: AlwaysStoppedAnimation<Color>(
CupertinoColors.systemRed), // iOS-style red
minHeight: 8, // Slightly thicker progress bar
),
)),
],
),
),
barrierDismissible: false,
);
Timer.periodic(Duration(seconds: 1), (timer) {
secondsRemaining.value--;
if (secondsRemaining.value <= 0) {
timer.cancel();
// Get.back();
_clearDataAndExit();
}
});
}
static Future<void> _clearDataAndExit() async {
await storage.deleteAll();
await box.erase();
exit(0); // Exit the app
print('exit');
}
}

View File

@@ -0,0 +1,8 @@
// import 'package:ride/controller/functions/crud.dart';
// class RemoveAccount {
// void removeAccount()async{
// var res=await CRUD().post(link: link)
// }
// }

View File

@@ -0,0 +1,25 @@
// import 'package:credit_card_scanner/credit_card_scanner.dart';
// import 'package:get/get.dart';
//
// class ScanIdCard extends GetxController {
// CardDetails? _cardDetails;
// CardScanOptions scanOptions = const CardScanOptions(
// scanCardHolderName: true,
// enableDebugLogs: true,
// validCardsToScanBeforeFinishingScan: 5,
// possibleCardHolderNamePositions: [
// CardHolderNameScanPosition.aboveCardNumber,
// ],
// );
//
// Future<void> scanCard() async {
// final CardDetails? cardDetails =
// await CardScanner.scanCard(scanOptions: scanOptions);
// if (cardDetails == null) {
// return;
// }
//
// _cardDetails = cardDetails;
// update();
// }
// }

View File

@@ -0,0 +1,88 @@
import 'dart:convert';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:jwt_decoder/jwt_decoder.dart';
import 'package:secure_string_operations/secure_string_operations.dart';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/controller/functions/encrypt_decrypt.dart';
import '../../constant/box_name.dart';
import '../../constant/char_map.dart';
import '../../constant/info.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import 'crud.dart';
class SecureStorage {
final FlutterSecureStorage _storage = const FlutterSecureStorage();
void saveData(String key, value) async {
await _storage.write(key: key, value: value);
}
Future<String?> readData(String boxName) async {
final String? value = await _storage.read(key: boxName);
return value;
}
}
const List<String> keysToFetch = [
'serverPHP',
'seferAlexandriaServer',
'seferPaymentServer',
'seferCairoServer',
'seferGizaServer',
];
class AppInitializer {
List<Map<String, dynamic>> links = [];
Future<void> initializeApp() async {
if (box.read(BoxName.jwt) == null) {
await LoginDriverController().getJWT();
} else {
bool isTokenExpired = JwtDecoder.isExpired(X
.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs)
.toString()
.split(AppInformation.addd)[0]);
if (isTokenExpired) {
await LoginDriverController().getJWT();
}
}
// await getKey();
}
Future<void> getAIKey(String key1) async {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key1});
if (res != 'failure') {
var d = jsonDecode(res)['message'];
final rawValue = d[key1].toString();
// ✅ اكتبها في storage
await storage.write(key: key1, value: rawValue);
await Future.delayed(Duration.zero);
}
}
Future<void> getKey() async {
try {
var res =
await CRUD().get(link: AppLink.getLocationAreaLinks, payload: {});
if (res != 'failure') {
links = List<Map<String, dynamic>>.from(jsonDecode(res)['message']);
await box.write(BoxName.locationName, links);
await box.write(BoxName.basicLink, (links[0]['server_link']));
await box.write(links[2]['name'], (links[2]['server_link']));
await box.write(links[1]['name'], (links[3]['server_link']));
await box.write(links[3]['name'], (links[1]['server_link']));
await box.write(BoxName.paymentLink, (links[4]['server_link']));
}
} catch (e) {}
}
}

View File

@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
class SecurityChecks {
static const platform = MethodChannel(
'com.intaleq_driver/security'); // Choose a unique channel name
static Future<bool> isDeviceCompromised() async {
try {
final bool result = await platform
.invokeMethod('isNativeRooted'); // Invoke the native method
return result;
} on PlatformException catch (e) {
print("Failed to check security status: ${e.message}");
return true; // Treat platform errors as a compromised device (for safety)
}
}
static isDeviceRootedFromNative(BuildContext context) async {
bool compromised = await isDeviceCompromised();
if (compromised) {
showDialog(
barrierDismissible: false,
context: context,
builder: (context) => AlertDialog(
title: Text("Security Warning".tr),
content: Text(
"Your device appears to be compromised. The app will now close."
.tr),
actions: [
TextButton(
onPressed: () {
SystemNavigator.pop(); // Close the app
},
child: Text("OK"),
),
],
),
);
} else {
// Continue with normal app flow
print("Device is secure.");
}
}
}

View File

@@ -0,0 +1,104 @@
import 'dart:convert';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/info.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/auth/captin/register_captin_controller.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import '../auth/captin/login_captin_controller.dart';
import 'encrypt_decrypt.dart';
class SmsEgyptController extends GetxController {
var headers = {'Content-Type': 'application/json'};
Future<String> getSender() async {
var res = await CRUD().get(link: AppLink.getSender, payload: {});
if (res != 'failure') {
var d = jsonDecode(res)['message'][0]['senderId'].toString();
return d;
} else {
return "Sefer Egy";
}
}
Future<dynamic> sendSmsEgypt(String phone) async {
String sender = await getSender();
var body = jsonEncode({"receiver": "2$phone"});
var res = await http.post(
Uri.parse(AppLink.sendSms),
body: body,
headers: headers,
);
if (jsonDecode(res.body)['message'].toString() != "Success") {
await CRUD().post(link: AppLink.updatePhoneInvalidSMS, payload: {
"phone_number":
('+2${Get.find<RegisterCaptainController>().phoneController.text}')
});
box.write(BoxName.phoneDriver,
('+2${Get.find<RegisterCaptainController>().phoneController.text}'));
box.write(BoxName.phoneVerified, '1');
await Get.put(LoginDriverController()).loginWithGoogleCredential(
box.read(BoxName.driverID).toString(),
(box.read(BoxName.emailDriver).toString()),
);
} else {
Get.defaultDialog(
title: 'You will receive code in sms message'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'OK'.tr,
onPressed: () {
Get.back();
}));
}
}
Future checkCredit(String phone, otp) async {
var res = await http.post(
Uri.parse(AppLink.checkCredit),
body: {
"username": AppInformation.appName,
"password": AK.smsPasswordEgypt,
},
headers: headers,
);
}
Future sendSmsWithValidaty(String phone, otp) async {
var res = await http.post(
Uri.parse(AppLink.checkCredit),
body: {
"username": AppInformation.appName,
"password": AK.smsPasswordEgypt,
"message": "This is an example SMS message.",
"language": box.read(BoxName.lang) == 'en' ? "e" : 'r',
"sender": "Sefer", //"Kazumi", // todo add sefer sender name
"receiver": "2$phone",
"validity": "10",
"StartTime": DateTime.now().toString() // "1/1/2024 10:00:00"
},
headers: headers,
);
}
Future sendSmsStatus(String smsid) async {
var res = await http.post(
Uri.parse(AppLink.checkCredit),
body: {
"username": AppInformation.appName,
"password": AK.smsPasswordEgypt,
"smsid": smsid //"00b77dfc-5b8f-474d-9def-9f0158b70f98"
},
headers: headers,
);
}
}

View File

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/colors.dart';
import 'package:sefer_driver/constant/style.dart';
class Toast {
static void show(BuildContext context, String message, Color color) {
final snackBar = SnackBar(
clipBehavior: Clip.antiAliasWithSaveLayer,
backgroundColor: color,
elevation: 3,
content: Text(
message,
style: AppStyle.title.copyWith(color: AppColor.secondaryColor),
),
behavior: SnackBarBehavior.floating,
animation: const AlwaysStoppedAnimation(1.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0), // Custom border radius
),
width: Get.width * .8,
// shape: const StadiumBorder(
// side: BorderSide(
// color: AppColor.secondaryColor,
// width: 1.0,
// style: BorderStyle.solid,
// )),
duration: const Duration(seconds: 2),
);
ScaffoldMessenger.of(context).showSnackBar(
snackBar,
);
}
}

View File

@@ -0,0 +1,52 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';
import 'package:get/get.dart';
class TextToSpeechController extends GetxController {
final flutterTts = FlutterTts();
bool isComplete = false;
// Initialize TTS in initState
@override
void onInit() {
super.onInit();
initTts();
}
// Dispose of TTS when controller is closed
@override
void onClose() {
super.onClose();
flutterTts.completionHandler;
}
// Function to initialize TTS engine
Future<void> initTts() async {
String? lang =
WidgetsBinding.instance.platformDispatcher.locale.countryCode;
await flutterTts
.setLanguage(box.read(BoxName.lang).toString()); //'en-US' Set language
// await flutterTts.setLanguage('ar-SA'); //'en-US' Set language
// await flutterTts.setLanguage(lang!); //'en-US' Set language
await flutterTts.setSpeechRate(0.5); // Adjust speech rate
await flutterTts.setVolume(1.0); // Set volume
}
// Function to speak the given text
Future<void> speakText(String text) async {
try {
await flutterTts.awaitSpeakCompletion(true);
var result = await flutterTts.speak(text);
if (result == 1) {
// TTS operation has started
// You can perform additional operations here, if needed
isComplete = true;
update();
}
} catch (error) {
mySnackeBarError('Failed to speak text: $error');
}
}
}

View File

@@ -0,0 +1,22 @@
// import 'package:ride/constant/credential.dart';
// import 'package:twilio_flutter/twilio_flutter.dart';
//
// class TwilioSMS {
// TwilioFlutter twilioFlutter = TwilioFlutter(
// accountSid: AppCredintials.accountSIDTwillo,
// authToken: AppCredintials.authTokenTwillo,
// twilioNumber: '+962 7 9858 3052');
//
// Future<void> sendSMS({
// required String recipientPhoneNumber,
// required String message,
// }) async {
// try {
// await twilioFlutter.sendSMS(
// toNumber: recipientPhoneNumber,
// messageBody: message,
// );
// } catch (e) {
// }
// }
// }

View File

@@ -0,0 +1,552 @@
import 'dart:convert';
import 'dart:io';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart';
import 'package:image/image.dart' as img;
import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:path_provider/path_provider.dart' as path_provider;
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../main.dart';
import '../../print.dart';
import 'encrypt_decrypt.dart';
class ImageController extends GetxController {
File? myImage;
bool isloading = false;
CroppedFile? croppedFile;
final picker = ImagePicker();
var image;
Future<img.Image> detectAndCropDocument(File imageFile) async {
img.Image? image = img.decodeImage(await imageFile.readAsBytes());
if (image == null) throw Exception('Unable to decode image');
int left = image.width, top = image.height, right = 0, bottom = 0;
// Threshold for considering a pixel as part of the document (adjust as needed)
const int threshold = 240;
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++) {
final pixel = image.getPixel(x, y);
final luminance = img.getLuminance(pixel);
if (luminance < threshold) {
left = x < left ? x : left;
top = y < top ? y : top;
right = x > right ? x : right;
bottom = y > bottom ? y : bottom;
}
}
}
// Add a small padding
left = (left - 5).clamp(0, image.width);
top = (top - 5).clamp(0, image.height);
right = (right + 5).clamp(0, image.width);
bottom = (bottom + 5).clamp(0, image.height);
return img.copyCrop(image,
x: left, y: top, width: right - left, height: bottom - top);
}
Future<File> rotateImageIfNeeded(File imageFile) async {
img.Image croppedDoc = await detectAndCropDocument(imageFile);
// Check if the document is in portrait orientation
bool isPortrait = croppedDoc.height > croppedDoc.width;
img.Image processedImage;
if (isPortrait) {
// Rotate the image by 90 degrees clockwise
processedImage = img.copyRotate(croppedDoc, angle: 90);
} else {
processedImage = croppedDoc;
}
// Get temporary directory
final tempDir = await path_provider.getTemporaryDirectory();
final tempPath = tempDir.path;
// Create the processed image file
File processedFile = File('$tempPath/processed_image.jpg');
await processedFile.writeAsBytes(img.encodeJpg(processedImage));
return processedFile;
}
Future<File> rotateImage(File imageFile) async {
// Read the image file
img.Image? image = img.decodeImage(await imageFile.readAsBytes());
if (image == null) return imageFile;
// Rotate the image by 90 degrees clockwise
img.Image rotatedImage = img.copyRotate(image, angle: 90);
// Get temporary directory
final tempDir = await path_provider.getTemporaryDirectory();
final tempPath = tempDir.path;
// Create the rotated image file
File rotatedFile = File('$tempPath/rotated_image.jpg');
await rotatedFile.writeAsBytes(img.encodeJpg(rotatedImage));
return rotatedFile;
}
choosImage(String link, String imageType) async {
try {
final pickedImage = await picker.pickImage(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.rear,
);
if (pickedImage == null) return;
image = File(pickedImage.path);
croppedFile = await ImageCropper().cropImage(
sourcePath: image!.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Cropper'.tr,
toolbarColor: AppColor.blueColor,
toolbarWidgetColor: AppColor.yellowColor,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
),
IOSUiSettings(
title: 'Cropper'.tr,
),
],
);
if (croppedFile == null) return;
myImage = File(croppedFile!.path);
isloading = true;
update();
// Rotate the compressed image
File processedImage = await rotateImageIfNeeded(File(croppedFile!.path));
File compressedImage = await compressImage(processedImage);
print('link =$link');
// Log.print('link: ${link}');
//n8u22456
await uploadImage(
compressedImage,
{
'driverID':
box.read(BoxName.driverID) ?? box.read(BoxName.passengerID),
'imageType': imageType,
},
link,
);
} catch (e) {
print('Error in choosImage: $e');
mySnackeBarError('Image Upload Failed'.tr);
// Get.snackbar('Image Upload Failed'.tr, e.toString(),
// backgroundColor: AppColor.primaryColor);
} finally {
isloading = false;
update();
}
}
choosImageNewCAr(String link, String imageType) async {
try {
final pickedImage = await picker.pickImage(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.rear,
);
if (pickedImage == null) return;
image = File(pickedImage.path);
croppedFile = await ImageCropper().cropImage(
sourcePath: image!.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Cropper'.tr,
toolbarColor: AppColor.blueColor,
toolbarWidgetColor: AppColor.yellowColor,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false,
),
IOSUiSettings(
title: 'Cropper'.tr,
),
],
);
if (croppedFile == null) return;
myImage = File(croppedFile!.path);
isloading = true;
update();
// Rotate the compressed image
File processedImage = await rotateImageIfNeeded(File(croppedFile!.path));
File compressedImage = await compressImage(processedImage);
print('link =$link');
// Log.print('link: ${link}');
//n8u22456
await uploadNewCar(
compressedImage,
{
'driverID': box.read(BoxName.driverID) +
'_' +
DateTime.now().toIso8601String(),
'imageType': imageType,
},
link,
);
} catch (e) {
print('Error in choosImage: $e');
// Get.snackbar('Image Upload Failed'.tr, e.toString(),
// backgroundColor: AppColor.primaryColor);
mySnackeBarError('Image Upload Failed'.tr);
} finally {
isloading = false;
update();
}
}
// choosFaceFromDriverLicense(String link, String imageType) async {
// final pickedImage = await picker.pickImage(
// source: ImageSource.camera,
// preferredCameraDevice: CameraDevice.rear,
// );
// if (pickedImage == null) return;
// image = File(pickedImage.path);
// File? processedImage;
// // For face images, use face detection and cropping
// processedImage = await detectAndCropFace(image!);
// if (processedImage == null) {
// Get.snackbar('Face Detection Failed', 'No face detected in the image.');
// return;
// }
// isloading = true;
// update();
// File compressedImage = await compressImage(processedImage);
// try {
// await uploadImage(
// compressedImage,
// {
// 'driverID': box.read(BoxName.driverID).toString(),
// 'imageType': imageType
// },
// link,
// );
// } catch (e) {
// Get.snackbar('Image Upload Failed'.tr, e.toString(),
// backgroundColor: AppColor.redColor);
// } finally {
// isloading = false;
// update();
// }
// }
choosFace(String link, String imageType) async {
final pickedImage = await picker.pickImage(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.front,
);
if (pickedImage != null) {
image = File(pickedImage.path);
isloading = true;
update();
// Compress the image
File compressedImage = await compressImage(File(pickedImage.path));
// Save the picked image directly
// File savedImage = File(pickedImage.path);
print('link =$link');
try {
await uploadImage(
compressedImage,
{
'driverID':
box.read(BoxName.driverID) ?? box.read(BoxName.passengerID),
'imageType': imageType
},
link,
);
} catch (e) {
mySnackeBarError('Image Upload Failed'.tr);
// Get.snackbar('Image Upload Failed'.tr, e.toString(),
// backgroundColor: AppColor.redColor);
} finally {
isloading = false;
update();
}
}
}
uploadImage(File file, Map data, String link) async {
var request = http.MultipartRequest(
'POST',
Uri.parse(link),
);
Log.print('request: ${request}');
var length = await file.length();
var stream = http.ByteStream(file.openRead());
var multipartFile = http.MultipartFile(
'image',
stream,
length,
filename: basename(file.path),
);
request.headers.addAll({
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
});
// Set the file name to the driverID
request.files.add(
http.MultipartFile(
'image',
stream,
length,
filename: '${box.read(BoxName.driverID)}.jpg',
),
);
data.forEach((key, value) {
request.fields[key] = value;
});
var myrequest = await request.send();
var res = await http.Response.fromStream(myrequest);
if (res.statusCode == 200) {
Log.print('jsonDecode(res.body): ${jsonDecode(res.body)}');
return jsonDecode(res.body);
} else {
throw Exception(
'Failed to upload image: ${res.statusCode} - ${res.body}');
}
}
uploadNewCar(File file, Map data, String link) async {
var request = http.MultipartRequest(
'POST',
Uri.parse(link),
);
var length = await file.length();
var stream = http.ByteStream(file.openRead());
var multipartFile = http.MultipartFile(
'image',
stream,
length,
filename: basename(file.path),
);
request.headers.addAll({
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
});
// Set the file name to the driverID
request.files.add(
http.MultipartFile(
'image',
stream,
length,
filename: '${box.read(BoxName.driverID)}.jpg',
),
);
data.forEach((key, value) {
request.fields[key] = value;
});
var myrequest = await request.send();
var res = await http.Response.fromStream(myrequest);
if (res.statusCode == 200) {
Log.print('jsonDecode(res.body): ${jsonDecode(res.body)}');
return jsonDecode(res.body);
} else {
throw Exception(
'Failed to upload image: ${res.statusCode} - ${res.body}');
}
}
choosImagePicture(String link, String imageType) async {
final pickedImage = await picker.pickImage(
source: ImageSource.gallery,
// preferredCameraDevice: CameraDevice.rear,
// maxHeight: Get.height * .3,
// maxWidth: Get.width * .9,
// imageQuality: 100,
);
image = File(pickedImage!.path);
croppedFile = await ImageCropper().cropImage(
sourcePath: image!.path,
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Cropper'.tr,
toolbarColor: AppColor.blueColor,
toolbarWidgetColor: AppColor.yellowColor,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false),
IOSUiSettings(
title: 'Cropper'.tr,
),
],
);
myImage = File(pickedImage.path);
isloading = true;
update();
// Save the cropped image
// File savedCroppedImage = File(croppedFile!.path);
File compressedImage = await compressImage(File(croppedFile!.path));
print('link =$link');
try {
await uploadImage(
compressedImage,
{
'driverID':
(box.read(BoxName.driverID)) ?? (box.read(BoxName.passengerID)),
'imageType': imageType
},
link,
);
} catch (e) {
mySnackeBarError('Image Upload Failed'.tr);
// Get.snackbar('Image Upload Failed'.tr, e.toString(),
// backgroundColor: AppColor.redColor);
} finally {
isloading = false;
update();
}
}
uploadImagePicture(File file, Map data, String link) async {
var request = http.MultipartRequest(
'POST',
Uri.parse(link), //'https://ride.mobile-app.store/uploadImage1.php'
);
var length = await file.length();
var stream = http.ByteStream(file.openRead());
var multipartFile = http.MultipartFile(
'image',
stream,
length,
filename: basename(file.path),
);
request.headers.addAll({
'Authorization':
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
});
// Set the file name to the driverID
request.files.add(
http.MultipartFile(
'image',
stream,
length,
filename: '${(box.read(BoxName.driverID))}.jpg',
),
);
data.forEach((key, value) {
request.fields[key] = value;
});
var myrequest = await request.send();
var res = await http.Response.fromStream(myrequest);
if (res.statusCode == 200) {
return jsonDecode(res.body);
} else {
throw Exception(
'Failed to upload image: ${res.statusCode} - ${res.body}');
}
}
}
Future<File> compressImage(File file) async {
final dir = await path_provider.getTemporaryDirectory();
final targetPath = "${dir.absolute.path}/temp.jpg";
var result = await FlutterImageCompress.compressAndGetFile(
file.absolute.path,
targetPath,
quality: 70,
minWidth: 1024,
minHeight: 1024,
);
return File(result!.path);
}
// Future<File> detectAndCropFace(File imageFile) async {
// final inputImage = InputImage.fromFilePath(imageFile.path);
// final options = FaceDetectorOptions(
// enableClassification: false,
// enableLandmarks: false,
// enableTracking: false,
// minFaceSize: 0.15,
// performanceMode: FaceDetectorMode.accurate,
// );
// final faceDetector = FaceDetector(options: options);
// try {
// final List<Face> faces = await faceDetector.processImage(inputImage);
// final image = img.decodeImage(await imageFile.readAsBytes());
// if (image == null) throw Exception('Unable to decode image');
// int left, top, width, height;
// if (faces.isNotEmpty) {
// // Face detected, crop around the face
// final face = faces[0];
// double padding = 0.2; // 20% padding
// int paddingX = (face.boundingBox.width * padding).round();
// int paddingY = (face.boundingBox.height * padding).round();
// left = (face.boundingBox.left - paddingX).round();
// top = (face.boundingBox.top - paddingY).round();
// width = (face.boundingBox.width + 2 * paddingX).round();
// height = (face.boundingBox.height + 2 * paddingY).round();
// } else {
// // No face detected, crop the center of the image
// int size = min(image.width, image.height);
// left = (image.width - size) ~/ 2;
// top = (image.height - size) ~/ 2;
// width = size;
// height = size;
// }
// // Ensure dimensions are within image bounds
// left = left.clamp(0, image.width - 1);
// top = top.clamp(0, image.height - 1);
// width = width.clamp(1, image.width - left);
// height = height.clamp(1, image.height - top);
// final croppedImage =
// img.copyCrop(image, x: left, y: top, width: width, height: height);
// // Save the cropped image
// final tempDir = await path_provider.getTemporaryDirectory();
// final tempPath = tempDir.path;
// final croppedFile = File('$tempPath/cropped_image.jpg');
// await croppedFile.writeAsBytes(img.encodeJpg(croppedImage, quality: 100));
// return croppedFile;
// } finally {
// faceDetector.close();
// }
// }

View File

@@ -0,0 +1,15 @@
import 'package:get/get.dart';
import '../../constant/box_name.dart';
import '../../main.dart';
class HomePageController extends GetxController {
late bool isVibrate = box.read(BoxName.isvibrate) ?? true;
void changeVibrateOption(bool value) {
isVibrate = box.read(BoxName.isvibrate) ?? true;
isVibrate = value;
box.write(BoxName.isvibrate, value);
update();
}
}

View File

@@ -0,0 +1,115 @@
import 'dart:convert';
import 'dart:math';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import '../../../constant/table_names.dart';
import '../../../main.dart';
class DriverBehaviorController extends GetxController {
Future<List<Map<String, dynamic>>> getAllData() async {
return await sql.getAllData(TableName.behavior);
}
var isLoading = false.obs;
var overallScore = 100.0.obs;
var lastTrips = [].obs;
Future<void> fetchDriverBehavior() async {
isLoading.value = true;
try {
final response = await CRUD().get(
link: AppLink.get_driver_behavior,
payload: {"driver_id": box.read(BoxName.driverID).toString()},
);
if (response != 'failure') {
final json = jsonDecode(response.body);
overallScore.value =
double.parse(json['data']['overall_behavior_score'].toString());
lastTrips.value = json['data']['last_10_trips'];
} else {
// Get.snackbar("Error", json['message'] ?? "Unknown error");
}
} catch (e) {
Get.snackbar("Error", "Exception: $e");
} finally {
isLoading.value = false;
}
}
Future<Map<String, dynamic>> analyzeData() async {
final data = await getAllData();
if (data.isEmpty) return {};
double maxSpeed = 0;
double totalSpeed = 0;
int hardBrakes = 0;
double totalDistance = 0;
double? prevLat, prevLng;
for (var item in data) {
double speed = item['speed'] ?? 0;
double lat = item['lat'] ?? 0;
double lng = item['lng'] ?? 0;
double acc = item['acceleration'] ?? 0;
if (speed > maxSpeed) maxSpeed = speed;
totalSpeed += speed;
// ✅ Hard brake threshold
if (acc.abs() > 3.0) hardBrakes++;
// ✅ Distance between points
if (prevLat != null && prevLng != null) {
totalDistance += _calculateDistance(prevLat, prevLng, lat, lng);
}
prevLat = lat;
prevLng = lng;
}
double avgSpeed = totalSpeed / data.length;
double behaviorScore = 100 - (hardBrakes * 5) - ((maxSpeed > 100) ? 10 : 0);
behaviorScore = behaviorScore.clamp(0, 100);
return {
'max_speed': maxSpeed,
'avg_speed': avgSpeed,
'hard_brakes': hardBrakes,
'total_distance': totalDistance,
'behavior_score': behaviorScore,
};
}
Future<void> sendSummaryToServer(String driverId, String tripId) async {
final summary = await analyzeData();
if (summary.isEmpty) return;
final body = {
'driver_id': driverId,
'trip_id': tripId,
...summary,
};
CRUD().post(link: AppLink.saveBehavior, payload: (body));
await clearData();
}
Future<void> clearData() async {
await sql.deleteAllData(TableName.behavior);
}
double _calculateDistance(
double lat1, double lon1, double lat2, double lon2) {
const p = 0.017453292519943295;
final a = 0.5 -
cos((lat2 - lat1) * p) / 2 +
cos(lat1 * p) * cos(lat2 * p) * (1 - cos((lon2 - lon1) * p)) / 2;
return 12742 * asin(sqrt(a)); // distance in km
}
}

View File

@@ -0,0 +1,78 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_font_icons/flutter_font_icons.dart';
import 'package:get/get.dart';
import '../../../constant/colors.dart';
import '../../functions/launch.dart';
class ContactUsController extends GetxController {
final String phone1 = '+201018805430';
final String phone2 = '+201080182934';
final TimeOfDay workStartTime = const TimeOfDay(hour: 12, minute: 0);
final TimeOfDay workEndTime = const TimeOfDay(hour: 19, minute: 0);
bool _isWithinWorkTime(TimeOfDay now) {
return (now.hour > workStartTime.hour ||
(now.hour == workStartTime.hour &&
now.minute >= workStartTime.minute)) &&
(now.hour < workEndTime.hour ||
(now.hour == workEndTime.hour && now.minute <= workEndTime.minute));
}
void showContactDialog(BuildContext context) {
TimeOfDay now = TimeOfDay.now();
showCupertinoModalPopup(
context: context,
builder: (context) => CupertinoActionSheet(
title: Text('Contact Us'.tr),
message: Text('Choose a contact option'.tr),
actions: <Widget>[
if (_isWithinWorkTime(now))
CupertinoActionSheetAction(
child: Text(phone1),
onPressed: () => makePhoneCall(
phone1,
),
),
if (_isWithinWorkTime(now))
CupertinoActionSheetAction(
child: Text(phone2),
onPressed: () => makePhoneCall(phone2),
),
if (!_isWithinWorkTime(now))
CupertinoActionSheetAction(
child: Text(
'Work time is from 12:00 - 19:00.\nYou can send a WhatsApp message or email.'
.tr),
onPressed: () => Navigator.pop(context),
),
CupertinoActionSheetAction(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
const Icon(
FontAwesome.whatsapp,
color: AppColor.greenColor,
),
Text('Send WhatsApp Message'.tr),
],
),
onPressed: () =>
launchCommunication('whatsapp', phone1, 'Hello'.tr),
),
CupertinoActionSheetAction(
child: Text('Send Email'.tr),
onPressed: () =>
launchCommunication('email', 'support@sefer.live', 'Hello'.tr),
),
],
cancelButton: CupertinoActionSheetAction(
child: Text('Cancel'.tr),
onPressed: () => Navigator.pop(context),
),
),
);
}
}

View File

@@ -0,0 +1,150 @@
import 'dart:convert';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:fl_chart/fl_chart.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/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/models/model/driver/rides_summary_model.dart';
class DurationController extends GetxController {
final data = DurationData;
// late AnimationController animationController;
late List<MonthlyDataModel> rideData;
late List<MonthlyRideModel> rideCountData;
late List<MonthlyPriceDriverModel> ridePriceDriverData;
Map<String, dynamic> jsonData1 = {};
Map<String, dynamic> jsonData2 = {};
bool isLoading = false;
String totalDurationToday = '';
var chartData;
var chartRideCount;
var chartRidePriceDriver;
List monthlyList = [];
@override
void onInit() async {
super.onInit();
await fetchData();
await fetchRideDriver();
await getStaticDriver();
}
getStaticDriver() async {
isLoading = true;
update();
var res = await CRUD().get(
link: AppLink.driverStatistic,
payload: {'driverID': box.read(BoxName.driverID)});
if (res == 'failure') {
monthlyList = [];
isLoading = false;
update();
} else {
monthlyList = jsonDecode(res)['message'];
isLoading = false;
update();
}
}
Future<void> fetchData() async {
isLoading = true;
update(); // Notify the observers about the loading state change
var res = await CRUD().get(
link: AppLink.getTotalDriverDuration,
payload: {'driver_id': box.read(BoxName.driverID)},
);
jsonData1 = jsonDecode(res);
var jsonResponse = jsonDecode(res) as Map<String, dynamic>;
isLoading = false;
final List<dynamic> jsonData = jsonResponse['message'];
rideData = jsonData.map<MonthlyDataModel>((item) {
return MonthlyDataModel.fromJson(item);
}).toList();
final List<FlSpot> spots = rideData
.map((data) => FlSpot(
data.day.toDouble(),
data.totalDuration.toDouble(),
))
.toList();
chartData = spots;
update(); // Notify the observers about the data and loading state change
}
Future<void> fetchRideDriver() async {
isLoading = true;
update(); // Notify the observers about the loading state change
var res = await CRUD().get(
link: AppLink.getRidesDriverByDay,
payload: {'driver_id': box.read(BoxName.driverID)},
);
if (res != 'failure') {
jsonData2 = jsonDecode(res);
var jsonResponse = jsonDecode(res) as Map<String, dynamic>;
isLoading = false;
final List<dynamic> jsonData = jsonResponse['message'];
rideCountData = jsonData.map<MonthlyRideModel>((item) {
return MonthlyRideModel.fromJson(item);
}).toList();
ridePriceDriverData = jsonData.map<MonthlyPriceDriverModel>((item) {
return MonthlyPriceDriverModel.fromJson(item);
}).toList();
final List<FlSpot> spots = rideCountData
.map((data) => FlSpot(
data.day.toDouble(),
data.countRide.toDouble(),
))
.toList();
chartRideCount = spots;
final List<FlSpot> spotsDriverPrices = ridePriceDriverData
.map((data) => FlSpot(
data.day.toDouble(),
data.pricePerDay.toDouble(),
))
.toList();
chartRidePriceDriver = spotsDriverPrices;
update(); // Notify the observers about the data and loading state change
} else {
Get.defaultDialog(
title: 'No data yet!'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'OK'.tr,
onPressed: () {
Get.back();
Get.back();
}));
}
}
List<DurationData> parseData(List<dynamic> json) {
return json.map((entry) {
final Map<String, dynamic> entryMap = entry;
final day = DateTime.parse(entryMap['day']);
final totalDuration = _parseDuration(entryMap['total_duration']);
return DurationData(day, totalDuration);
}).toList();
}
Duration _parseDuration(String durationString) {
final parts = durationString.split(':');
final hours = int.parse(parts[0]);
final minutes = int.parse(parts[1]);
final seconds = int.parse(parts[2]);
return Duration(hours: hours, minutes: minutes, seconds: seconds);
}
}
class DurationData {
final DateTime day;
final Duration totalDuration;
DurationData(this.day, this.totalDuration);
}

View File

@@ -0,0 +1,58 @@
import 'dart:convert';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:get/get.dart';
class AssuranceHealthController extends GetxController {
bool isLoading = false;
Map tripCount = {};
Future getTripCountByCaptain() async {
var res = await CRUD().get(link: AppLink.getTripCountByCaptain, payload: {
"driver_id": box.read(BoxName.driverID).toString(),
});
if (res != 'failure') {
tripCount = jsonDecode(res)['message'];
update();
}
}
Future<void> addDriverHealthAssurance({
String? driverId,
String? assured,
required String healthInsuranceProvider,
}) async {
// Define the URL to your PHP backend
// Data to be sent to the backend
Map<String, String> data = {
"driver_id": box.read(BoxName.driverID).toString(),
"assured": '1',
"health_insurance_provider": healthInsuranceProvider,
};
try {
// Send the POST request to your backend
var response = await CRUD()
.post(link: AppLink.addHealthInsuranceProvider, payload: data);
if (response != 'failure') {
// Handle success (e.g., show a success message)
mySnackbarSuccess(
"You have successfully opted for health insurance.".tr);
} else {
// Handle failure (e.g., show an error message)
print("Failed to save health assurance data");
mySnackeBarError("Please enter a health insurance status.".tr);
}
} catch (e) {
// Handle any errors
print("Error: $e");
}
}
}

View File

@@ -0,0 +1,103 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../../constant/box_name.dart';
import '../../../../constant/links.dart';
import '../../../../constant/style.dart';
import '../../../../main.dart';
import '../../../../views/widgets/elevated_btn.dart';
import '../../../functions/crud.dart';
import '../../../functions/encrypt_decrypt.dart';
class HelpController extends GetxController {
bool isLoading = false;
final formKey = GlobalKey<FormState>();
final helpQuestionController = TextEditingController();
Map helpQuestionDate = {};
Map helpQuestionRepleyDate = {};
String status = '';
String qustion = '';
late int indexQuestion = 0;
getIndex(int i, String qustion1) async {
indexQuestion = i;
qustion = qustion1;
update();
}
void addHelpQuestion() async {
isLoading = true;
update();
var res = await CRUD().post(link: AppLink.addhelpCenter, payload: {
'driverID': box.read(BoxName.driverID).toString(),
'helpQuestion': (helpQuestionController.text)
});
var d = jsonDecode(res);
isLoading = false;
update();
if (d['status'].toString() == 'success') {
getHelpQuestion();
// Get.snackbar('Feedback data saved successfully'.tr, '',
// backgroundColor: AppColor.greenColor,
// snackPosition: SnackPosition.BOTTOM);
}
}
void getHelpQuestion() async {
isLoading = true;
update();
var res = await CRUD().get(link: AppLink.gethelpCenter, payload: {
'driverID': box.read(BoxName.driverID).toString(),
});
if (res == "failure") {
isLoading = false;
update();
Get.defaultDialog(
title: 'There is no help Question here'.tr,
titleStyle: AppStyle.title,
middleText: '',
confirm: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
MyElevatedButton(
title: 'Add Question'.tr,
onPressed: () {
Get.back();
}),
MyElevatedButton(
title: 'Back'.tr,
onPressed: () {
Get.back();
Get.back();
}),
],
));
}
helpQuestionDate = jsonDecode(res);
isLoading = false;
update();
}
Future getHelpRepley(String id) async {
isLoading = true;
update();
var res = await CRUD().get(link: AppLink.getByIdhelpCenter, payload: {
'id': id,
});
if (res == "failure") {
status = 'not yet';
isLoading = false;
update();
}
helpQuestionRepleyDate = jsonDecode(res);
isLoading = false;
update();
}
@override
void onInit() {
getHelpQuestion();
super.onInit();
}
}

View File

@@ -0,0 +1,22 @@
import 'dart:convert';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:get/get.dart';
class MaintainCenterController extends GetxController {
bool isLoading = false;
Map tripCount = {};
Future getTripCountByCaptain() async {
var res = await CRUD().get(link: AppLink.getTripCountByCaptain, payload: {
"driver_id": box.read(BoxName.driverID).toString(),
});
if (res != 'failure') {
tripCount = jsonDecode(res)['message'];
update();
}
}
}

View File

@@ -0,0 +1,69 @@
import 'dart:convert';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/print.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:get/get.dart';
import 'package:video_player/video_player.dart';
class VideoController extends GetxController {
var videos = [];
var isLoading = true.obs;
final String apiUrl =
'${AppLink.seferCairoServer}/ride/videos_driver/get.php';
@override
void onInit() {
fetchVideos();
super.onInit();
}
late VideoPlayerController videoPlayerController;
// Initialize the video player with the provided URL
Future<void> initializeVideo(String videoUrl) async {
videoPlayerController =
VideoPlayerController.networkUrl(Uri.parse(videoUrl));
await videoPlayerController.initialize();
videoPlayerController
.setLooping(true); // Set to true if you want the video to loop
update(); // Update the UI after the video has been initialized
}
// Play the video
void play() {
videoPlayerController.play();
update();
}
// Pause the video
void pause() {
videoPlayerController.pause();
update();
}
@override
void onClose() {
videoPlayerController
.dispose(); // Dispose of the video player controller when not in use
super.onClose();
}
void fetchVideos() async {
try {
var res = await CRUD().get(link: apiUrl, payload: {});
if (res != 'failure') {
videos = jsonDecode(res)['message'];
// Log.print('videos: ${videos}');
update();
} else {
mySnackeBarError('');
}
} catch (e) {
mySnackeBarError(e.toString());
} finally {
isLoading(false);
}
}
}

View File

@@ -0,0 +1,454 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/controller/home/captin/map_driver_controller.dart';
import 'dart:async';
import '../../../constant/links.dart';
import '../../../constant/style.dart';
import '../../../constant/table_names.dart';
import '../../../main.dart';
import '../../../print.dart';
import '../../../views/home/my_wallet/walet_captain.dart';
import '../../../views/widgets/elevated_btn.dart';
import '../../firebase/firbase_messge.dart';
import '../../functions/crud.dart';
import '../../functions/location_background_controller.dart';
import '../../functions/location_controller.dart';
import '../payment/captain_wallet_controller.dart';
class HomeCaptainController extends GetxController {
bool isActive = false;
DateTime? activeStartTime;
Duration activeDuration = Duration.zero;
Timer? activeTimer;
Map data = {};
BitmapDescriptor carIcon = BitmapDescriptor.defaultMarker;
bool isLoading = true;
late double kazan = 0;
double latePrice = 0;
double heavyPrice = 0;
double comfortPrice = 0,
speedPrice = 0,
deliveryPrice = 0,
mashwariPrice = 0,
fuelPrice = 0;
double naturePrice = 0;
bool isCallOn = false;
String totalMoneyToday = '0';
double? rating = 5;
String rideId = '0';
String countRideToday = '0';
String totalMoneyInSEFER = '0';
String totalDurationToday = '0';
Timer? timer;
late LatLng myLocation = const LatLng(32, 36);
String totalPoints = '0';
String countRefuse = '0';
bool mapType = false;
bool mapTrafficON = false;
double widthMapTypeAndTraffic = 50;
// Inject the LocationController class
final locationController = Get.put(LocationController());
// final locationBackController = Get.put(LocationBackgroundController());
String formatDuration(Duration duration) {
String twoDigits(int n) => n.toString().padLeft(2, "0");
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
return "${duration.inHours}:$twoDigitMinutes:$twoDigitSeconds";
}
void goToWalletFromConnect() {
Get.back();
Get.back();
Get.to(() => WalletCaptainRefactored());
}
void changeRideId() {
rideId = 'rideId';
update();
}
void addCustomCarIcon() {
ImageConfiguration config = ImageConfiguration(
size: const Size(30, 35), devicePixelRatio: Get.pixelRatio);
BitmapDescriptor.asset(
config,
'assets/images/car.png',
// mipmaps: false,
).then((value) {
carIcon = value;
update();
});
}
String stringActiveDuration = '';
void onButtonSelected() {
// totalPoints = Get.find<CaptainWalletController>().totalPoints;
isActive = !isActive;
if (isActive) {
if (double.parse(totalPoints) > -300) {
locationController.startLocationUpdates();
HapticFeedback.heavyImpact();
// locationBackController.startBackLocation();
activeStartTime = DateTime.now();
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
activeDuration = DateTime.now().difference(activeStartTime!);
stringActiveDuration = formatDuration(activeDuration);
update();
});
} else {
locationController.stopLocationUpdates();
activeStartTime = null;
activeTimer?.cancel();
savePeriod(activeDuration);
activeDuration = Duration.zero;
update();
}
} else {
locationController.stopLocationUpdates();
activeStartTime = null;
activeTimer?.cancel();
savePeriod(activeDuration);
activeDuration = Duration.zero;
update();
}
// }
}
void getRefusedOrderByCaptain() async {
DateTime today = DateTime.now();
int todayDay = today.day;
String driverId = box.read(BoxName.driverID).toString();
String customQuery = '''
SELECT COUNT(*) AS count
FROM ${TableName.driverOrdersRefuse}
WHERE driver_id = '$driverId'
AND created_at LIKE '%$todayDay%'
''';
try {
List<Map<String, dynamic>> results =
await sql.getCustomQuery(customQuery);
countRefuse = results[0]['count'].toString();
update();
if (int.parse(countRefuse) > 3 || double.parse(totalPoints) <= -3000) {
locationController.stopLocationUpdates();
activeStartTime = null;
activeTimer?.cancel();
savePeriod(activeDuration);
activeDuration = Duration.zero;
update();
Get.defaultDialog(
// backgroundColor: CupertinoColors.destructiveRed,
barrierDismissible: false,
title: 'You Are Stopped For this Day !'.tr,
content: Text(
'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
.tr,
style: AppStyle.title,
),
confirm: MyElevatedButton(
title: 'Ok , See you Tomorrow'.tr,
onPressed: () {
Get.back();
Get.back();
}));
}
} catch (e) {}
}
void changeMapType() {
mapType = !mapType;
// heightButtomSheetShown = isButtomSheetShown == true ? 240 : 0;
update();
}
void changeMapTraffic() {
mapTrafficON = !mapTrafficON;
update();
}
// late GoogleMapController mapHomeCaptainController;
// void onMapCreated(GoogleMapController controller) {
// mapHomeCaptainController = controller;
// controller.getVisibleRegion();
// // Animate camera to user location (optional)
// controller.animateCamera(
// CameraUpdate.newLatLng(Get.find<LocationController>().myLocation),
// );
// }
GoogleMapController? mapHomeCaptainController; // Nullable controller
void onMapCreated(GoogleMapController controller) {
mapHomeCaptainController = controller;
// Optional: Check if the controller is still null (just for safety)
if (mapHomeCaptainController != null) {
// Get the visible region
controller.getVisibleRegion();
// Animate camera to user location (optional)
controller.animateCamera(
CameraUpdate.newLatLng(Get.find<LocationController>().myLocation),
);
} else {}
}
void savePeriod(Duration period) {
final periods = box.read<List<dynamic>>(BoxName.periods) ?? [];
periods.add(period.inSeconds);
box.write(BoxName.periods, periods);
}
Duration calculateTotalDuration() {
final periods = box.read<List<dynamic>>(BoxName.periods) ?? [];
Duration totalDuration = Duration.zero;
for (dynamic periodInSeconds in periods) {
final periodDuration = Duration(seconds: periodInSeconds);
totalDuration += periodDuration;
}
return totalDuration;
}
void startPeriodicExecution() {
Timer.periodic(const Duration(seconds: 30), (timer) async {
await getCaptainDurationOnToday();
});
}
void stopTimer() {
timer?.cancel();
}
getlocation() async {
isLoading = true;
update();
await Get.find<LocationController>().getLocation();
isLoading = false;
update();
}
Map walletDriverPointsDate = {};
Future getCaptainWalletFromBuyPoints() async {
// isLoading = true;
update();
var res = await CRUD().get(
link: AppLink.getDriverPaymentPoints,
payload: {'driverID': box.read(BoxName.driverID).toString()},
);
isLoading = false;
// update();
if (res != 'failure') {
walletDriverPointsDate = jsonDecode(res);
double totalPointsDouble = double.parse(
walletDriverPointsDate['message'][0]['total_amount'].toString());
totalPoints = totalPointsDouble.toStringAsFixed(0);
update();
} else {
totalPoints = '0';
}
}
@override
void onInit() async {
// await locationBackController.requestLocationPermission();
Get.put(FirebaseMessagesController());
addToken();
await getlocation();
onButtonSelected();
getDriverRate();
addCustomCarIcon();
getKazanPercent();
getPaymentToday();
getCountRideToday();
getAllPayment();
startPeriodicExecution();
getCaptainWalletFromBuyPoints();
onMapCreated(mapHomeCaptainController!);
// totalPoints = Get.find<CaptainWalletController>().totalPoints.toString();
getRefusedOrderByCaptain();
// LocationController().getLocation();
super.onInit();
}
// void getRefusedOrderByCaptain() async {
// // Get today's date in YYYY-MM-DD format
// String today = DateTime.now().toString().substring(0, 10);
// String driverId = box.read(BoxName.driverID).toString();
// String customQuery = '''
// SELECT COUNT(*) AS count
// FROM ${TableName.driverOrdersRefuse}
// WHERE driver_id = '$driverId'
// AND DATE(created_at) = '$today'
// ''';
// try {
// List<Map<String, dynamic>> results =
// await sql.getCustomQuery(customQuery);
// countRefuse = results[0]['count'].toString();
// update();
// if (int.parse(countRefuse) > 3) {
// box.write(BoxName.statusDriverLocation, 'on');
// locationController.stopLocationUpdates();
// Get.defaultDialog(
// // backgroundColor: CupertinoColors.destructiveRed,
// barrierDismissible: false,
// title: 'You Are Stopped For this Day !'.tr,
// content: Text(
// 'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
// .tr,
// style: AppStyle.title,
// ),
// confirm: MyElevatedButton(
// title: 'Ok , See you Tomorrow'.tr,
// onPressed: () => Get.back()));
// } else {
// box.write(BoxName.statusDriverLocation, 'off');
// }
// } catch (e) {}
// }
addToken() async {
String? fingerPrint = await storage.read(key: BoxName.fingerPrint);
CRUD().post(link: AppLink.addTokensDriver, payload: {
'token': (box.read(BoxName.tokenDriver)),
'captain_id': (box.read(BoxName.driverID)).toString(),
'fingerPrint': (fingerPrint).toString()
});
// CRUD().post(
// link: "${AppLink.seferAlexandriaServer}/ride/firebase/addDriver.php",
// payload: {
// 'token': box.read(BoxName.tokenDriver),
// 'captain_id': box.read(BoxName.driverID).toString(),
// 'fingerPrint': (fingerPrint).toString()
// });
// CRUD().post(
// link: "${AppLink.seferGizaServer}/ride/firebase/addDriver.php",
// payload: {
// 'token': box.read(BoxName.tokenDriver),
// 'captain_id': box.read(BoxName.driverID).toString(),
// 'fingerPrint': (fingerPrint).toString()
// });
await CRUD().postWallet(
link: "${AppLink.seferPaymentServer}/ride/firebase/addDriver.php",
payload: {
'token': box.read(BoxName.tokenDriver),
'captain_id': box.read(BoxName.driverID).toString(),
'fingerPrint': (fingerPrint).toString()
});
// MapDriverController().driverCallPassenger();
// box.write(BoxName.statusDriverLocation, 'off');
}
getPaymentToday() async {
var res = await CRUD().get(
link: AppLink.getDriverPaymentToday,
payload: {'driverID': box.read(BoxName.driverID).toString()});
if (res != 'failure') {
data = jsonDecode(res);
totalMoneyToday = data['message'][0]['todayAmount'].toString();
update();
} else {}
}
getKazanPercent() async {
var res = await CRUD().get(
link: AppLink.getKazanPercent,
payload: {'country': box.read(BoxName.countryCode).toString()},
);
if (res != 'failure') {
var json = jsonDecode(res);
kazan = double.parse(json['message'][0]['kazan']);
naturePrice = double.parse(json['message'][0]['naturePrice']);
heavyPrice = double.parse(json['message'][0]['heavyPrice']);
latePrice = double.parse(json['message'][0]['latePrice']);
comfortPrice = double.parse(json['message'][0]['comfortPrice']);
speedPrice = double.parse(json['message'][0]['speedPrice']);
deliveryPrice = double.parse(json['message'][0]['deliveryPrice']);
mashwariPrice = double.parse(json['message'][0]['freePrice']);
fuelPrice = double.parse(json['message'][0]['fuelPrice']);
}
update();
}
double mpg = 0;
calculateConsumptionFuel() {
mpg = fuelPrice / 12; //todo in register car add mpg in box
}
getCountRideToday() async {
var res = await CRUD().get(
link: AppLink.getCountRide,
payload: {'driver_id': box.read(BoxName.driverID).toString()});
data = jsonDecode(res);
countRideToday = data['message'][0]['count'].toString();
update();
}
getDriverRate() async {
var res = await CRUD().get(
link: AppLink.getDriverRate,
payload: {'driver_id': box.read(BoxName.driverID).toString()});
if (res != 'failure') {
var decod = jsonDecode(res);
if (decod['message'][0]['rating'] != null) {
rating = double.parse(decod['message'][0]['rating'].toString());
} else {
rating = 5.0; // Set a default value (e.g., 5.0 for full rating)
}
} else {
rating = 5;
}
}
getAllPayment() async {
var res = await CRUD().get(
link: AppLink.getAllPaymentFromRide,
payload: {'driverID': box.read(BoxName.driverID).toString()});
data = jsonDecode(res);
totalMoneyInSEFER = data['message'][0]['total_amount'] ?? '0';
update();
}
void changeToAppliedRide(String status) {
box.write(BoxName.rideStatus, status);
Log.print('rideStatus from homcaptain : ${box.read(BoxName.rideStatus)}');
update();
}
Future<void> getCaptainDurationOnToday() async {
var res = await CRUD().get(
link: AppLink.getTotalDriverDurationToday,
payload: {'driver_id': box.read(BoxName.driverID).toString()});
data = jsonDecode(res);
totalDurationToday = data['message'][0]['total_duration'];
update();
}
@override
void dispose() {
activeTimer?.cancel();
stopTimer();
super.dispose();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,282 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter_overlay_window/flutter_overlay_window.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/main.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'dart:math' as math;
import '../../../constant/box_name.dart';
import '../../../print.dart';
import '../../functions/audio_controller.dart';
import '../../functions/crud.dart';
import '../../functions/encrypt_decrypt.dart';
import '../../functions/location_controller.dart';
import 'home_captain_controller.dart';
class OrderRequestController extends GetxController {
double progress = 0;
double progressSpeed = 0;
int duration = 15;
int durationSpeed = 20;
int remainingTime = 0;
int remainingTimeSpeed = 0;
String countRefuse = '0';
bool applied = false;
final locationController = Get.put(LocationController());
BitmapDescriptor startIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor endIcon = BitmapDescriptor.defaultMarker;
final arguments = Get.arguments;
var myList;
late int hours;
late int minutes;
GoogleMapController? mapController; // Make it nullable
@override
Future<void> onInit() async {
print('OrderRequestController onInit called');
await initializeOrderPage();
bool isOverlayActive = await FlutterOverlayWindow.isActive();
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
addCustomStartIcon();
addCustomEndIcon();
startTimer(
myList[6].toString(),
myList[16].toString(),
);
update();
super.onInit();
}
late LatLngBounds bounds;
late List<LatLng> pointsDirection;
late String body;
late double latPassengerLocation;
late double lngPassengerLocation;
late double lngPassengerDestination;
late double latPassengerDestination;
Future<void> initializeOrderPage() async {
final myListString = Get.arguments['myListString'];
if (Get.arguments['DriverList'] == null ||
Get.arguments['DriverList'].isEmpty) {
myList = jsonDecode(myListString);
Log.print('myList from myListString: ${myList}');
} else {
myList = Get.arguments['DriverList'];
Log.print('myList from DriverList: ${myList}');
}
body = Get.arguments['body'];
Duration durationToAdd =
Duration(seconds: (double.tryParse(myList[4]) ?? 0).toInt());
hours = durationToAdd.inHours;
minutes = (durationToAdd.inMinutes % 60).round();
startTimerSpeed(myList[6].toString(), body.toString());
// --- Using the provided logic for initialization ---
var cords = myList[0].toString().split(',');
var cordDestination = myList[1].toString().split(',');
double? parseDouble(String value) {
try {
return double.parse(value);
} catch (e) {
Log.print("Error parsing value: $value");
return null; // or handle the error appropriately
}
}
latPassengerLocation = parseDouble(cords[0]) ?? 0.0;
lngPassengerLocation = parseDouble(cords[1]) ?? 0.0;
latPassengerDestination = parseDouble(cordDestination[0]) ?? 0.0;
lngPassengerDestination = parseDouble(cordDestination[1]) ?? 0.0;
pointsDirection = [
LatLng(latPassengerLocation, lngPassengerLocation),
LatLng(latPassengerDestination, lngPassengerDestination)
];
Log.print('pointsDirection: $pointsDirection');
calculateBounds();
update();
}
void onMapCreated(GoogleMapController controller) {
mapController = controller;
animateCameraToBounds();
}
void calculateBounds() {
double minLat = math.min(latPassengerLocation, latPassengerDestination);
double maxLat = math.max(latPassengerLocation, latPassengerDestination);
double minLng = math.min(lngPassengerLocation, lngPassengerDestination);
double maxLng = math.max(lngPassengerLocation, lngPassengerDestination);
bounds = LatLngBounds(
southwest: LatLng(minLat, minLng),
northeast: LatLng(maxLat, maxLng),
);
Log.print('Calculated Bounds: $bounds');
}
void animateCameraToBounds() {
if (mapController != null) {
mapController!.animateCamera(CameraUpdate.newLatLngBounds(bounds, 80.0));
} else {
Log.print('mapController is null, cannot animate camera.');
}
}
getRideDEtailsForBackgroundOrder(String rideId) async {
await CRUD().get(link: AppLink.getRidesDetails, payload: {
'id': rideId,
});
}
void addCustomStartIcon() async {
ImageConfiguration config = const ImageConfiguration(size: Size(30, 30));
BitmapDescriptor.asset(
config,
'assets/images/A.png',
).then((value) {
startIcon = value;
update();
});
}
void addCustomEndIcon() {
ImageConfiguration config = const ImageConfiguration(size: Size(30, 30));
BitmapDescriptor.asset(
config,
'assets/images/b.png',
).then((value) {
endIcon = value;
update();
});
}
void changeApplied() {
applied = true;
update();
}
double mpg = 0;
calculateConsumptionFuel() {
mpg = Get.find<HomeCaptainController>().fuelPrice / 12;
}
bool _timerActive = false;
Future<void> startTimer(String driverID, String orderID) async {
_timerActive = true;
for (int i = 0; i <= duration && _timerActive; i++) {
await Future.delayed(const Duration(seconds: 1));
progress = i / duration;
remainingTime = duration - i;
update();
}
if (remainingTime == 0 && _timerActive) {
if (applied == false) {
endTimer();
refuseOrder(orderID);
}
}
}
void endTimer() {
_timerActive = false;
}
void startTimerSpeed(String driverID, orderID) async {
for (int i = 0; i <= durationSpeed; i++) {
await Future.delayed(const Duration(seconds: 1));
progressSpeed = i / durationSpeed;
remainingTimeSpeed = durationSpeed - i;
update();
}
if (remainingTimeSpeed == 0) {
if (applied == false) {
Get.back();
}
}
}
void refuseOrder(
orderID,
) async {
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
'driver_id': box.read(BoxName.driverID),
'order_id': (orderID),
'status': 'Refused'
});
await CRUD().post(link: AppLink.updateRides, payload: {
'id': (orderID),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
if (AppLink.endPoint != AppLink.seferCairoServer) {
CRUD().post(link: '${AppLink.endPoint}/rides/update.php', payload: {
'id': (orderID),
'status': 'Refused',
'driver_id': box.read(BoxName.driverID),
});
}
update();
}
addRideToNotificationDriverString(
orderID,
String startLocation,
String endLocation,
String date,
String time,
String price,
String passengerId,
String status,
String carType,
String passengerRate,
String priceForPassenger,
String distance,
String duration,
) async {
await CRUD().post(link: AppLink.addWaitingRide, payload: {
'id': (orderID),
'start_location': startLocation,
'end_location': endLocation,
'date': date,
'time': time,
'price': price,
'passenger_id': (passengerId),
'status': status,
'carType': carType,
'passengerRate': passengerRate,
'price_for_passenger': priceForPassenger,
'distance': distance,
'duration': duration,
});
if (AppLink.endPoint != AppLink.seferCairoServer) {
CRUD().post(
link: '${AppLink.endPoint}/notificationCaptain/addWaitingRide.php',
payload: {
'id': (orderID),
'start_location': startLocation,
'end_location': endLocation,
'date': date,
'time': time,
'price': price,
'passenger_id': (passengerId),
'status': status,
'carType': carType,
'passengerRate': passengerRate,
'price_for_passenger': priceForPassenger,
'distance': distance,
'duration': duration,
});
}
}
}

View File

@@ -0,0 +1,14 @@
import 'package:get/get.dart';
class MyMenuController extends GetxController {
bool isDrawerOpen = true;
void getDrawerMenu() {
if (isDrawerOpen == true) {
isDrawerOpen = false;
} else {
isDrawerOpen = true;
}
update();
}
}

View File

@@ -0,0 +1,363 @@
import 'dart:convert';
import 'package:local_auth/local_auth.dart';
import 'package:sefer_driver/constant/style.dart';
import 'package:sefer_driver/controller/firebase/firbase_messge.dart';
import 'package:sefer_driver/controller/firebase/local_notification.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:flutter/material.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/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import '../../../views/widgets/mydialoug.dart';
class CaptainWalletController extends GetxController {
bool isLoading = false;
final formKeyTransfer = GlobalKey<FormState>();
final formKeyAccount = GlobalKey<FormState>();
Map walletDate = {};
Map walletDateVisa = {};
Map walletDriverPointsDate = {};
final formKey = GlobalKey<FormState>();
String totalAmount = '0';
double kazan = 0;
String totalAmountVisa = '0';
String totalPoints = '0';
final amountFromBudgetController = TextEditingController();
final newDriverPhoneController = TextEditingController();
final phoneWallet = TextEditingController();
final cardBank = TextEditingController();
final bankCode = TextEditingController();
payFromBudget() async {
if (formKey.currentState!.validate()) {
var pointFromBudget = int.parse((amountFromBudgetController.text));
// await getPaymentId('fromBudgetToPoints',
// int.parse((amountFromBudgetController.text)) * -1);
var paymentToken3 =
await generateToken((pointFromBudget * -1).toString());
var paymentID = await getPaymentId(
'fromBudgetToPoints', (pointFromBudget * -1).toString());
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'amount': (pointFromBudget * -1).toString(),
'rideId': paymentID.toString(),
'payment_method': 'myBudget',
'passengerID': 'myBudgetToPoint',
'token': paymentToken3,
'driverID': box.read(BoxName.driverID).toString(),
});
Future.delayed(const Duration(seconds: 1));
await addDriverWallet(
'fromBudget', pointFromBudget.toString(), pointFromBudget.toString());
update();
Get.back();
await refreshCaptainWallet();
NotificationController().showNotification(
'You have successfully charged your account'.tr,
'$pointFromBudget ${'has been added to your budget'.tr}',
'tone1',
'',
);
}
}
Future refreshCaptainWallet() async {
await getCaptainWalletFromRide();
await getCaptainWalletFromBuyPoints();
// await checkAccountCaptainBank();
}
List amountToNewDriverMap = [];
bool isNewTransfer = false;
Future detectNewDriverFromMyBudget() async {
if (formKeyTransfer.currentState!.validate()) {
if (int.parse(amountFromBudgetController.text) <
double.parse(totalAmountVisa) &&
int.parse(amountFromBudgetController.text) > 10) {
//get new driver details
isNewTransfer = true;
update();
var res = await CRUD().get(
link: AppLink.getDriverDetails,
payload: {'driver_phone': '+2${newDriverPhoneController.text}'});
isNewTransfer = false;
update();
if (res != 'failure') {
var d = jsonDecode(res);
amountToNewDriverMap = d['data'];
// update();
} else {
mySnackeBarError("This driver is not registered".tr);
}
} else {
mySnackeBarError('Your Budget less than needed'.tr);
}
}
}
Future getCaptainWalletFromRide() async {
isLoading = true;
update();
var res = await CRUD().getWallet(
link: AppLink.getAllPaymentFromRide,
payload: {'driverID': box.read(BoxName.driverID).toString()},
);
// isLoading = false;
if (res != 'failure') {
walletDate = jsonDecode(res);
totalAmount = walletDate['message'][0]['total_amount'] ?? '0';
update();
var res1 = await CRUD().getWallet(
link: AppLink.getAllPaymentVisa,
payload: {'driverID': box.read(BoxName.driverID).toString()});
walletDateVisa = jsonDecode(res1);
totalAmountVisa = walletDateVisa['message'][0]['diff'].toString();
update();
} else {
totalAmount = "0";
totalAmountVisa = "0";
}
}
Future getCaptainWalletFromBuyPoints() async {
// isLoading = true;
update();
var res = await CRUD().getWallet(
link: AppLink.getDriverPaymentPoints,
payload: {'driverID': box.read(BoxName.driverID).toString()},
);
isLoading = false;
// update();
if (res != 'failure') {
walletDriverPointsDate = jsonDecode(res);
double totalPointsDouble = double.parse(
walletDriverPointsDate['message'][0]['total_amount'].toString());
totalPoints = totalPointsDouble.toStringAsFixed(0);
} else {
totalPoints = '0';
}
update();
}
String paymentToken = '';
Future<String> generateToken(String amount) async {
var res =
await CRUD().postWallet(link: AppLink.addPaymentTokenDriver, payload: {
'driverID': box.read(BoxName.driverID).toString(),
'amount': amount.toString(),
});
var d = (res);
return d['message'];
}
// late String paymentID;
Future<String> getPaymentId(String paymentMethod, amount) async {
// paymentToken = await generateToken(amount);
var res =
await CRUD().postWallet(link: AppLink.addDriverPaymentPoints, payload: {
'driverID': box.read(BoxName.driverID).toString(),
'amount': amount.toString(),
'payment_method': paymentMethod.toString(),
});
var d = (res);
// paymentID = d['message'].toString();
return d['message'];
}
Future addDriverWallet(String paymentMethod, point, count) async {
paymentToken = await generateToken(count);
var paymentID = await getPaymentId(paymentMethod, point.toString());
await CRUD().postWallet(link: AppLink.addDriversWalletPoints, payload: {
'driverID': box.read(BoxName.driverID).toString(),
'paymentID': paymentID.toString(),
'amount': point,
'token': paymentToken,
'paymentMethod': paymentMethod.toString(),
});
}
Future addDriverPayment(String paymentMethod, point, wayPay) async {
paymentToken = await generateToken(point);
var paymentID = await getPaymentId(paymentMethod, point.toString());
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'amount': point.toString(),
'rideId': paymentID.toString(),
'payment_method': paymentMethod,
'passengerID': wayPay,
'token': paymentToken,
'driverID': box.read(BoxName.driverID).toString(),
});
}
Future addDriverWalletFromPromo(String paymentMethod, point) async {
var resPromotion =
await CRUD().postWallet(link: AppLink.addpromotionDriver, payload: {
'driver_id': box.read(BoxName.driverID).toString(),
'payment_amount': point,
'timePromo': paymentMethod,
});
if (resPromotion != 'failure') {
paymentToken = await generateToken(point);
var paymentID = await getPaymentId(paymentMethod, point.toString());
var res =
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'amount': point,
'rideId': paymentID.toString(),
'payment_method': paymentMethod.toString(),
'passengerID': paymentMethod,
'token': paymentToken,
'driverID': box.read(BoxName.driverID).toString(),
});
if (res != 'failure') {
String title = 'wallet_updated'.tr; // Notification title
String message = '${'wallet_credited_message'.tr} $point';
String tone = 'default_tone'.tr; // Notification tone or sound
String payLoad =
'wallet_updated'; // Additional data payload for the notification
Get.find<NotificationController>()
.showNotification(title, message, tone, payLoad);
}
} else {
Get.back();
mySnackeBarError(
"A promotion record for this driver already exists for today.".tr);
}
}
Future addDriverWalletToInvitor(String paymentMethod, driverID, point) async {
paymentToken = await generateToken(point);
var paymentID = await getPaymentId(paymentMethod, point.toString());
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'driverID': driverID,
'amount': point,
'token': paymentToken,
'rideId': paymentID.toString(),
'payment_method': paymentMethod.toString(),
'passengerID': paymentMethod,
});
await addSeferWallet(paymentMethod,
(double.parse(point) * -2).toString()); // deduct 2 from sefer wallet
}
Future addSeferWallet(String paymentMethod, String point) async {
var seferToken = await generateToken(point.toString());
await CRUD().postWallet(link: AppLink.addSeferWallet, payload: {
'amount': point.toString(),
'paymentMethod': paymentMethod,
'passengerId': 'driver',
'token': seferToken,
'driverId': box.read(BoxName.driverID).toString(),
});
}
Future addTransferDriversWallet(String paymentMethod1, paymentMethod2) async {
var paymentID =
await getPaymentId(paymentMethod1, amountFromBudgetController.text);
paymentToken = await generateToken(
(int.parse(amountFromBudgetController.text) * -1).toString());
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'amount': (int.parse(amountFromBudgetController.text) * -1).toString(),
'rideId': paymentID.toString(),
'payment_method': paymentMethod1,
'passengerID': 'To ${amountToNewDriverMap[0]['id']}',
'token': paymentToken,
'driverID': box.read(BoxName.driverID).toString(),
});
paymentID = await getPaymentId(paymentMethod2,
(int.parse(amountFromBudgetController.text) - 5).toString());
paymentToken = await generateToken(amountFromBudgetController.text);
var res1 =
await CRUD().postWallet(link: AppLink.addDriversWalletPoints, payload: {
'driverID': amountToNewDriverMap[0]['id'].toString(),
'paymentID': paymentID.toString(),
'amount': ((int.parse(amountFromBudgetController.text) - 5))
// kazan) // double.parse(kazan) .08 for egypt
.toStringAsFixed(
0), // this will convert buddget to poitns by kazan .08
'token': paymentToken,
'paymentMethod': paymentMethod2.toString(),
});
if (res1 != 'failure') {
Get.find<FirebaseMessagesController>().sendNotificationToDriverMAP(
'Transfer',
'${'You have transfer to your wallet from'.tr}'
'${box.read(BoxName.nameDriver)}',
amountToNewDriverMap[0]['token'].toString(),
[],
'order1.wav');
await addSeferWallet('payout fee', '5');
Get.defaultDialog(
title: 'transfer Successful'.tr,
middleText: '',
titleStyle: AppStyle.title,
confirm: MyElevatedButton(
title: 'Ok'.tr,
onPressed: () async {
Get.back();
Get.back();
await refreshCaptainWallet();
}));
}
}
//check if account bank is created or not
Future checkAccountCaptainBank() async {
isLoading = true;
update();
if (box.read(BoxName.accountIdStripeConnect).toString().isEmpty) {
var res = await CRUD().get(link: AppLink.getAccount, payload: {
'id': box.read(BoxName.driverID).toString(),
});
var d = jsonDecode(res);
if (d['status'] != 'failure') {
box.write(BoxName.accountIdStripeConnect,
d['message'][0]['accountBank'].toString());
}
}
isLoading = false;
update();
}
getKazanPercent() async {
var res = await CRUD().get(
link: AppLink.getKazanPercent,
payload: {'country': box.read(BoxName.countryCode).toString()},
);
if (res != 'failure') {
var json = jsonDecode(res);
kazan = double.parse(json['message'][0]['kazan'].toString());
// naturePrice = double.parse(json['message'][0]['naturePrice']);
// heavyPrice = double.parse(json['message'][0]['heavyPrice']);
// latePrice = double.parse(json['message'][0]['latePrice']);
// comfortPrice = double.parse(json['message'][0]['comfortPrice']);
// speedPrice = double.parse(json['message'][0]['speedPrice']);
// deliveryPrice = double.parse(json['message'][0]['deliveryPrice']);
// mashwariPrice = double.parse(json['message'][0]['freePrice']);
// fuelPrice = double.parse(json['message'][0]['fuelPrice']);
}
update();
}
@override
void onInit() async {
// getKazanPercent();
await refreshCaptainWallet();
super.onInit();
}
}

View File

@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../constant/box_name.dart';
import '../../functions/digit_obsecur_formate.dart';
import '../../functions/secure_storage.dart';
class CreditCardController extends GetxController {
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
final TextEditingController cardNumberController = TextEditingController();
final TextEditingController cardHolderNameController =
TextEditingController();
final TextEditingController expiryDateController = TextEditingController();
final TextEditingController cvvCodeController = TextEditingController();
openPayment() async {
String? cardNumber = await SecureStorage().readData(BoxName.cardNumber);
String? cardHolderName =
await SecureStorage().readData(BoxName.cardHolderName);
String? expiryDate = await SecureStorage().readData(BoxName.expiryDate);
String? cvvCode = await SecureStorage().readData(BoxName.cvvCode);
if (cvvCode != null && cvvCode.isNotEmpty) {
final maskedCardNumber = DigitObscuringFormatter()
.formatEditUpdate(
TextEditingValue.empty,
TextEditingValue(text: cardNumber ?? ''),
)
.text;
cardNumberController.text = maskedCardNumber;
cardHolderNameController.text = cardHolderName ?? '';
expiryDateController.text = expiryDate ?? '';
cvvCodeController.text = cvvCode;
}
}
@override
void onInit() async {
super.onInit();
openPayment();
// String? cardNumber = await SecureStorage().readData(BoxName.cardNumber);
// String? cardHolderName =
// await SecureStorage().readData(BoxName.cardHolderName);
// String? expiryDate = await SecureStorage().readData(BoxName.expiryDate);
// String? cvvCode = await SecureStorage().readData(BoxName.cvvCode);
// if (cvvCode != null && cvvCode.isNotEmpty) {
// final maskedCardNumber = DigitObscuringFormatter()
// .formatEditUpdate(
// TextEditingValue.empty,
// TextEditingValue(text: cardNumber ?? ''),
// )
// .text;
// cardNumberController.text = maskedCardNumber;
// cardHolderNameController.text = cardHolderName ?? '';
// expiryDateController.text = expiryDate ?? '';
// cvvCodeController.text = cvvCode;
// }
}
}
class CreditCardModel {
String cardNumber;
String cardHolderName;
String expiryDate;
String cvvCode;
CreditCardModel({
required this.cardNumber,
required this.cardHolderName,
required this.expiryDate,
required this.cvvCode,
});
}

View File

@@ -0,0 +1,234 @@
import 'dart:convert';
import 'package:local_auth/local_auth.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:get/get.dart';
import '../../../constant/links.dart';
import '../../../views/widgets/mydialoug.dart';
import '../../functions/crud.dart';
import 'captain_wallet_controller.dart';
class PaymobPayout extends GetxController {
bool isLoading = false;
String dropdownValue = 'etisalat';
int payOutFee = 5;
payToDriverWallet(String amount, String issuer, String msisdn) async {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
var dec = await CRUD()
.postWallet(link: AppLink.paymobPayoutDriverWallet, payload: {
"issuer": issuer,
"method": "wallet",
"amount": amount, //9.0,
"full_name":
'${box.read(BoxName.nameDriver)} ${box.read(BoxName.lastNameDriver)}',
"msisdn": msisdn, //"01010101010",
"bank_transaction_type": "cash_transfer"
});
if (dec['disbursement_status'] == 'successful') {
var paymentToken = await Get.find<CaptainWalletController>()
.generateToken(
((-1) * (double.parse(dec['amount'].toString())) - payOutFee)
.toStringAsFixed(0));
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'rideId': DateTime.now().toIso8601String(),
'amount':
((-1) * (double.parse(dec['amount'].toString())) - payOutFee)
.toStringAsFixed(0),
'payment_method': 'payout',
'passengerID': 'myself',
'token': paymentToken,
'driverID': box.read(BoxName.driverID).toString(),
});
await Get.find<CaptainWalletController>()
.addSeferWallet('payout fee myself', payOutFee.toString());
await updatePaymentToPaid(box.read(BoxName.driverID).toString());
await sendEmail(
box.read(BoxName.driverID).toString(),
amount,
box.read(BoxName.phoneDriver).toString(),
box.read(BoxName.nameDriver).toString(),
'Wallet',
box.read(BoxName.emailDriver).toString());
mySnackbarSuccess('${'Transaction successful'.tr} ${dec['amount']}');
Get.find<CaptainWalletController>().refreshCaptainWallet();
} else if (dec['disbursement_status'] == 'failed') {
mySnackeBarError('Transaction failed'.tr);
}
} else {
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
}
}
Future updatePaymentToPaid(String driverID) async {
await CRUD().postWallet(link: AppLink.updatePaymetToPaid, payload: {
'driverID': driverID.toString(),
});
}
Future sendEmail(
String driverId, amount, phone, name, bankCardNumber, email) async {
await CRUD().sendEmail(AppLink.sendEmailToDrivertransaction, {
"driverID": driverId,
"total_amount": amount,
"phone": phone,
"name_arabic": name,
"accountBank": bankCardNumber,
"email": email
});
}
getAIKey(String key) async {
var res =
await CRUD().get(link: AppLink.getapiKey, payload: {"keyName": key});
if (res != 'failure') {
var d = jsonDecode(res)['message'];
return d[key].toString();
} else {}
}
payToDriverBankAccount(
String amount, String bankCardNumber, String bankCode) async {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
var body = {
"issuer": "bank_card",
"method": "bank_card",
"amount": amount, //9.0,
"full_name":
'${box.read(BoxName.nameDriver)} ${box.read(BoxName.lastNameDriver)}',
"bank_card_number": bankCardNumber, //"1111-2222-3333-4444",
"bank_code": bankCode, //"CIB",
"bank_transaction_type": "cash_transfer"
};
var dec = await CRUD().postWallet(
link:
'wl.tripz-egypt.com/v1/main/ride/payMob/paymob_driver/paymob_payout.php',
payload: body,
);
if (dec['disbursement_status'] == 'successful') {
var paymentToken = await Get.find<CaptainWalletController>()
.generateToken(
((-1) * (double.parse(dec['amount'].toString())) - payOutFee)
.toStringAsFixed(0));
await CRUD().postWallet(link: AppLink.addDrivePayment, payload: {
'rideId': DateTime.now().toIso8601String(),
'amount':
((-1) * (double.parse(dec['amount'].toString())) - payOutFee)
.toStringAsFixed(0),
'payment_method': 'payout',
'passengerID': 'myself',
'token': paymentToken,
'driverID': box.read(BoxName.driverID).toString(),
});
await Get.find<CaptainWalletController>()
.addSeferWallet('payout fee myself', payOutFee.toString());
await updatePaymentToPaid(box.read(BoxName.driverID).toString());
await sendEmail(
box.read(BoxName.driverID).toString(),
amount,
box.read(BoxName.phoneDriver).toString(),
box.read(BoxName.nameDriver).toString(),
'Wallet',
box.read(BoxName.emailDriver).toString());
mySnackbarSuccess('${'Transaction successful'.tr} ${dec['amount']}');
Get.find<CaptainWalletController>().refreshCaptainWallet();
} else if (dec['disbursement_status'] == 'failed') {
mySnackeBarError('Transaction failed'.tr);
}
} else {
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
}
}
Future payToWalletDriverAll(
String amount, String issuer, String msisdn) async {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
await payToDriverWallet(amount, issuer, msisdn);
} else {
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
}
}
Future payToBankDriverAll(
String amount, String bankCardNumber, String bankCode) async {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
await payToDriverBankAccount(amount, bankCardNumber, bankCode);
} else {
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
}
}
}

View File

@@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:sefer_driver/constant/style.dart';
import '../../constant/api_key.dart';
import '../../constant/links.dart';
import '../functions/crud.dart';
import '../functions/location_controller.dart';
class PointsForRiderController extends GetxController {
List<String> locations = [];
String hintTextDestinationPoint = 'Search for your destination'.tr;
TextEditingController placeStartController = TextEditingController();
void addLocation(String location) {
locations.add(location);
update();
}
void getTextFromList(String location) {
locations.add(location);
update();
Get.back();
}
void removeLocation(int index) {
locations.removeAt(index);
update();
}
void onReorder(int oldIndex, int newIndex) {
if (newIndex > oldIndex) {
newIndex -= 1;
update();
}
final item = locations.removeAt(oldIndex);
locations.insert(newIndex, item);
update();
}
}
class LocationModel {
String name;
double lat, lon;
LocationModel({required this.name, required this.lat, required this.lon});
}
class WayPointController extends GetxController {
// A list of text editing controllers for each text field
// final textFields = [TextEditingController()].obs;
List<String> wayPoints = [];
List<List<dynamic>> placeListResponse = [];
double wayPointHeight = 400;
String hintTextDestinationPoint = 'Search for your destination'.tr;
TextEditingController textSearchCotroller = TextEditingController();
// A list of places corresponding to each text field
final places = <String>[];
final hintTextPointList = <String>[];
late LatLng myLocation;
void addWayPoints() {
String wayPoint = 'Add a Stop'.tr;
if (wayPoints.length < 5) {
wayPoints.add(wayPoint);
update();
} else {
Get.defaultDialog(
title: 'This is most WayPoints',
titleStyle: AppStyle.title,
middleText: '');
}
update();
}
void removeTextField(int index) {
wayPoints.removeAt(index);
update();
}
// A method to reorder the text fields and the places
void reorderTextFields(int oldIndex, int newIndex) {
if (newIndex > oldIndex) {
newIndex -= 1;
}
final wayPoint = wayPoints.removeAt(oldIndex);
wayPoints.insert(newIndex, wayPoint);
update();
}
void updatePlace(int index, String input) async {
var url =
'${AppLink.googleMapsLink}place/nearbysearch/json?keyword=$input&location=${myLocation.latitude},${myLocation.longitude}&radius=50000&language=en&key=${AK.mapAPIKEY.toString()}';
var response = await CRUD().getGoogleApi(link: url, payload: {});
// final place = input;
// if (index == 0) {
List<dynamic> newList = [];
placeListResponse.add(newList);
newList = response['results'];
placeListResponse[index].add(newList);
update();
// }
update();
}
@override
void onInit() {
Get.put(LocationController());
addWayPoints();
myLocation = Get.find<LocationController>().myLocation;
super.onInit();
}
}
class PlaceList extends StatelessWidget {
// Get the controller instance
final controller = Get.put(WayPointController());
@override
Widget build(BuildContext context) {
// Use the Obx widget to rebuild the widget when the controller changes
return Obx(() {
// Use the ListView widget to display the list of places
return ListView(
// The children of the list are the places
children: [
// Loop through the places in the controller
for (final place in controller.places)
// Create a text widget for each place
Text(
// Use the place as the text
place,
// Add some style and padding
style: const TextStyle(fontSize: 18.0),
),
],
);
});
}
}

View File

@@ -0,0 +1,44 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
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/constant/style.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
class FeedBackController extends GetxController {
bool isLoading = false;
final formKey = GlobalKey<FormState>();
final feedbackController = TextEditingController();
void addFeedBack() async {
isLoading = true;
update();
var res = await CRUD().post(link: AppLink.addFeedBack, payload: {
'passengerId': box.read(BoxName.passengerID).toString(),
'feedBack': feedbackController.text
});
var d = jsonDecode(res);
if (d['status'].toString() == 'success') {
Get.defaultDialog(
title: 'Success'.tr,
titleStyle: AppStyle.title,
middleText: 'Feedback data saved successfully'.tr,
middleTextStyle: AppStyle.title,
confirm: MyElevatedButton(
kolor: AppColor.greenColor,
title: 'Ok'.tr,
onPressed: () {
Get.back();
Get.back();
}));
}
isLoading = false;
update();
}
}

View File

@@ -0,0 +1,35 @@
import 'dart:convert';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
class OrderHistoryController extends GetxController {
List<dynamic> orderHistoryListPassenger = [];
bool isloading = true;
@override
void onInit() {
getOrderHistoryByPassenger();
super.onInit();
}
Future getOrderHistoryByPassenger() async {
var res = await CRUD().get(link: AppLink.getRides, payload: {
'passenger_id': box.read(BoxName.passengerID).toString(),
});
if (res.toString() == 'failure') {
// Get.snackbar('failure', 'message');
isloading = false;
update();
} else {
var jsonDecoded = jsonDecode(res);
orderHistoryListPassenger = jsonDecoded['data'];
isloading = false;
update();
}
}
}

View File

@@ -0,0 +1,42 @@
import 'dart:convert';
import 'package:get/get.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/views/widgets/elevated_btn.dart';
class PromosController extends GetxController {
List<dynamic> promoList = [];
bool isLoading = true;
late String promos;
@override
void onInit() {
getPromoByToday();
super.onInit();
}
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();
}));
isLoading = false;
update();
} else {
var jsonDecoded = jsonDecode(res);
promoList = jsonDecoded['message'];
isLoading = false;
update();
}
}
}

View File

@@ -0,0 +1,98 @@
import 'dart:async';
import 'package:sefer_driver/controller/auth/captin/login_captin_controller.dart';
import 'package:sefer_driver/views/home/on_boarding_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';
import '../../constant/box_name.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/auth/captin/login_captin.dart';
class SplashScreenController extends GetxController
with GetTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> animation;
final progress = 0.0.obs;
Timer? _progressTimer;
String packageInfo = '';
Future<void> _getPackageInfo() async {
final info = await PackageInfo.fromPlatform();
packageInfo = info.version;
box.write(BoxName.packagInfo, packageInfo);
update();
}
@override
void onInit() {
super.onInit();
_getPackageInfo();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1500), // Reduced duration
)..forward();
animation =
CurvedAnimation(parent: _animationController, curve: Curves.easeOut);
startTimer();
_startProgressTimer();
}
void _startProgressTimer() {
Log.print(
'box.read(BoxName.phoneDriver): ${box.read(BoxName.phoneDriver)}');
Log.print(
'box.read(BoxName.phoneVerified): ${box.read(BoxName.phoneVerified)}');
const totalTime = 3000; // 5 seconds in milliseconds
const interval = 50; // Update every 50ms
int elapsed = 0;
_progressTimer =
Timer.periodic(const Duration(milliseconds: interval), (timer) async {
elapsed += interval;
progress.value = (elapsed / totalTime).clamp(0.0, 1.0);
if (elapsed >= totalTime) {
timer.cancel();
// Get.off(SyrianCardAI());
box.read(BoxName.onBoarding) == null
? Get.off(() => OnBoardingPage())
: box.read(BoxName.phoneDriver) != null &&
box.read(BoxName.phoneVerified) == '1'
? await Get.put(LoginDriverController())
.loginWithGoogleCredential(
box.read(BoxName.driverID).toString(),
box.read(BoxName.emailDriver).toString())
: Get.off(() => LoginCaptin());
}
});
}
void startTimer() async {
Timer(const Duration(seconds: 5), () async {
// box.read(BoxName.onBoarding) == null
// ? Get.off(() => OnBoardingPage())
// : box.read(BoxName.email) != null &&
// box.read(BoxName.phone) != null &&
// box.read(BoxName.isVerified) == '1'
// // ? Get.off(() => const MapPagePassenger())
// ? await Get.put(LoginController()).loginUsingCredentials(
// box.read(BoxName.passengerID).toString(),
// box.read(BoxName.email).toString(),
// )
// : Get.off(() => LoginPage());
});
}
@override
void onClose() {
_progressTimer?.cancel();
_animationController.dispose();
super.onClose();
}
}

View File

@@ -0,0 +1,112 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../constant/box_name.dart';
import '../../main.dart';
import '../themes/themes.dart';
class LocaleController extends GetxController {
Locale? language;
String countryCode = '';
ThemeData appTheme = lightThemeEnglish;
void changeLang(String langcode) {
Locale locale;
switch (langcode) {
case "ar":
locale = const Locale("ar");
appTheme = lightThemeArabic;
box.write(BoxName.lang, 'ar');
break;
case "en":
locale = const Locale("en");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'en');
break;
case "tr":
locale = const Locale("tr");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'tr');
break;
case "fr":
locale = const Locale("fr");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'fr');
break;
case "it":
locale = const Locale("it");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'it');
break;
case "de":
locale = const Locale("de");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'de');
break;
case "el":
locale = const Locale("el");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'el');
break;
case "es":
locale = const Locale("es");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'es');
break;
case "fa":
locale = const Locale("fa");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'fa');
break;
case "zh":
locale = const Locale("zh");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'zh');
break;
case "ru":
locale = const Locale("ru");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'ru');
break;
case "hi":
locale = const Locale("hi");
appTheme = lightThemeEnglish;
box.write(BoxName.lang, 'hi');
break;
case "ar-ma":
locale = const Locale("ar-ma");
appTheme = lightThemeArabic;
box.write(BoxName.lang, 'ar-ma');
break;
case "ar-gulf":
locale = const Locale("ar-gulf");
appTheme = lightThemeArabic;
box.write(BoxName.lang, 'ar-gulf');
break;
default:
locale = Locale(Get.deviceLocale!.languageCode);
box.write(BoxName.lang, Get.deviceLocale!.languageCode);
appTheme = lightThemeEnglish;
break;
}
box.write(BoxName.lang, langcode);
Get.changeTheme(appTheme);
Get.updateLocale(locale);
update();
}
@override
void onInit() {
String? storedLang = box.read(BoxName.lang);
if (storedLang == null) {
// Use device language if no language is stored
storedLang = Get.deviceLocale!.languageCode;
box.write(BoxName.lang, storedLang);
}
changeLang(storedLang);
super.onInit();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,168 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:sefer_driver/controller/local/phone_intel/helpers.dart';
import 'countries.dart';
class PickerDialogStyle {
final Color? backgroundColor;
final TextStyle? countryCodeStyle;
final TextStyle? countryNameStyle;
final Widget? listTileDivider;
final EdgeInsets? listTilePadding;
final EdgeInsets? padding;
final Color? searchFieldCursorColor;
final InputDecoration? searchFieldInputDecoration;
final EdgeInsets? searchFieldPadding;
final double? width;
PickerDialogStyle({
this.backgroundColor,
this.countryCodeStyle,
this.countryNameStyle,
this.listTileDivider,
this.listTilePadding,
this.padding,
this.searchFieldCursorColor,
this.searchFieldInputDecoration,
this.searchFieldPadding,
this.width,
});
}
class CountryPickerDialog extends StatefulWidget {
final List<Country> countryList;
final Country selectedCountry;
final ValueChanged<Country> onCountryChanged;
final String searchText;
final List<Country> filteredCountries;
final PickerDialogStyle? style;
final String languageCode;
const CountryPickerDialog({
Key? key,
required this.searchText,
required this.languageCode,
required this.countryList,
required this.onCountryChanged,
required this.selectedCountry,
required this.filteredCountries,
this.style,
}) : super(key: key);
@override
State<CountryPickerDialog> createState() => _CountryPickerDialogState();
}
class _CountryPickerDialogState extends State<CountryPickerDialog> {
late List<Country> _filteredCountries;
late Country _selectedCountry;
@override
void initState() {
_selectedCountry = widget.selectedCountry;
_filteredCountries = widget.filteredCountries.toList()
..sort(
(a, b) => a
.localizedName(widget.languageCode)
.compareTo(b.localizedName(widget.languageCode)),
);
super.initState();
}
@override
Widget build(BuildContext context) {
final mediaWidth = MediaQuery.of(context).size.width;
final width = widget.style?.width ?? mediaWidth;
const defaultHorizontalPadding = 40.0;
const defaultVerticalPadding = 24.0;
return Dialog(
insetPadding: EdgeInsets.symmetric(
vertical: defaultVerticalPadding,
horizontal: mediaWidth > (width + defaultHorizontalPadding * 2)
? (mediaWidth - width) / 2
: defaultHorizontalPadding),
backgroundColor: widget.style?.backgroundColor,
child: Container(
padding: widget.style?.padding ?? const EdgeInsets.all(10),
child: Column(
children: <Widget>[
Padding(
padding:
widget.style?.searchFieldPadding ?? const EdgeInsets.all(0),
child: TextField(
cursorColor: widget.style?.searchFieldCursorColor,
decoration: widget.style?.searchFieldInputDecoration ??
InputDecoration(
suffixIcon: const Icon(Icons.search),
labelText: widget.searchText,
),
onChanged: (value) {
_filteredCountries = widget.countryList.stringSearch(value)
..sort(
(a, b) => a
.localizedName(widget.languageCode)
.compareTo(b.localizedName(widget.languageCode)),
);
if (mounted) setState(() {});
},
),
),
const SizedBox(height: 20),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: _filteredCountries.length,
itemBuilder: (ctx, index) => Column(
children: <Widget>[
ListTile(
leading: kIsWeb
? Image.asset(
'assets/flags/${_filteredCountries[index].code.toLowerCase()}.png',
package: 'intl_phone_field',
width: 32,
)
: Text(
_filteredCountries[index].flag,
style: const TextStyle(fontSize: 18),
),
contentPadding: widget.style?.listTilePadding,
title: Text(
_filteredCountries[index]
.localizedName(widget.languageCode),
style: widget.style?.countryNameStyle ??
const TextStyle(fontWeight: FontWeight.w700),
),
trailing: Text(
'+${_filteredCountries[index].dialCode}',
style: widget.style?.countryCodeStyle ??
const TextStyle(fontWeight: FontWeight.w700),
),
onTap: () {
_selectedCountry = _filteredCountries[index];
widget.onCountryChanged(_selectedCountry);
Navigator.of(context).pop();
},
),
widget.style?.listTileDivider ??
const Divider(thickness: 1),
],
),
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,31 @@
import 'countries.dart';
bool isNumeric(String s) =>
s.isNotEmpty && int.tryParse(s.replaceAll("+", "")) != null;
String removeDiacritics(String str) {
var withDia =
'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var withoutDia =
'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
for (int i = 0; i < withDia.length; i++) {
str = str.replaceAll(withDia[i], withoutDia[i]);
}
return str;
}
extension CountryExtensions on List<Country> {
List<Country> stringSearch(String search) {
search = removeDiacritics(search.toLowerCase());
return where(
(country) => isNumeric(search) || search.startsWith("+")
? country.dialCode.contains(search)
: removeDiacritics(country.name.replaceAll("+", "").toLowerCase())
.contains(search) ||
country.nameTranslations.values.any((element) =>
removeDiacritics(element.toLowerCase()).contains(search)),
).toList();
}
}

View File

@@ -0,0 +1,521 @@
library intl_phone_field;
import 'dart:async';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import './countries.dart';
import './phone_number.dart';
import 'country_picker_dialog.dart';
import 'helpers.dart';
class IntlPhoneField extends StatefulWidget {
/// The TextFormField key.
final GlobalKey<FormFieldState>? formFieldKey;
/// Whether to hide the text being edited (e.g., for passwords).
final bool obscureText;
/// How the text should be aligned horizontally.
final TextAlign textAlign;
/// How the text should be aligned vertically.
final TextAlignVertical? textAlignVertical;
final VoidCallback? onTap;
/// {@macro flutter.widgets.editableText.readOnly}
final bool readOnly;
final FormFieldSetter<PhoneNumber>? onSaved;
/// {@macro flutter.widgets.editableText.onChanged}
///
/// See also:
///
/// * [inputFormatters], which are called before [onChanged]
/// runs and can validate and change ("format") the input value.
/// * [onEditingComplete], [onSubmitted], [onSelectionChanged]:
/// which are more specialized input change notifications.
final ValueChanged<PhoneNumber>? onChanged;
final ValueChanged<Country>? onCountryChanged;
/// An optional method that validates an input. Returns an error string to display if the input is invalid, or null otherwise.
///
/// A [PhoneNumber] is passed to the validator as argument.
/// The validator can handle asynchronous validation when declared as a [Future].
/// Or run synchronously when declared as a [Function].
///
/// By default, the validator checks whether the input number length is between selected country's phone numbers min and max length.
/// If `disableLengthCheck` is not set to `true`, your validator returned value will be overwritten by the default validator.
/// But, if `disableLengthCheck` is set to `true`, your validator will have to check phone number length itself.
final FutureOr<String?> Function(PhoneNumber?)? validator;
/// {@macro flutter.widgets.editableText.keyboardType}
final TextInputType keyboardType;
/// Controls the text being edited.
///
/// If null, this widget will create its own [TextEditingController].
final TextEditingController? controller;
/// Defines the keyboard focus for this widget.
///
/// The [focusNode] is a long-lived object that's typically managed by a
/// [StatefulWidget] parent. See [FocusNode] for more information.
///
/// To give the keyboard focus to this widget, provide a [focusNode] and then
/// use the current [FocusScope] to request the focus:
///
/// ```dart
/// FocusScope.of(context).requestFocus(myFocusNode);
/// ```
///
/// This happens automatically when the widget is tapped.
///
/// To be notified when the widget gains or loses the focus, add a listener
/// to the [focusNode]:
///
/// ```dart
/// focusNode.addListener(() { print(myFocusNode.hasFocus); });
/// ```
///
/// If null, this widget will create its own [FocusNode].
///
/// ## Keyboard
///
/// Requesting the focus will typically cause the keyboard to be shown
/// if it's not showing already.
///
/// On Android, the user can hide the keyboard - without changing the focus -
/// with the system back button. They can restore the keyboard's visibility
/// by tapping on a text field. The user might hide the keyboard and
/// switch to a physical keyboard, or they might just need to get it
/// out of the way for a moment, to expose something it's
/// obscuring. In this case requesting the focus again will not
/// cause the focus to change, and will not make the keyboard visible.
///
/// This widget builds an [EditableText] and will ensure that the keyboard is
/// showing when it is tapped by calling [EditableTextState.requestKeyboard()].
final FocusNode? focusNode;
/// {@macro flutter.widgets.editableText.onSubmitted}
///
/// See also:
///
/// * [EditableText.onSubmitted] for an example of how to handle moving to
/// the next/previous field when using [TextInputAction.next] and
/// [TextInputAction.previous] for [textInputAction].
final void Function(String)? onSubmitted;
/// If false the widget is "disabled": it ignores taps, the [TextFormField]'s
/// [decoration] is rendered in grey,
/// [decoration]'s [InputDecoration.counterText] is set to `""`,
/// and the drop down icon is hidden no matter [showDropdownIcon] value.
///
/// If non-null this property overrides the [decoration]'s
/// [Decoration.enabled] property.
final bool enabled;
/// The appearance of the keyboard.
///
/// This setting is only honored on iOS devices.
///
/// If unset, defaults to the brightness of [ThemeData.brightness].
final Brightness? keyboardAppearance;
/// Initial Value for the field.
/// This property can be used to pre-fill the field.
final String? initialValue;
final String languageCode;
/// 2 letter ISO Code or country dial code.
///
/// ```dart
/// initialCountryCode: 'IN', // India
/// initialCountryCode: '+225', // Côte d'Ivoire
/// ```
final String? initialCountryCode;
/// List of Country to display see countries.dart for format
final List<Country>? countries;
/// The decoration to show around the text field.
///
/// By default, draws a horizontal line under the text field but can be
/// configured to show an icon, label, hint text, and error text.
///
/// Specify null to remove the decoration entirely (including the
/// extra padding introduced by the decoration to save space for the labels).
final InputDecoration decoration;
/// The style to use for the text being edited.
///
/// This text style is also used as the base style for the [decoration].
///
/// If null, defaults to the `subtitle1` text style from the current [Theme].
final TextStyle? style;
/// Disable view Min/Max Length check
final bool disableLengthCheck;
/// Won't work if [enabled] is set to `false`.
final bool showDropdownIcon;
final BoxDecoration dropdownDecoration;
/// The style use for the country dial code.
final TextStyle? dropdownTextStyle;
/// {@macro flutter.widgets.editableText.inputFormatters}
final List<TextInputFormatter>? inputFormatters;
/// The text that describes the search input field.
///
/// When the input field is empty and unfocused, the label is displayed on top of the input field (i.e., at the same location on the screen where text may be entered in the input field).
/// When the input field receives focus (or if the field is non-empty), the label moves above (i.e., vertically adjacent to) the input field.
final String searchText;
/// Position of an icon [leading, trailing]
final IconPosition dropdownIconPosition;
/// Icon of the drop down button.
///
/// Default is [Icon(Icons.arrow_drop_down)]
final Icon dropdownIcon;
/// Whether this text field should focus itself if nothing else is already focused.
final bool autofocus;
/// Autovalidate mode for text form field.
///
/// If [AutovalidateMode.onUserInteraction], this FormField will only auto-validate after its content changes.
/// If [AutovalidateMode.always], it will auto-validate even without user interaction.
/// If [AutovalidateMode.disabled], auto-validation will be disabled.
///
/// Defaults to [AutovalidateMode.onUserInteraction].
final AutovalidateMode? autovalidateMode;
/// Whether to show or hide country flag.
///
/// Default value is `true`.
final bool showCountryFlag;
/// Message to be displayed on autoValidate error
///
/// Default value is `Invalid Mobile Number`.
final String? invalidNumberMessage;
/// The color of the cursor.
final Color? cursorColor;
/// How tall the cursor will be.
final double? cursorHeight;
/// How rounded the corners of the cursor should be.
final Radius? cursorRadius;
/// How thick the cursor will be.
final double cursorWidth;
/// Whether to show cursor.
final bool? showCursor;
/// The padding of the Flags Button.
///
/// The amount of insets that are applied to the Flags Button.
///
/// If unset, defaults to [EdgeInsets.zero].
final EdgeInsetsGeometry flagsButtonPadding;
/// The type of action button to use for the keyboard.
final TextInputAction? textInputAction;
/// Optional set of styles to allow for customizing the country search
/// & pick dialog
final PickerDialogStyle? pickerDialogStyle;
/// The margin of the country selector button.
///
/// The amount of space to surround the country selector button.
///
/// If unset, defaults to [EdgeInsets.zero].
final EdgeInsets flagsButtonMargin;
/// Enable the autofill hint for phone number.
final bool disableAutoFillHints;
/// If null, default magnification configuration will be used.
final TextMagnifierConfiguration? magnifierConfiguration;
const IntlPhoneField({
Key? key,
this.formFieldKey,
this.initialCountryCode,
this.languageCode = 'en',
this.disableAutoFillHints = false,
this.obscureText = false,
this.textAlign = TextAlign.left,
this.textAlignVertical,
this.onTap,
this.readOnly = false,
this.initialValue,
this.keyboardType = TextInputType.phone,
this.controller,
this.focusNode,
this.decoration = const InputDecoration(),
this.style,
this.dropdownTextStyle,
this.onSubmitted,
this.validator,
this.onChanged,
this.countries,
this.onCountryChanged,
this.onSaved,
this.showDropdownIcon = true,
this.dropdownDecoration = const BoxDecoration(),
this.inputFormatters,
this.enabled = true,
this.keyboardAppearance,
@Deprecated('Use searchFieldInputDecoration of PickerDialogStyle instead')
this.searchText = 'Search country',
this.dropdownIconPosition = IconPosition.leading,
this.dropdownIcon = const Icon(Icons.arrow_drop_down),
this.autofocus = false,
this.textInputAction,
this.autovalidateMode = AutovalidateMode.onUserInteraction,
this.showCountryFlag = true,
this.cursorColor,
this.disableLengthCheck = false,
this.flagsButtonPadding = EdgeInsets.zero,
this.invalidNumberMessage = 'Invalid Mobile Number',
this.cursorHeight,
this.cursorRadius = Radius.zero,
this.cursorWidth = 2.0,
this.showCursor = true,
this.pickerDialogStyle,
this.flagsButtonMargin = EdgeInsets.zero,
this.magnifierConfiguration,
}) : super(key: key);
@override
State<IntlPhoneField> createState() => _IntlPhoneFieldState();
}
class _IntlPhoneFieldState extends State<IntlPhoneField> {
late List<Country> _countryList;
late Country _selectedCountry;
late List<Country> filteredCountries;
late String number;
String? validatorMessage;
@override
void initState() {
super.initState();
_countryList = widget.countries ?? countries;
filteredCountries = _countryList;
number = widget.initialValue ?? '';
if (widget.initialCountryCode == null && number.startsWith('+')) {
number = number.substring(1);
// parse initial value
_selectedCountry = countries.firstWhere(
(country) => number.startsWith(country.fullCountryCode),
orElse: () => _countryList.first);
// remove country code from the initial number value
number = number.replaceFirst(
RegExp("^${_selectedCountry.fullCountryCode}"), "");
} else {
_selectedCountry = _countryList.firstWhere(
(item) => item.code == (widget.initialCountryCode ?? 'US'),
orElse: () => _countryList.first);
// remove country code from the initial number value
if (number.startsWith('+')) {
number = number.replaceFirst(
RegExp("^\\+${_selectedCountry.fullCountryCode}"), "");
} else {
number = number.replaceFirst(
RegExp("^${_selectedCountry.fullCountryCode}"), "");
}
}
if (widget.autovalidateMode == AutovalidateMode.always) {
final initialPhoneNumber = PhoneNumber(
countryISOCode: _selectedCountry.code,
countryCode: '+${_selectedCountry.dialCode}',
number: widget.initialValue ?? '',
);
final value = widget.validator?.call(initialPhoneNumber);
if (value is String) {
validatorMessage = value;
} else {
(value as Future).then((msg) {
validatorMessage = msg;
});
}
}
}
Future<void> _changeCountry() async {
filteredCountries = _countryList;
await showDialog(
context: context,
useRootNavigator: false,
builder: (context) => StatefulBuilder(
builder: (ctx, setState) => CountryPickerDialog(
languageCode: widget.languageCode.toLowerCase(),
style: widget.pickerDialogStyle,
filteredCountries: filteredCountries,
searchText: widget.searchText,
countryList: _countryList,
selectedCountry: _selectedCountry,
onCountryChanged: (Country country) {
_selectedCountry = country;
widget.onCountryChanged?.call(country);
setState(() {});
},
),
),
);
if (mounted) setState(() {});
}
@override
Widget build(BuildContext context) {
return TextFormField(
key: widget.formFieldKey,
initialValue: (widget.controller == null) ? number : null,
autofillHints: widget.disableAutoFillHints
? null
: [AutofillHints.telephoneNumberNational],
readOnly: widget.readOnly,
obscureText: widget.obscureText,
textAlign: widget.textAlign,
textAlignVertical: widget.textAlignVertical,
cursorColor: widget.cursorColor,
onTap: widget.onTap,
controller: widget.controller,
focusNode: widget.focusNode,
cursorHeight: widget.cursorHeight,
cursorRadius: widget.cursorRadius,
cursorWidth: widget.cursorWidth,
showCursor: widget.showCursor,
onFieldSubmitted: widget.onSubmitted,
magnifierConfiguration: widget.magnifierConfiguration,
decoration: widget.decoration.copyWith(
prefixIcon: _buildFlagsButton(),
counterText: !widget.enabled ? '' : null,
),
style: widget.style,
onSaved: (value) {
widget.onSaved?.call(
PhoneNumber(
countryISOCode: _selectedCountry.code,
countryCode:
'+${_selectedCountry.dialCode}${_selectedCountry.regionCode}',
number: value!,
),
);
},
onChanged: (value) async {
final phoneNumber = PhoneNumber(
countryISOCode: _selectedCountry.code,
countryCode: '+${_selectedCountry.fullCountryCode}',
number: value,
);
if (widget.autovalidateMode != AutovalidateMode.disabled) {
validatorMessage = await widget.validator?.call(phoneNumber);
}
widget.onChanged?.call(phoneNumber);
},
validator: (value) {
if (value == null || !isNumeric(value)) return validatorMessage;
if (!widget.disableLengthCheck) {
return value.length >= _selectedCountry.minLength &&
value.length <= _selectedCountry.maxLength
? null
: widget.invalidNumberMessage;
}
return validatorMessage;
},
maxLength: widget.disableLengthCheck ? null : _selectedCountry.maxLength,
keyboardType: widget.keyboardType,
inputFormatters: widget.inputFormatters,
enabled: widget.enabled,
keyboardAppearance: widget.keyboardAppearance,
autofocus: widget.autofocus,
textInputAction: widget.textInputAction,
autovalidateMode: widget.autovalidateMode,
);
}
Container _buildFlagsButton() {
return Container(
margin: widget.flagsButtonMargin,
child: DecoratedBox(
decoration: widget.dropdownDecoration,
child: InkWell(
borderRadius: widget.dropdownDecoration.borderRadius as BorderRadius?,
onTap: widget.enabled ? _changeCountry : null,
child: Padding(
padding: widget.flagsButtonPadding,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SizedBox(
width: 4,
),
if (widget.enabled &&
widget.showDropdownIcon &&
widget.dropdownIconPosition == IconPosition.leading) ...[
widget.dropdownIcon,
const SizedBox(width: 4),
],
if (widget.showCountryFlag) ...[
kIsWeb
? Image.asset(
'assets/flags/${_selectedCountry.code.toLowerCase()}.png',
package: 'intl_phone_field',
width: 32,
)
: Text(
_selectedCountry.flag,
style: const TextStyle(fontSize: 18),
),
const SizedBox(width: 8),
],
FittedBox(
child: Text(
'+${_selectedCountry.dialCode}',
style: widget.dropdownTextStyle,
),
),
if (widget.enabled &&
widget.showDropdownIcon &&
widget.dropdownIconPosition == IconPosition.trailing) ...[
const SizedBox(width: 4),
widget.dropdownIcon,
],
const SizedBox(width: 8),
],
),
),
),
),
);
}
}
enum IconPosition {
leading,
trailing,
}

View File

@@ -0,0 +1,79 @@
import 'countries.dart';
class NumberTooLongException implements Exception {}
class NumberTooShortException implements Exception {}
class InvalidCharactersException implements Exception {}
class PhoneNumber {
String countryISOCode;
String countryCode;
String number;
PhoneNumber({
required this.countryISOCode,
required this.countryCode,
required this.number,
});
factory PhoneNumber.fromCompleteNumber({required String completeNumber}) {
if (completeNumber == "") {
return PhoneNumber(countryISOCode: "", countryCode: "", number: "");
}
try {
Country country = getCountry(completeNumber);
String number;
if (completeNumber.startsWith('+')) {
number = completeNumber.substring(1 + country.dialCode.length + country.regionCode.length);
} else {
number = completeNumber.substring(country.dialCode.length + country.regionCode.length);
}
return PhoneNumber(
countryISOCode: country.code, countryCode: country.dialCode + country.regionCode, number: number);
} on InvalidCharactersException {
rethrow;
// ignore: unused_catch_clause
} on Exception catch (e) {
return PhoneNumber(countryISOCode: "", countryCode: "", number: "");
}
}
bool isValidNumber() {
Country country = getCountry(completeNumber);
if (number.length < country.minLength) {
throw NumberTooShortException();
}
if (number.length > country.maxLength) {
throw NumberTooLongException();
}
return true;
}
String get completeNumber {
return countryCode + number;
}
static Country getCountry(String phoneNumber) {
if (phoneNumber == "") {
throw NumberTooShortException();
}
final validPhoneNumber = RegExp(r'^[+0-9]*[0-9]*$');
if (!validPhoneNumber.hasMatch(phoneNumber)) {
throw InvalidCharactersException();
}
if (phoneNumber.startsWith('+')) {
return countries
.firstWhere((country) => phoneNumber.substring(1).startsWith(country.dialCode + country.regionCode));
}
return countries.firstWhere((country) => phoneNumber.startsWith(country.dialCode + country.regionCode));
}
@override
String toString() => 'PhoneNumber(countryISOCode: $countryISOCode, countryCode: $countryCode, number: $number)';
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,91 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:sefer_driver/constant/style.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../functions/crud.dart';
class NotificationCaptainController extends GetxController {
bool isLoading = false;
Map notificationData = {};
getNotifications() async {
isLoading = true;
update();
var res = await CRUD().get(
link: AppLink.getNotificationCaptain,
payload: {'driverID': box.read(BoxName.driverID)});
if (res == "failure") {
// MyDialog().getDialog('There is no notification yet'.tr, '', () {
// Get.back();
// Get.back();
// });
Get.dialog(
CupertinoAlertDialog(
title: Column(
children: [
const Icon(
CupertinoIcons.bell_slash_fill,
color: CupertinoColors.systemGrey,
size: 40,
),
const SizedBox(height: 12),
Text(
'There is no notification yet'.tr,
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
actions: [
CupertinoDialogAction(
onPressed: () {
Get.back();
Get.back();
},
child: Text('Back'.tr),
),
],
),
barrierDismissible: true,
transitionCurve: Curves.easeOutBack,
transitionDuration: const Duration(milliseconds: 200),
);
}
notificationData = jsonDecode(res);
// sql.insertData(notificationData['message'], TableName.captainNotification);
isLoading = false;
update();
}
updateNotification(String id) async {
await CRUD().post(
link: AppLink.updateNotificationCaptain,
payload: {'isShown': 'true', 'id': id},
);
}
addNotificationCaptain(String driverId, title, body, isPin) async {
await CRUD().post(link: AppLink.addNotificationCaptain, payload: {
'driverID': driverId,
'title': title,
'body': body,
'isPin': isPin
});
}
@override
void onInit() {
getNotifications();
super.onInit();
}
}

View File

@@ -0,0 +1,65 @@
import 'dart:convert';
import 'package:get/get.dart';
import 'package:sefer_driver/controller/firebase/firbase_messge.dart';
import '../../constant/box_name.dart';
import '../../constant/links.dart';
import '../../constant/style.dart';
import '../../main.dart';
import '../../views/widgets/elevated_btn.dart';
import '../functions/crud.dart';
class PassengerNotificationController extends GetxController {
bool isloading = false;
Map notificationData = {};
getNotifications() async {
isloading = true;
update();
var res = await CRUD().get(
link: AppLink.getNotificationPassenger,
payload: {'passenger_id': box.read(BoxName.passengerID)});
if (res == "failure") {
Get.defaultDialog(
title: 'There is no notification yet'.tr,
titleStyle: AppStyle.title,
middleText: '',
confirm: MyElevatedButton(
title: 'Back',
onPressed: () {
Get.back();
Get.back();
}));
}
notificationData = jsonDecode(res);
// sql.insertData(notificationData['message'], TableName.captainNotification);
isloading = false;
update();
}
updateNotification(String id) async {
await CRUD().post(
link: AppLink.updateNotificationPassenger,
payload: {'isShown': 'true', 'id': id},
);
Get.back();
getNotifications();
}
addNotificationToPassenger(String title, body) async {
var res = CRUD().post(link: AppLink.addNotificationPassenger, payload: {
'title': title,
'body': body,
});
FirebaseMessagesController()
.sendNotificationToPassengerToken(title, body, 'token', [], 'ding.wav');
}
@override
void onInit() {
getNotifications();
super.onInit();
}
}

View File

@@ -0,0 +1,184 @@
import 'dart:convert';
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/controller/functions/location_controller.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import '../../views/widgets/mydialoug.dart';
import '../functions/crud.dart';
class RideAvailableController extends GetxController {
bool isLoading = false;
Map rideAvailableMap = {};
late LatLng southwest;
late LatLng northeast;
LatLngBounds calculateBounds(double lat, double lng, double radiusInMeters) {
const double earthRadius = 6378137.0; // Earth's radius in meters
double latDelta = (radiusInMeters / earthRadius) * (180 / pi);
double lngDelta =
(radiusInMeters / (earthRadius * cos(pi * lat / 180))) * (180 / pi);
double minLat = lat - latDelta;
double maxLat = lat + latDelta;
double minLng = lng - lngDelta;
double maxLng = lng + lngDelta;
// Ensure the latitude is between -90 and 90
minLat = max(-90.0, minLat);
maxLat = min(90.0, maxLat);
// Ensure the longitude is between -180 and 180
minLng = (minLng + 180) % 360 - 180;
maxLng = (maxLng + 180) % 360 - 180;
// Ensure the bounds are in the correct order
if (minLng > maxLng) {
double temp = minLng;
minLng = maxLng;
maxLng = temp;
}
return LatLngBounds(
southwest: LatLng(minLat, minLng),
northeast: LatLng(maxLat, maxLng),
);
}
double calculateDistance(String startLocation) {
List<String> startLocationParts = startLocation.split(',');
double startLatitude = double.parse(startLocationParts[0]);
double startLongitude = double.parse(startLocationParts[1]);
// Assuming currentLocation is the driver's location
double currentLatitude = Get.find<LocationController>().latitude;
double currentLongitude = Get.find<LocationController>().longitude;
return Geolocator.distanceBetween(
currentLatitude,
currentLongitude,
startLatitude,
startLongitude,
);
}
// void sortRidesByDistance() {
// rideAvailableMap['message'].sort((a, b) {
// double distanceA = calculateDistance(a['start_location']);
// double distanceB = calculateDistance(b['start_location']);
// return distanceA.compareTo(distanceB);
// });
// }
getRideAvailable() async {
try {
isLoading = true;
update();
LatLngBounds bounds = calculateBounds(
Get.find<LocationController>().myLocation!.latitude,
Get.find<LocationController>().myLocation!.longitude,
4000);
var payload = {
'southwestLat': bounds.southwest.latitude.toString(),
'southwestLon': bounds.southwest.longitude.toString(),
'northeastLat': bounds.northeast.latitude.toString(),
'northeastLon': bounds.northeast.longitude.toString(),
};
var res =
await CRUD().get(link: AppLink.getRideWaiting, payload: payload);
if (res != 'failure') {
rideAvailableMap = jsonDecode(res);
isLoading = false;
update();
} else {
HapticFeedback.lightImpact();
Get.dialog(
CupertinoAlertDialog(
title: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
CupertinoIcons.car,
size: 44,
color: CupertinoColors.systemGrey,
),
const SizedBox(height: 12),
Text(
"No Rides Available".tr,
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
content: Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
"Please check back later for available rides.".tr,
style: const TextStyle(
fontSize: 13,
color: CupertinoColors.systemGrey,
),
),
),
actions: [
CupertinoDialogAction(
onPressed: () {
Get.back();
Get.back();
},
child: Text('OK'.tr),
),
],
),
barrierDismissible: true,
transitionCurve: Curves.easeOutBack,
transitionDuration: const Duration(milliseconds: 200),
);
}
} catch (e) {
isLoading = false;
update();
Get.dialog(
CupertinoAlertDialog(
title: const Icon(
CupertinoIcons.exclamationmark_triangle_fill,
color: CupertinoColors.systemRed,
size: 44,
),
content: Text(
"Error fetching rides. Please try again.".tr,
style: const TextStyle(fontSize: 14),
),
actions: [
CupertinoDialogAction(
onPressed: () => Get.back(),
child: Text('OK'.tr),
),
],
),
);
}
}
@override
void onInit() {
getRideAvailable();
super.onInit();
}
}

View File

@@ -0,0 +1,221 @@
import 'dart:io';
import 'dart:convert';
import '../../../print.dart';
abstract class LingoHunter {
/// Extracts translatable strings...
static Future<void> extractAndCreateTranslationFiles({
required String baseLang,
required List<String> langs,
String? projectDirectory,
String? outputDirectory,
bool translateBaseLang = true,
List<RegExp>? additionalRegExps,
bool overrideRegExps = false,
List<String> fileExtensions = const ['.dart'],
}) async {
// 1. Find project root (improved logic)
String projectRoot;
if (projectDirectory != null) {
// Use provided directory, but check if it's valid
if (!await Directory(projectDirectory).exists()) {
throw ArgumentError(
"The provided projectDirectory '$projectDirectory' does not exist.");
}
projectRoot = projectDirectory;
} else {
projectRoot = await _findProjectRoot(); // Use the corrected function
}
// 2. Use the project root as output directory if not specified
final String outputDir = outputDirectory ?? projectRoot;
// 3. Output Directory Verification (Create if necessary)
final Directory outputDirObj = Directory(outputDir);
if (!await outputDirObj.exists()) {
try {
await outputDirObj.create(recursive: true);
} catch (e) {
throw Exception(
"Failed to create output directory: $outputDir. Error: $e");
}
}
print("Project root directory: $projectRoot");
print("Output directory: $outputDir");
// 4. Extract translatable strings
final Set<String> strings = await extractStringsFromFlutterProject(
directory: projectRoot, // Use the validated projectRoot
additionalRegExps: additionalRegExps,
overrideRegExps: overrideRegExps,
fileExtensions: fileExtensions,
);
// 5. Generate translation files
await _createTranslationFiles(
strings: strings,
outputDirectory: outputDir,
baseLang: baseLang,
langs: langs,
translateBaseLang: translateBaseLang,
);
print("Successfully extracted strings and generated translation files.");
}
/// Finds the project's root directory (corrected)
static Future<String> _findProjectRoot() async {
Directory current = Directory.current;
int maxIterations = 10; // Prevent infinite loop
int count = 0;
while (count < maxIterations) {
if (await File('${current.path}/pubspec.yaml').exists()) {
return current.path; // Return the directory *containing* pubspec.yaml
}
if (current.path == current.parent.path) {
break; // Reached root, stop searching
}
current = current.parent;
count++;
}
// If `pubspec.yaml` was not found, throw an exception
throw Exception(
"`pubspec.yaml` not found in the current directory or its parents.");
}
/// Extracts translatable strings (no changes needed here)
static Future<Set<String>> extractStringsFromFlutterProject({
required String directory,
List<RegExp>? additionalRegExps,
bool overrideRegExps = false,
List<String> fileExtensions = const ['.dart'],
}) async {
// ... (rest of the function remains the same) ...
final List<RegExp> defaultPatterns = [
RegExp(r'"([^"]+)"\.tr\(\)'), // "string".tr()
RegExp(r"'([^']+)'\.tr\(\)"), // 'string'.tr()
RegExp(r'"([^"]+)"\.tr'), // "string".tr
RegExp(r"'([^']+)'\.tr"), // 'string'.tr
RegExp(r'"([^"]+)"\.tr\(\w+\)'), // "string".tr(context)
RegExp(r"'([^']+)'\.tr\(\w+\)"), // 'string'.tr(context)
RegExp(r'context\.tr\("([^"]+)"\)'), // context.tr("string")
RegExp(r"context\.tr\('([^']+)'\)"), // context.tr('string')
RegExp(r'tr\(\w+, "([^"]+)"\)'), // tr(context, "string")
RegExp(r"tr\(\w+, '([^']+)'\)"), // tr(context, 'string')
RegExp(r'tr\("([^"]+)"\)'), // tr("string")
RegExp(r"tr\('([^']+)'\)"), // tr('string')
RegExp(r'"([^"]+)"\.tr\(args: \[.*?\]\)'), // "string".tr(args: [])
RegExp(r'"([^"]+)"\.plural\(\d+\)'), // "string".plural(3)
//Intl Package Patterns
RegExp(r'AppLocalizations\.of\(context\)!\.translate\("([^"]+)"\)'),
];
// Determine the patterns to use
List<RegExp> patterns;
if (overrideRegExps && additionalRegExps != null) {
patterns = additionalRegExps;
} else {
patterns = [...defaultPatterns];
if (additionalRegExps != null) {
patterns.addAll(additionalRegExps);
}
}
final Set<String> strings = {};
final Directory projectDirObj = Directory(directory);
// Check if the directory exists *before* listing
if (!await projectDirObj.exists()) {
throw ArgumentError("The directory '$directory' does not exist.");
}
final List<FileSystemEntity> entities =
await projectDirObj.list(recursive: true).toList();
// Filter files by the specified extensions
final List<File> filteredFiles = entities
.whereType<File>()
.where((file) => fileExtensions.any((ext) => file.path.endsWith(ext)))
.toList();
// Extract strings from files
for (final File file in filteredFiles) {
final String content = await file.readAsString();
for (final RegExp pattern in patterns) {
final Iterable<RegExpMatch> matches = pattern.allMatches(content);
for (final RegExpMatch match in matches) {
if (match.groupCount >= 1 && match.group(1) != null) {
strings.add(match.group(1)!);
}
}
}
}
return strings;
}
/// Creates translation files (no changes needed)
static Future<void> _createTranslationFiles({
required Set<String> strings,
required String outputDirectory,
required String baseLang,
required List<String> langs,
bool translateBaseLang = true,
}) async {
// ... (rest of the function remains the same) ...
final Directory outputDir = Directory(outputDirectory);
if (!await outputDir.exists()) {
Log.print('outputDir: ${outputDir}');
await outputDir.create(recursive: true);
}
// Always create the base language file, even if `translateBaseLang` is false
final String baseFilePath = '$outputDirectory/translations_$baseLang.json';
final Map<String, String> baseStrings = {
for (final string in strings) string: translateBaseLang ? string : ""
};
await _writeTranslationFile(baseFilePath, baseStrings);
for (final String lang in langs) {
final String langFilePath = '$outputDirectory/translations_$lang.json';
final Map<String, String> langStrings = {
for (final string in strings) string: ""
};
await _writeTranslationFile(langFilePath, langStrings);
}
}
/// Writes a translation file (no changes needed)
static Future<void> _writeTranslationFile(
String filePath, Map<String, String> strings) async {
// ... (rest of the function remains the same) ...
final File file = File(filePath);
final StringBuffer content = StringBuffer();
content.writeln('{');
int index = 0;
for (final MapEntry<String, String> entry in strings.entries) {
final String comma = (index < strings.length - 1) ? ',' : '';
final String key =
jsonEncode(entry.key).substring(1, jsonEncode(entry.key).length - 1);
final String value = entry.value.isEmpty
? ""
: jsonEncode(entry.value)
.substring(1, jsonEncode(entry.value).length - 1);
content.writeln(' "$key": "$value"$comma');
index++;
}
content.writeln('}');
await file.writeAsString(content.toString());
}
}

View File

@@ -0,0 +1,71 @@
import 'dart:convert';
import 'package:sefer_driver/views/widgets/elevated_btn.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/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
class DriverWalletHistoryController extends GetxController {
bool isLoading = false;
List archive = [];
List weeklyList = [];
getArchivePayment() async {
isLoading = true;
update();
var res = await CRUD().getWallet(
link: AppLink.getWalletByDriver,
payload: {'driverID': box.read(BoxName.driverID)});
if (res == 'failure') {
Get.defaultDialog(
barrierDismissible: false,
title: 'There is no data yet.'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'Back'.tr,
onPressed: () {
Get.back();
// Get.back();
},
));
}
archive = jsonDecode(res)['message'];
isLoading = false;
update();
}
getWeekllyArchivePayment() async {
isLoading = true;
update();
var res = await CRUD().getWallet(
link: AppLink.getDriverWeekPaymentMove,
payload: {'driverID': box.read(BoxName.driverID)});
if (res == 'failure') {
Get.defaultDialog(
barrierDismissible: false,
title: 'There is no data yet.'.tr,
middleText: '',
confirm: MyElevatedButton(
title: 'Back'.tr,
onPressed: () {
Get.back();
// Get.back();
},
));
} else {
weeklyList = jsonDecode(res)['message'];
}
isLoading = false;
update();
}
@override
void onInit() {
// getArchivePayment();
super.onInit();
}
}

View File

@@ -0,0 +1,730 @@
import 'dart:convert';
import 'package:sefer_driver/constant/api_key.dart';
import 'package:sefer_driver/constant/style.dart';
import 'package:sefer_driver/controller/functions/tts.dart';
import 'package:sefer_driver/controller/payment/paymob/paymob_response.dart';
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
import 'package:sefer_driver/views/widgets/error_snakbar.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:flutter_paypal/flutter_paypal.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:get/get.dart';
import 'package:local_auth/local_auth.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../constant/info.dart';
import '../../constant/links.dart';
import '../../main.dart';
import '../../print.dart';
import '../functions/crud.dart';
import '../functions/encrypt_decrypt.dart';
import '../functions/toast.dart';
import 'paymob/paymob_wallet.dart';
class PaymentController extends GetxController {
bool isLoading = false;
bool isWalletChecked = true;
bool isCashChecked = false;
bool isWalletFound = false;
bool isPromoSheetDialogue = false;
final formKey = GlobalKey<FormState>();
final promo = TextEditingController();
// double totalPassenger =
// double.parse(Get.find<MapDriverController>().totalPricePassenger);
int? selectedAmount = 0;
List<dynamic> totalPassengerWalletDetails = [];
final walletphoneController = TextEditingController();
String passengerTotalWalletAmount = '';
String ip = '1';
DateTime now = DateTime.now();
late int timestamp;
void updateSelectedAmount(int value) {
selectedAmount = value;
update();
}
void changePromoSheetDialogue() {
isPromoSheetDialogue = !isPromoSheetDialogue;
update();
}
getPassengerWallet() async {
isLoading = true;
update();
await CRUD().getWallet(
link: AppLink.getWalletByPassenger,
payload: {'passenger_id': box.read(BoxName.passengerID)}).then((value) {
box.write(BoxName.passengerWalletTotal,
jsonDecode(value)['message'][0]['total'].toString());
});
isLoading = false;
update();
}
addPassengerWallet() async {
isLoading = true;
update();
// double sallaryAccountNowBeforeAdding =
// double.parse(box.read(BoxName.passengerWalletTotal).toString());
await CRUD().postWallet(link: AppLink.addPassengersWallet, payload: {
'passenger_id': box.read(BoxName.passengerID).toString(),
'balance': selectedAmount.toString()
}).then((value) {
getPassengerWallet();
// sallaryAccountNowBeforeAdding = sallaryAccountNowBeforeAdding +
// double.parse(selectedAmount.toString());
// box.write(BoxName.passengerWalletTotal, sallaryAccountNowBeforeAdding);
});
isLoading = false;
update();
}
// void onChangedPaymentMethodWallet(bool? value) {
// if (box.read(BoxName.passengerWalletTotal) == null ||
// double.parse(box.read(BoxName.passengerWalletTotal).toString()) <
// totalPassenger) {
// isWalletChecked = false;
// isWalletChecked ? isCashChecked = true : isCashChecked = true;
// update();
// } else {
// isWalletChecked = !isWalletChecked;
// isWalletChecked ? isCashChecked = false : isCashChecked = true;
// update();
// }
// }
// void onChangedPaymentMethodCash(bool? value) {
// if (box.read(BoxName.passengerWalletTotal) == null ||
// double.parse(box.read(BoxName.passengerWalletTotal)) < totalPassenger) {
// isWalletChecked = false;
// isCashChecked = !isCashChecked;
// isCashChecked ? isWalletChecked = false : isWalletChecked = false;
// update();
// } else {
// isCashChecked = !isCashChecked;
// isCashChecked ? isWalletChecked = false : isWalletChecked = true;
// update();
// }
// }
late String clientSecret;
Future<void> makePaymentStripe(
double amount, String currency, Function method) async {
var newAmount = (amount * 100).toInt();
try {
// Check if local authentication is available
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
);
if (didAuthenticate) {
// User authenticated successfully, proceed with payment
clientSecret = await getClientSecret(newAmount.toString(), currency);
await initializePaymentSheet(clientSecret);
await Stripe.instance.presentPaymentSheet();
method();
} else {
// Authentication failed, handle accordingly
}
} else {
// Local authentication not available, proceed with payment without authentication
clientSecret = await getClientSecret(newAmount.toString(), currency);
await initializePaymentSheet(clientSecret);
await Stripe.instance.presentPaymentSheet();
method();
}
} catch (e) {
rethrow;
}
}
Future<void> initializePaymentSheet(String clientSecret) async {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
// intentConfiguration: IntentConfiguration.fromJson({}),
// applePay: const PaymentSheetApplePay(merchantCountryCode: 'US'),
// googlePay: const PaymentSheetGooglePay(merchantCountryCode: 'US'),
paymentIntentClientSecret: clientSecret,
merchantDisplayName: AppInformation.appName,
billingDetails: BillingDetails(
name: (box.read(BoxName.nameDriver)),
email: (box.read(BoxName.emailDriver)),
phone: (box.read(BoxName.phoneDriver)),
address: Address(
city: 'city',
country: box.read(BoxName.countryCode), //'United States'
line1: '',
line2: '',
postalCode: '12345',
state: box.read(BoxName.countryCode) // 'Boston'
)),
allowsDelayedPaymentMethods: true,
customerEphemeralKeySecret: Stripe.merchantIdentifier,
appearance: const PaymentSheetAppearance(
shapes: PaymentSheetShape(borderRadius: 12),
colors: PaymentSheetAppearanceColors(
background: AppColor.secondaryColor,
),
),
billingDetailsCollectionConfiguration:
const BillingDetailsCollectionConfiguration(
name: CollectionMode.automatic,
phone: CollectionMode.automatic,
email: CollectionMode.automatic,
// address: CollectionMode.automatic,
),
),
);
}
Future<String> getClientSecret(String amount, currency) async {
var res = await CRUD().postStripe(
link: 'https://api.stripe.com/v1/payment_intents',
payload: {
'amount': amount,
'currency': currency,
'payment_method_types[0]': 'card'
},
);
// Convert the res object to a JSON object
final jsonResponse = jsonDecode(res);
// Check if the client_secret property exists and is not null
if (jsonResponse.containsKey('client_secret') &&
jsonResponse['client_secret'] != null) {
// Return the client_secret property
return jsonResponse['client_secret'] as String;
} else {
throw Exception('Failed to fetch client secret');
}
}
Future<void> configure3dSecureFuture() async {
await Stripe.instance.openApplePaySetup();
}
Future<void> makePaymentPayPal(BuildContext context) async {
try {
// Check if local authentication is available
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
);
if (didAuthenticate) {
// User authenticated successfully, proceed with payment
if (selectedAmount != 0) {
changePromoSheetDialogue();
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => UsePaypal(
sandboxMode: true,
clientId: AK.payPalClientId,
secretKey: AK.payPalSecret,
returnURL: AppInformation.website,
cancelURL: "${AppInformation.website}/cancel",
transactions: [
{
"amount": {
//sb-opsju26682403@personal.example.com
"total": '$selectedAmount',
"currency": box.read(BoxName.countryCode) == 'Egypt'
? 'EGP'
: "JOD",
"details": {
"subtotal": '$selectedAmount',
"shipping": '0',
"shipping_discount": 0
}
},
"description": "The payment transaction description.",
"payment_options": const {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"item_list": {
"items": [
{
"name": "${AppInformation.appName} Wallet ",
"quantity": 1,
"price": '$selectedAmount',
"currency": "USD"
}
],
// shipping address is not required though
"shipping_address": const {
"recipient_name":
"${AppInformation.appName} Wallet",
"line1": "Shafa Badran",
"line2": "",
"city": "Amman",
"country_code": "JO",
"postal_code": "13112",
"phone": "+962798583052",
"state": "Amman"
},
}
}
],
note: "Contact us for any questions on your order.".tr,
onSuccess: (Map params) async {
addPassengerWallet();
changePromoSheetDialogue();
await getPassengerWallet();
},
onError: (error) {
Toast.show(context, ' $error'.tr, AppColor.redColor);
},
onCancel: (params) {
Toast.show(context, 'Pyament Cancelled .'.tr,
AppColor.yellowColor);
}),
),
);
} else {
Toast.show(context, 'You will choose one of above !'.tr,
AppColor.redColor);
}
} else {
// Authentication failed, handle accordingly
}
}
} catch (e) {
rethrow;
}
}
Map licenseDetailsMap = {};
Future getLicenseInfo() async {
var res = await CRUD().get(
link: AppLink.getLicense,
payload: {'driverID': box.read(BoxName.driverID)});
licenseDetailsMap = jsonDecode(res);
}
Future createConnectAccount() async {
String url = 'https://api.stripe.com/v1/accounts';
await getLicenseInfo();
DateTime dob =
DateTime.parse(licenseDetailsMap['message'][0]['dateOfBirth']);
int currentTimestamp =
(DateTime.now().millisecondsSinceEpoch / 1000).round();
int day = dob.day;
int month = dob.month;
int year = dob.year;
await getIpAddress();
final body = {
"type": "custom",
"business_profile[name]": box.read(BoxName.nameDriver),
"business_profile[product_description]": "Captain",
"business_profile[support_address][city]": "San Francisco",
"business_profile[support_address][country]": 'US',
"business_profile[support_address][line1]":
licenseDetailsMap['message'][0]['address'].toString().trim()[0],
"business_profile[support_address][postal_code]":
licenseDetailsMap['message'][0]['postalCode'],
"business_profile[support_address][state]": "MA",
"business_profile[support_email]": "support@sefer.live",
"business_profile[support_phone]": "555-123-4567",
"business_profile[url]": "https://sefer.live",
"business_type": "individual",
"capabilities[card_payments][requested]": "true",
"capabilities[transfers][requested]": "true",
"company[address][city]": "ATTLEBORO",
"company[address][country]": "US",
"company[address][line1]": "1249 NEWPORT AVE",
"company[address][postal_code]": "02703 ",
"company[address][state]": "MA",
"company[name]": AppInformation.companyName,
"country": "us",
"default_currency": "usd",
"email": "support@sefer.live",
// "individual[ssn]": "123-45-6789", //
"individual[id_number]": licenseDetailsMap['message'][0]['documentNo'],
// "individual[id_type]": "drivers_license", //
"individual[address][city]": "ATTLEBORO",
"individual[address][country]": "US",
"individual[address][line1]": licenseDetailsMap['message'][0]['address'],
// "individual[address][postal_code]": licenseDetailsMap['message'][0]
// ['postalCode'],
"individual[address][state]": "MA",
// "individual[ssn_last_4]": '1111', ////////
"individual[dob][day]": day.toString(),
"individual[dob][month]": month.toString(),
"individual[dob][year]": year.toString(),
"individual[email]": box.read(BoxName.emailDriver),
"individual[first_name]":
licenseDetailsMap['message'][0]['name'].toString().split(' ')[0],
"individual[gender]":
licenseDetailsMap['message'][0]['sex'] == 'M' ? 'male' : 'female',
"individual[last_name]":
licenseDetailsMap['message'][0]['name'].toString().split(' ')[1],
// "individual[phone]": box.read(BoxName.phoneDriver),////////////
"tos_acceptance[date]": currentTimestamp.toString(),
"tos_acceptance[ip]": ip.toString()
};
final response = await CRUD().postStripe(
link: url,
payload: body,
);
final responseData = jsonDecode(response);
final accountId = responseData['id'];
box.write(BoxName.accountIdStripeConnect, accountId);
await updateCaptainAccountBank();
return accountId;
}
Future updateCaptainAccountBank() async {
var res = await CRUD().post(link: AppLink.updateAccountBank, payload: {
'id': box.read(BoxName.driverID),
'accountBank': box.read(BoxName.accountIdStripeConnect),
});
if (jsonDecode(res)['status'] == 'success') {
mySnackbarSuccess('Account Updated'.tr);
// Get.snackbar('Account Updated', '');
}
}
Future<String> createTransactionToCaptain(
String amount, String account) async {
String url = 'https://api.stripe.com/v1/transfers';
final body = {
'amount': amount, //amount
'currency': 'usd',
'destination': account //'acct_1OKIjQRgcWrsdyDT' //account id
};
final response = await CRUD().postStripe(
link: url,
payload: body,
);
final responseData = jsonDecode(response);
final transactionId = responseData['id'];
return transactionId;
}
Future getIpAddress() async {
var url = Uri.parse('https://api.ipify.org?format=json');
var response = await http.get(url);
if (response.statusCode == 200) {
ip = jsonDecode(response.body)['ip'];
} else {}
}
// 'https://accept.paymob.com/unifiedcheckout/?publicKey=egy_pk_live_mbjDC9Ni6FSHKmsz8sOHiVk2xd7oWRve&clientSecret=egy_sk_live_c0904e9cf04506ae64f818d4e075b4a957e3713fdf7a22cb7da30a29e72442b5'
Future<void> payWithPayMob(
BuildContext context, String amount, currency, Function method) async {
String newAmount = (double.parse(amount) * 100).toStringAsFixed(2);
try {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
final PaymobResponse? response = await PaymobPayment.instance.pay(
context: context,
currency: currency, //"EGP",
amountInCents: newAmount, // 19.00 EGP
billingData: PaymobBillingData(),
onPayment: (PaymobResponse response) {},
);
if (response!.responseCode == 'APPROVED') {
Get.defaultDialog(
barrierDismissible: false,
title: 'Payment Successful'.tr,
titleStyle: AppStyle.title,
content: Text(
'The payment was approved.'.tr,
style: AppStyle.title,
),
confirm: MyElevatedButton(
title: 'OK'.tr,
kolor: AppColor.greenColor,
onPressed: () async {
Get.back();
method();
},
),
);
} else {
Get.defaultDialog(
barrierDismissible: false,
// backgroundColor: AppColor.redColor,
title: 'Payment Failed'.tr,
content: Text(
'The payment was not approved. Please try again.'.tr,
textAlign: TextAlign.center,
style: AppStyle.title,
),
confirm: MyElevatedButton(
title: 'OK'.tr,
kolor: AppColor.redColor,
onPressed: () async {
Get.back();
},
),
);
}
} else {
Get.snackbar("Authentication Failed",
"Please enable Face ID or Fingerprint in your settings.");
// Authentication failed, handle accordingly
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
// Authentication failed, handle accordingly
}
// else {
// final PaymobResponse? response = await PaymobPayment.instance.pay(
// context: context,
// currency: currency, //"EGP",
// amountInCents: newAmount, // 19.00 EGP
// billingData: PaymobBillingData(),
// onPayment: (PaymobResponse response) {},
// );
// if (response!.responseCode == 'APPROVED') {
// Get.defaultDialog(
// barrierDismissible: false,
// title: 'Payment Successful'.tr,
// titleStyle: AppStyle.title,
// // backgroundColor: AppColor.greenColor,
// content: Text(
// 'The payment was approved.'.tr,
// style: AppStyle.title,
// ),
// confirm: MyElevatedButton(
// kolor: AppColor.greenColor,
// title: 'OK'.tr,
// onPressed: () async {
// Get.back();
// method();
// },
// ),
// );
// } else {
// Get.defaultDialog(
// barrierDismissible: false,
// // backgroundColor: AppColor.redColor,
// title: 'Payment Failed'.tr,
// content: Column(
// children: [
// IconButton(
// onPressed: () {
// Get.find<TextToSpeechController>().speakText(
// 'The payment was not approved. Please try again.'.tr,
// );
// },
// icon: const Icon(Icons.headphones),
// ),
// Text(
// 'The payment was not approved. Please try again.'.tr,
// textAlign: TextAlign.center,
// style: AppStyle.title,
// ),
// Text(
// '${'The reason is'.tr} ${response.message!.tr}',
// textAlign: TextAlign.center,
// style: AppStyle.title.copyWith(color: AppColor.redColor),
// ),
// ],
// ),
// confirm: MyElevatedButton(
// title: 'OK'.tr,
// kolor: AppColor.redColor,
// onPressed: () async {
// Get.back();
// },
// ),
// );
// }
// }
} catch (e) {
Get.defaultDialog(
title: 'Error'.tr,
content: Text(
'An error occurred during the payment process.'.tr,
style: AppStyle.title,
),
);
rethrow;
}
}
Future<void> payWithPayMobWallet(
BuildContext context, String amount, currency, Function method) async {
String newAmount = (double.parse(amount) * 100).toStringAsFixed(2);
try {
bool isAvailable = await LocalAuthentication().isDeviceSupported();
if (isAvailable) {
// Authenticate the user
bool didAuthenticate = await LocalAuthentication().authenticate(
localizedReason: 'Use Touch ID or Face ID to confirm payment',
options: AuthenticationOptions(
biometricOnly: true,
sensitiveTransaction: true,
));
if (didAuthenticate) {
final PaymobResponseWallet? response =
await PaymobPaymentWallet.instance.pay(
context: context,
currency: currency, //"EGP",
amountInCents: newAmount, // 19.00 EGP
billingData: PaymobBillingDataWallet(),
onPayment: (PaymobResponseWallet response) {},
);
if (response!.success == true &&
response.message.toString() == 'Approved') {
Toast.show(context, 'Payment Successful'.tr, AppColor.greenColor);
method();
} else {
Get.defaultDialog(
barrierDismissible: false,
// backgroundColor: AppColor.redColor,
title: 'Payment Failed'.tr,
content: Column(
children: [
IconButton(
onPressed: () {
Get.find<TextToSpeechController>().speakText(
'The payment was not approved. Please try again.'.tr,
);
},
icon: const Icon(Icons.headphones),
),
Text(
'The payment was not approved. Please try again.'.tr,
textAlign: TextAlign.center,
style: AppStyle.title,
),
Text(
'${'The reason is'.tr} ${response.message!.tr}',
textAlign: TextAlign.center,
style: AppStyle.title.copyWith(color: AppColor.redColor),
),
],
),
confirm: MyElevatedButton(
title: 'OK'.tr,
kolor: AppColor.redColor,
onPressed: () async {
Get.back();
},
),
);
}
} else {
// Authentication failed, handle accordingly
MyDialog().getDialog('Authentication failed'.tr, ''.tr, () {
Get.back();
});
}
} else {
MyDialog().getDialog('Biometric Authentication'.tr,
'You should use Touch ID or Face ID to confirm payment'.tr, () {
Get.back();
});
// final PaymobResponse? response = await PaymobPayment.instance.pay(
// context: context,
// currency: currency, //"EGP",
// amountInCents: newAmount, // 19.00 EGP
// billingData: PaymobBillingData(),
// onPayment: (PaymobResponse response) {},
// );
// // if (response!.responseCode == 'APPROVED') {
// if (response!.responseCode == '200' && response.success == true) {
// Toast.show(context, 'Payment Successful'.tr, AppColor.greenColor);
// method();
// Get.defaultDialog(
// barrierDismissible: false,
// title: 'Payment Successful'.tr,
// titleStyle: AppStyle.title,
// // backgroundColor: AppColor.greenColor,
// content: Text(
// 'The payment was approved.'.tr,
// style: AppStyle.title,
// ),
// confirm: MyElevatedButton(
// kolor: AppColor.greenColor,
// title: 'OK'.tr,
// onPressed: () async {
// Get.back();
// method();
// },
// ),
// );
// } else {
// Get.defaultDialog(
// barrierDismissible: false,
// // backgroundColor: AppColor.redColor,
// title: 'Payment Failed'.tr,
// content: Text(
// 'The payment was not approved. Please try again.'.tr,
// textAlign: TextAlign.center,
// style: AppStyle.title,
// ),
// confirm: MyElevatedButton(
// title: 'OK'.tr,
// kolor: AppColor.redColor,
// onPressed: () async {
// Get.back();
// },
// ),
// );
// }
}
} catch (e) {
Get.defaultDialog(
title: 'Error'.tr,
content: Text(
'An error occurred during the payment process.'.tr,
style: AppStyle.title,
),
);
rethrow;
}
}
@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

@@ -0,0 +1,154 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:dio/dio.dart' as dio;
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../constant/api_key.dart';
import '../../main.dart';
import '../functions/encrypt_decrypt.dart';
class PaymobManager extends GetxController {
String authanticationToken1 = "";
String orderId1 = "";
Future<String> getPaymentKey(int amount, String currency) async {
try {
String authanticationToken = await _getAuthanticationToken();
int orderId = await _getOrderId(
authanticationToken: authanticationToken,
amount: (100 * amount).toString(),
currency: currency,
);
String paymentKey = await _getPaymentKey(
authanticationToken: authanticationToken,
amount: (100 * amount).toString(),
currency: currency,
orderId: orderId.toString(),
);
authanticationToken1 = authanticationToken.toString();
orderId1 = orderId.toString();
update();
return paymentKey;
} catch (e) {
throw Exception();
}
}
Future<void> payWithPayMob(int amount, String currency) async {
// 1. Fetch Payment Key (Assuming PaymobManager is a custom class)
String paymentToken;
try {
paymentToken = await PaymobManager().getPaymentKey(amount, currency);
} on Exception catch (e) {
// Handle errors gracefully, e.g., display error message to user
return;
}
// 2. Prepare Payment Data Payload
final Map<String, dynamic> data = {
"source": {
"identifier": "01010101010", // Replace with actual source identifier
"subtype": "WALLET",
},
"payment_token": paymentToken,
};
// 3. Make Payment Request using Dio
final dio = Dio();
try {
final response = await dio.post(
'https://accept.paymobsolutions.com/api/acceptance/payments/pay',
data: data,
);
// 4. Handle Payment Response
if (response.statusCode == 200) {
final paymentData = response.data; // Assuming JSON response
// Navigate to success screen or display success message
launchUrl(Uri.parse(paymentData['iframe_redirection_url']));
} else {
// Payment failed: Handle errors (e.g., display error message)
}
} on DioError catch (e) {
// Handle network or Dio-related errors
}
}
Future<String> _getStatusAfterPaid() async {
final dio.Response response = await Dio().post(
"https://accept.paymob.com/api/ecommerce/orders/transaction_inquiry",
data: {
"auth_token": authanticationToken1,
"merchant_order_id": "970960",
"order_id": orderId1
});
return response.data["success"];
}
Future<String> _getAuthanticationToken() async {
final dio.Response response =
await Dio().post("https://accept.paymob.com/api/auth/tokens", data: {
"api_key": AK.payMobApikey,
'username': AK.usernamePayMob,
"password": AK.passwordPayMob,
});
return response.data["token"];
}
Future<int> _getOrderId({
required String authanticationToken,
required String amount,
required String currency,
}) async {
final dio.Response response = await Dio()
.post("https://accept.paymob.com/api/ecommerce/orders", data: {
"auth_token": authanticationToken,
"amount_cents": amount,
"currency": currency,
"delivery_needed": "false",
"items": [],
});
return response.data["id"];
}
Future<String> _getPaymentKey({
required String authanticationToken,
required String orderId,
required String amount,
required String currency,
}) async {
final dio.Response response = await Dio()
.post("https://accept.paymob.com/api/acceptance/payment_keys", data: {
"expiration": 200,
"auth_token": authanticationToken.toString(),
"order_id": orderId.toString(),
"integration_id":
4556056, ////todo wallet or online card int.parse(AK.integrationIdPayMob),
"lock_order_when_paid": "false",
"amount_cents": amount,
"currency": currency,
"billing_data": {
"first_name": (box.read(BoxName.nameDriver)),
"last_name": (box.read(BoxName.lastNameDriver)),
"email": (box.read(BoxName.emailDriver)),
"phone_number": (box.read(BoxName.phoneDriver)),
"apartment": "NA",
"floor": "NA",
"street": "NA",
"building": "NA",
"shipping_method": "NA",
"postal_code": "NA",
"city": "NA",
"country": box.read(BoxName.countryCode),
"state": "NA"
},
});
return response.data["token"];
}
}

View File

@@ -0,0 +1,326 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/controller/functions/encrypt_decrypt.dart';
import 'package:sefer_driver/main.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class PaymobResponse {
bool success;
String? transactionID;
String? responseCode;
String? message;
PaymobResponse({
this.transactionID,
required this.success,
this.responseCode,
this.message,
});
factory PaymobResponse.fromJson(Map<String, dynamic> json) {
return PaymobResponse(
success: json['success'] == 'true',
transactionID: json['id'],
message: json['message'],
responseCode: json['txn_response_code'],
);
}
}
class PaymobPayment {
static PaymobPayment instance = PaymobPayment();
bool _isInitialized = false;
final Dio _dio = Dio();
final _baseURL = 'https://accept.paymob.com/api/';
late String _apiKey;
late int _integrationID;
late int _iFrameID;
late String _iFrameURL;
late int _userTokenExpiration;
/// Initializing PaymobPayment instance.
Future<bool> initialize({
/// It is a unique identifier for the merchant which used to authenticate your requests calling any of Accept's API.
/// from dashboard Select Settings -> Account Info -> API Key
required String apiKey,
/// from dashboard Select Developers -> Payment Integrations -> Online Card ID
required int integrationID,
/// from paymob Select Developers -> iframes
required int iFrameID,
/// The expiration time of this payment token in seconds. (The maximum is 3600 seconds which is an hour)
int userTokenExpiration = 300,
}) async {
if (_isInitialized) {
return true;
}
_dio.options.baseUrl = _baseURL;
_dio.options.validateStatus = (status) => true;
_apiKey = apiKey;
_integrationID = integrationID;
_iFrameID = iFrameID;
_iFrameURL =
'https://accept.paymobsolutions.com/api/acceptance/iframes/$_iFrameID?payment_token=';
_isInitialized = true;
_userTokenExpiration = userTokenExpiration;
return _isInitialized;
}
/// Get authentication token, which is valid for one hour from the creation time.
Future<String> _getAuthToken() async {
try {
final response = await _dio.post(
'auth/tokens',
data: {
'api_key': _apiKey,
},
);
return response.data['token'];
} catch (e) {
rethrow;
}
}
/// At this step, you will register an order to Accept's database, so that you can pay for it later using a transaction
Future<int> _addOrder({
required String authToken,
required String currency,
required String amount,
required List items,
}) async {
try {
final response = await _dio.post(
'ecommerce/orders',
data: {
"auth_token": authToken,
"delivery_needed": "false",
"amount_cents": amount,
"currency": currency,
"items": items,
},
);
return response.data['id'];
} catch (e) {
rethrow;
}
}
/// At this step, you will obtain a payment_key token. This key will be used to authenticate your payment request. It will be also used for verifying your transaction request metadata.
Future<String> _getPurchaseToken({
required String authToken,
required String currency,
required int orderID,
required String amount,
required PaymobBillingData billingData,
}) async {
final response = await _dio.post(
'acceptance/payment_keys',
data: {
"auth_token": authToken,
"amount_cents": amount,
"expiration": _userTokenExpiration,
"order_id": orderID,
"billing_data": billingData,
"currency": currency,
"integration_id": _integrationID,
"lock_order_when_paid": "false"
},
);
final message = response.data['message'];
if (message != null) {
throw Exception(message);
}
return response.data['token'];
}
/// Proceed to pay with only calling this function.
/// Opens a WebView at Paymob redirectedURL to accept user payment info.
Future<PaymobResponse?> pay(
{
/// BuildContext for navigation to WebView
required BuildContext context,
/// Which Currency you would pay in.
required String currency,
/// Payment amount in cents EX: 20000 is an 200 EGP
required String amountInCents,
/// Optional Callback if you can use return result of pay function or use this callback
void Function(PaymobResponse response)? onPayment,
/// list of json objects contains the contents of the purchase.
List? items,
/// The billing data related to the customer related to this payment.
PaymobBillingData? billingData}) async {
if (!_isInitialized) {
throw Exception(
'PaymobPayment is not initialized call:`PaymobPayment.instance.initialize`');
}
final authToken = await _getAuthToken();
final orderID = await _addOrder(
authToken: authToken,
currency: currency,
amount: amountInCents,
items: items ?? [],
);
final purchaseToken = await _getPurchaseToken(
authToken: authToken,
currency: currency,
orderID: orderID,
amount: amountInCents,
billingData: billingData ?? PaymobBillingData(),
);
if (context.mounted) {
final response = await PaymobIFrame.show(
context: context,
redirectURL: _iFrameURL + purchaseToken,
onPayment: onPayment,
);
return response;
}
return null;
} //51624
}
class PaymobBillingData {
String? email;
String? firstName;
String? lastName;
String? phoneNumber;
String? apartment;
String? floor;
String? street;
String? building;
String? postalCode;
String? city;
String? state;
String? country;
String? shippingMethod;
PaymobBillingData({
this.email,
this.firstName,
this.lastName,
this.phoneNumber,
this.apartment,
this.floor,
this.street,
this.building,
this.postalCode,
this.city,
this.state,
this.country,
this.shippingMethod,
});
Map<String, dynamic> toJson() {
return {
"email": (box.read(BoxName.emailDriver)),
"first_name": box.read(BoxName.nameDriver),
"last_name": box.read(BoxName.nameDriver),
"phone_number": (box.read(BoxName.phoneDriver)),
"apartment": apartment ?? "NA",
"floor": floor ?? "NA",
"building": building ?? "NA",
"street": street ?? "NA",
"postal_code": postalCode ?? "NA",
"city": city ?? "NA",
"state": state ?? "NA",
"country": country ?? "NA",
"shipping_method": shippingMethod ?? "NA",
};
}
}
class PaymobIFrame extends StatefulWidget {
const PaymobIFrame({
Key? key,
required this.redirectURL,
this.onPayment,
}) : super(key: key);
final String redirectURL;
final void Function(PaymobResponse)? onPayment;
static Future<PaymobResponse?> show({
required BuildContext context,
required String redirectURL,
void Function(PaymobResponse)? onPayment,
}) =>
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return PaymobIFrame(
onPayment: onPayment,
redirectURL: redirectURL,
);
},
),
);
@override
State<PaymobIFrame> createState() => _PaymobIFrameState();
}
class _PaymobIFrameState extends State<PaymobIFrame> {
WebViewController? controller;
@override
void initState() {
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onNavigationRequest: (NavigationRequest request) {
if (request.url.contains('txn_response_code') &&
request.url.contains('success') &&
request.url.contains('id')) {
final params = _getParamFromURL(request.url);
final response = PaymobResponse.fromJson(params);
if (widget.onPayment != null) {
widget.onPayment!(response);
}
Navigator.pop(context, response);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse(widget.redirectURL));
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: controller == null
? const Center(
child: CircularProgressIndicator.adaptive(),
)
: SafeArea(
child: WebViewWidget(
controller: controller!,
),
),
);
}
Map<String, dynamic> _getParamFromURL(String url) {
final uri = Uri.parse(url);
Map<String, dynamic> data = {};
uri.queryParameters.forEach((key, value) {
data[key] = value;
});
return data;
}
}

View File

@@ -0,0 +1,470 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/controller/functions/encrypt_decrypt.dart';
import 'package:sefer_driver/main.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../../../print.dart';
class PaymobResponseWallet {
final bool success;
final String? transactionID;
final String? responseCode;
final String? message;
PaymobResponseWallet({
required this.success,
this.transactionID,
this.responseCode,
this.message,
});
factory PaymobResponseWallet.fromJson(Map<String, dynamic> json) {
return PaymobResponseWallet(
success: json['success'] == 'true',
transactionID: json['id'],
responseCode: json['txn_response_code'],
message: json['data']['message'],
);
}
}
class PaymobPaymentWallet {
static PaymobPaymentWallet instance = PaymobPaymentWallet();
bool _isInitializedWallet = false;
final Dio _dio = Dio();
final _baseURL = 'https://accept.paymob.com/api/';
late String _apiKey;
late int _integrationID;
late int _iFrameID;
late String _iFrameURL;
late int _userTokenExpiration;
/// Initializing PaymobPayment instance.
Future<bool> initialize({
/// It is a unique identifier for the merchant which used to authenticate your requests calling any of Accept's API.
/// from dashboard Select Settings -> Account Info -> API Key
required String apiKey,
/// from dashboard Select Developers -> Payment Integrations -> Online Card ID
required int integrationID,
/// from paymob Select Developers -> iframes
required int iFrameID,
/// The expiration time of this payment token in seconds. (The maximum is 3600 seconds which is an hour)
int userTokenExpiration = 300,
}) async {
if (_isInitializedWallet) {
return true;
}
_dio.options.baseUrl = _baseURL;
_dio.options.validateStatus = (status) => true;
_apiKey = apiKey;
_integrationID = integrationID;
_iFrameID = iFrameID;
_iFrameURL =
'https://accept.paymobsolutions.com/api/acceptance/iframes/$_iFrameID?payment_token=';
_isInitializedWallet = true;
_userTokenExpiration = userTokenExpiration;
return _isInitializedWallet;
}
/// Get authentication token, which is valid for one hour from the creation time.
Future<String> _getAuthToken() async {
try {
final response = await _dio.post(
'auth/tokens',
data: {
'api_key': _apiKey,
},
);
return response.data['token'];
} catch (e) {
rethrow;
}
}
/// At this step, you will register an order to Accept's database, so that you can pay for it later using a transaction
Future<int> _addOrder({
required String authToken,
required String currency,
required String amount,
required List items,
}) async {
try {
final response = await _dio.post(
'ecommerce/orders',
data: {
"auth_token": authToken,
"delivery_needed": "false",
"amount_cents": amount,
"currency": currency,
"items": items,
},
);
return response.data['id'];
} catch (e) {
rethrow;
}
}
/// At this step, you will obtain a payment_key token. This key will be used to authenticate your payment request. It will be also used for verifying your transaction request metadata.
Future<String> _getPurchaseToken({
required String authToken,
required String currency,
required int orderID,
required String amount,
required PaymobBillingDataWallet billingData,
}) async {
final response = await _dio.post(
'acceptance/payment_keys',
data: {
"auth_token": authToken,
"amount_cents": amount,
"expiration": _userTokenExpiration,
"order_id": orderID,
"billing_data": billingData,
"currency": currency,
"integration_id": _integrationID,
"lock_order_when_paid": "false"
},
);
// final message = response.data['message'];
// if (message != null) {
// throw Exception(message);
// }
return response.data['token'];
}
Future<String> _getWalletUrl({
required String paymentToken,
}) async {
final Map<String, dynamic> data = {
"source": {
"identifier": box.read(BoxName.phoneWallet).toString(),
"subtype": "WALLET",
},
"payment_token": paymentToken,
};
final dio = Dio();
try {
final response = await dio.post(
'https://accept.paymobsolutions.com/api/acceptance/payments/pay',
data: data,
);
// 4. Handle Payment Response
if (response.statusCode == 200) {
final paymentData = response.data; // Assuming JSON response
return paymentData['iframe_redirection_url'];
// Navigate to success screen or display success message
} else {
// Payment failed: Handle errors (e.g., display error message)
}
} on DioError catch (e) {
// Handle network or Dio-related errors
}
return '';
}
/// Proceed to pay with only calling this function.
/// Opens a WebView at Paymob redirectedURL to accept user payment info.
Future<PaymobResponseWallet?> pay(
{
/// BuildContext for navigation to WebView
required BuildContext context,
/// Which Currency you would pay in.
required String currency,
/// Payment amount in cents EX: 20000 is an 200 EGP
required String amountInCents,
/// Optional Callback if you can use return result of pay function or use this callback
void Function(PaymobResponseWallet response)? onPayment,
/// list of json objects contains the contents of the purchase.
List? items,
/// The billing data related to the customer related to this payment.
PaymobBillingDataWallet? billingData}) async {
if (!_isInitializedWallet) {
throw Exception(
'PaymobPayment is not initialized call:`PaymobPayment.instance.initialize`');
}
final authToken = await _getAuthToken();
final orderID = await _addOrder(
authToken: authToken,
currency: currency,
amount: amountInCents,
items: items ?? [],
);
final purchaseToken = await _getPurchaseToken(
authToken: authToken,
currency: currency,
orderID: orderID,
amount: amountInCents,
billingData: billingData ??
PaymobBillingDataWallet(
// email: box.read(BoxName.email) ?? box.read(BoxName.emailDriver),
// firstName: box.read(BoxName.name) ?? box.read(BoxName.nameDriver),
// lastName:
// box.read(BoxName.lastNameDriver) ?? box.read(BoxName.name),
// phoneNumber:
// box.read(BoxName.phone) ?? box.read(BoxName.phoneDriver),
),
);
final urlWallet = await _getWalletUrl(paymentToken: purchaseToken);
Log.print('urlWallet: ${urlWallet}');
if (context.mounted) {
final response = await PaymobIFrameWallet.show(
context: context,
redirectURL: urlWallet,
onPayment: onPayment,
);
return response;
}
return null;
}
}
class PaymobBillingDataWallet {
String? email;
String? firstName;
String? lastName;
String? phoneNumber;
String? apartment;
String? floor;
String? street;
String? building;
String? postalCode;
String? city;
String? state;
String? country;
String? shippingMethod;
PaymobBillingDataWallet({
this.email,
this.firstName,
this.lastName,
this.phoneNumber,
this.apartment,
this.floor,
this.street,
this.building,
this.postalCode,
this.city,
this.state,
this.country,
this.shippingMethod,
});
Map<String, dynamic> toJson() {
return {
"email": (box.read(BoxName.emailDriver)),
"first_name": box.read(BoxName.name) ?? box.read(BoxName.nameDriver),
"last_name": box.read(BoxName.name) ?? box.read(BoxName.nameDriver),
"phone_number": (box.read(BoxName.phoneWallet)),
"apartment": apartment ?? "NA",
"floor": floor ?? "NA",
"building": building ?? "NA",
"street": street ?? "NA",
"postal_code": postalCode ?? "NA",
"city": city ?? "NA",
"state": state ?? "NA",
"country": country ?? "NA",
"shipping_method": shippingMethod ?? "NA",
};
}
}
class PaymobIFrameWallet extends StatefulWidget {
const PaymobIFrameWallet({
Key? key,
required this.redirectURL,
this.onPayment,
}) : super(key: key);
final String redirectURL;
final void Function(PaymobResponseWallet)? onPayment;
static Future<PaymobResponseWallet?> show({
required BuildContext context,
required String redirectURL,
void Function(PaymobResponseWallet)? onPayment,
}) =>
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return PaymobIFrameWallet(
onPayment: onPayment,
redirectURL: redirectURL,
);
},
),
);
@override
State<PaymobIFrameWallet> createState() => _PaymobIFrameState();
}
// class _PaymobIFrameState extends State<PaymobIFrameWallet> {
// WebViewController? controller;
// @override
// void initState() {
// controller = WebViewController()
// ..setJavaScriptMode(JavaScriptMode.unrestricted)
// ..setNavigationDelegate(
// NavigationDelegate(
// onNavigationRequest: (NavigationRequest request) {
// Log.print('request.url: ${request.url}');
// if (request.url.contains('txn_response_code') &&
// request.url.contains('success') &&
// request.url.contains('id')) {
// final params = _getParamFromURL(request.url);
// final response = PaymobResponseWallet.fromJson(params);
// if (widget.onPayment != null) {
// widget.onPayment!(response);
// }
// Navigator.pop(context, response);
// return NavigationDecision.prevent;
// }
// return NavigationDecision.navigate;
// },
// ),
// )
// ..loadRequest(Uri.parse(widget.redirectURL));
// super.initState();
// }
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// body: controller == null
// ? const Center(
// child: CircularProgressIndicator.adaptive(),
// )
// : SafeArea(
// child: WebViewWidget(
// controller: controller!,
// ),
// ),
// );
// }
// Map<String, dynamic> _getParamFromURL(String url) {
// final uri = Uri.parse(url);
// final queryParams = uri.queryParameters;
// final data = <String, dynamic>{};
// queryParams.forEach((key, value) {
// if (key.contains('.')) {
// final parts = key.split('.');
// data.putIfAbsent(parts.first, () => <String, dynamic>{});
// (data[parts.first] as Map<String, dynamic>)[parts.last] = value;
// } else {
// data[key] = value;
// }
// });
// return data;
// }
// }
class _PaymobIFrameState extends State<PaymobIFrameWallet> {
WebViewController? controller;
@override
void initState() {
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onNavigationRequest: (NavigationRequest request) {
Log.print('request.url: ${request.url}');
if (request.url.contains('txn_response_code') &&
request.url.contains('success') &&
request.url.contains('id')) {
final params = _getParamFromURL(request.url);
final response = PaymobResponseWallet.fromJson(params);
if (widget.onPayment != null) {
widget.onPayment!(response);
}
Navigator.pop(context, response);
// Show a dialog after successful payment
// _showSuccessDialog(response);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse(widget.redirectURL));
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: controller == null
? const Center(
child: CircularProgressIndicator.adaptive(),
)
: SafeArea(
child: WebViewWidget(
controller: controller!,
),
),
);
}
Map<String, dynamic> _getParamFromURL(String url) {
final uri = Uri.parse(url);
final queryParams = uri.queryParameters;
final data = <String, dynamic>{};
queryParams.forEach((key, value) {
if (key.contains('.')) {
final parts = key.split('.');
data.putIfAbsent(parts.first, () => <String, dynamic>{});
(data[parts.first] as Map<String, dynamic>)[parts.last] = value;
} else {
data[key] = value;
}
});
return data;
}
void _showSuccessDialog(PaymobResponseWallet response) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Payment Successful'),
content: Text('Transaction ID: EGP'),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop(); // Close the dialog
},
child: Text('OK'),
),
],
);
},
);
}
}

View File

View File

@@ -0,0 +1,97 @@
import 'dart:convert';
import 'package:flutter/material.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/controller/functions/crud.dart';
import 'package:sefer_driver/main.dart';
class CaptainProfileController extends GetxController {
bool isLoading = false;
TextEditingController vin = TextEditingController();
TextEditingController color = TextEditingController();
TextEditingController make = TextEditingController();
TextEditingController model = TextEditingController();
TextEditingController year = TextEditingController();
TextEditingController expirationDate = TextEditingController();
Future updateFields() async {
var payload = {
'driverID': box.read(BoxName.driverID).toString(),
};
if (vin.text.isNotEmpty) {
payload['vin'] = vin.text;
}
if (color.text.isNotEmpty) {
payload['color'] = color.text;
}
if (model.text.isNotEmpty) {
payload['model'] = model.text;
}
if (make.text.isNotEmpty) {
payload['make'] = make.text;
}
if (year.text.isNotEmpty) {
payload['year'] = year.text;
}
if (expirationDate.text.isNotEmpty) {
payload['expiration_date'] = expirationDate.text;
}
var res =
await CRUD().post(link: AppLink.updateRegisrationCar, payload: payload);
if (jsonDecode(res)['status'] == 'success') {
box.write(BoxName.vin, vin.text);
box.write(BoxName.color, color.text);
box.write(BoxName.model, model.text);
box.write(BoxName.make, make.text);
box.write(BoxName.year, year.text);
box.write(BoxName.expirationDate, expirationDate.text);
update();
Get.back();
}
}
Map captainProfileData = {};
Future getProfileData() async {
isLoading = true;
update();
var res = await CRUD().get(
link: AppLink.getCaptainProfile,
payload: {'id': box.read(BoxName.driverID)});
if (res != 'failure') {
var d = jsonDecode(res);
captainProfileData = d['message'];
update();
box.write(BoxName.sexDriver, d['message']['gender']);
box.write(BoxName.dobDriver, d['message']['birthdate']);
box.write(BoxName.vin, d['message']['vin']);
box.write(BoxName.color, d['message']['color']);
box.write(BoxName.model, d['message']['model']);
box.write(BoxName.carPlate, d['message']['car_plate']);
box.write(BoxName.make, d['message']['make']);
box.write(BoxName.year, d['message']['year']);
box.write(BoxName.expirationDate, d['message']['expiration_date']);
// box.write(BoxName.acc, d['message']['accountBank']);
isLoading = false;
update();
}
}
@override
void onInit() {
// if (box.read(BoxName.dobDriver) == null) {
getProfileData();
// }
super.onInit();
}
}

Some files were not shown because too many files have changed in this diff Show More