From 659f178737f9fe0f0c416b3bc3527f9e55848015 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 30 Sep 2024 09:37:26 +0300 Subject: [PATCH] 9/29/1 --- android/app/build.gradle | 7 +- android/app/src/main/AndroidManifest.xml | 64 +++---- android/app/src/main/res/values/strings.xml | 7 + ios/Podfile.lock | 23 +++ lib/constant/links.dart | 1 + .../auth/captin/login_captin_controller.dart | 2 + .../captin/register_captin_controller.dart | 169 +++++++++++------- lib/controller/auth/facebook_login.dart | 30 ++++ lib/controller/auth/google_sign.dart | 20 ++- lib/controller/firebase/firbase_messge.dart | 10 +- .../firebase/local_notification.dart | 2 +- .../payment/payment_controller.dart | 45 +++-- .../payment/paymob/paymob_wallet.dart | 93 +++++++++- lib/main.dart | 7 +- lib/views/auth/captin/login_captin.dart | 13 +- .../widget/left_menu_map_captain.dart | 29 +-- .../passenger_info_window.dart | 8 +- lib/views/home/my_wallet/points_captain.dart | 2 +- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 32 ++++ pubspec.yaml | 1 + 21 files changed, 416 insertions(+), 151 deletions(-) create mode 100644 lib/controller/auth/facebook_login.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 8f9f263..0443558 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -54,8 +54,8 @@ android { // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdk = 23 targetSdk = flutter.targetSdkVersion - versionCode = 94 - versionName = '1.5.94' + versionCode = 95 + versionName = '1.5.95' multiDexEnabled =true } @@ -85,6 +85,9 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // implementation platform('com.google.firebase:firebase-bom:32.1.1') + // implementation 'com.facebook.android:facebook-login:12.3.0' + implementation 'com.facebook.android:facebook-login:latest.release' + implementation 'com.stripe:paymentsheet:20.47.0' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2' diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index bdfa54c..9b28459 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -33,6 +33,22 @@ android:icon="@mipmap/launcher_icon" android:label="Sefer Driver" android:theme="@style/LaunchTheme"> + + + + + + + + + + + @@ -59,6 +75,7 @@ android:name="com.yalantis.ucrop.UCropActivity" android:screenOrientation="portrait" android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> + @@ -74,14 +91,7 @@ android:exported="false" android:foregroundServiceType="location" /> - - + - - - - - - - - - - - - + - - - --> + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 3b173d8..16654b8 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -5,4 +5,11 @@ AIzaSyCyfwRXTwSTLOFQSQgN5p7QZgGJVZnEKq0 FCM Notifications Notifications from Firebase Cloud Messaging + + + 1749628025888168 + fb1749628025888168 + af5af0a2c8feffe25c27755977bb9ff7 + + \ No newline at end of file diff --git a/ios/Podfile.lock b/ios/Podfile.lock index a496cb0..92c2bc7 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -13,6 +13,14 @@ PODS: - Flutter - device_info_plus (0.0.1): - Flutter + - FBAEMKit (17.0.3): + - FBSDKCoreKit_Basics (= 17.0.3) + - FBSDKCoreKit (17.0.3): + - FBAEMKit (= 17.0.3) + - FBSDKCoreKit_Basics (= 17.0.3) + - FBSDKCoreKit_Basics (17.0.3) + - FBSDKLoginKit (17.0.3): + - FBSDKCoreKit (= 17.0.3) - Firebase/Auth (10.28.0): - Firebase/CoreOnly - FirebaseAuth (~> 10.28.0) @@ -63,6 +71,9 @@ PODS: - Flutter (1.0.0) - flutter_contacts (0.0.1): - Flutter + - flutter_facebook_auth (7.0.1): + - FBSDKLoginKit (~> 17.0.2) + - Flutter - flutter_image_compress_common (1.0.0): - Flutter - Mantle @@ -286,6 +297,7 @@ DEPENDENCIES: - firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`) - Flutter (from `Flutter`) - flutter_contacts (from `.symlinks/plugins/flutter_contacts/ios`) + - flutter_facebook_auth (from `.symlinks/plugins/flutter_facebook_auth/ios`) - flutter_image_compress_common (from `.symlinks/plugins/flutter_image_compress_common/ios`) - flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`) - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) @@ -317,6 +329,10 @@ DEPENDENCIES: SPEC REPOS: trunk: - AppAuth + - FBAEMKit + - FBSDKCoreKit + - FBSDKCoreKit_Basics + - FBSDKLoginKit - Firebase - FirebaseAppCheckInterop - FirebaseAuth @@ -374,6 +390,8 @@ EXTERNAL SOURCES: :path: Flutter flutter_contacts: :path: ".symlinks/plugins/flutter_contacts/ios" + flutter_facebook_auth: + :path: ".symlinks/plugins/flutter_facebook_auth/ios" flutter_image_compress_common: :path: ".symlinks/plugins/flutter_image_compress_common/ios" flutter_local_notifications: @@ -435,6 +453,10 @@ SPEC CHECKSUMS: background_location: 1b80c1fe3abd9912bca298618f6e365abf6f588f camera_avfoundation: dd002b0330f4981e1bbcb46ae9b62829237459a4 device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d + FBAEMKit: 9900b2edd99a2d21629a6277e6166f14c6215799 + FBSDKCoreKit: 0791f8f68a8630931a4c12aa23a56cc021551596 + FBSDKCoreKit_Basics: 46d6b472c0dd0a5a7e972c025033d1c567f54eb4 + FBSDKLoginKit: b4a4eba1d62eb452544411824f41689adabd5bd2 Firebase: 5121c624121af81cbc81df3bda414b3c28c4f3c3 firebase_auth: e778ee89483b86fe4200d1f8e9a1c52aa5fb64a8 firebase_core: a9d0180d5285527884d07a41eb4a9ec9ed12cdb6 @@ -447,6 +469,7 @@ SPEC CHECKSUMS: FirebaseMessaging: 087a7c7cadef7b9239f005bc4db823894844f323 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_contacts: edb1c5ce76aa433e20e6cb14c615f4c0b66e0983 + flutter_facebook_auth: 4fa1dc3fa624284a5ddfdf9e4a2b7945b3835949 flutter_image_compress_common: ec1d45c362c9d30a3f6a0426c297f47c52007e3e flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086 flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12 diff --git a/lib/constant/links.dart b/lib/constant/links.dart index 8be5015..220b01f 100644 --- a/lib/constant/links.dart +++ b/lib/constant/links.dart @@ -281,6 +281,7 @@ class AppLink { 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"; diff --git a/lib/controller/auth/captin/login_captin_controller.dart b/lib/controller/auth/captin/login_captin_controller.dart index d9f3d8e..9367d0f 100644 --- a/lib/controller/auth/captin/login_captin_controller.dart +++ b/lib/controller/auth/captin/login_captin_controller.dart @@ -4,6 +4,7 @@ import 'package:SEFER/constant/colors.dart'; import 'package:SEFER/controller/functions/location_background_controller.dart'; import 'package:SEFER/print.dart'; import 'package:SEFER/views/auth/captin/cards/sms_signup.dart'; +import 'package:SEFER/views/auth/captin/login_captin.dart'; import 'package:SEFER/views/widgets/elevated_btn.dart'; import 'package:flutter/material.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; @@ -134,6 +135,7 @@ class LoginDriverController extends GetxController { } Get.off(() => HomeCaptain()); + // Get.off(() => LoginCaptin()); } else { Get.offAll(() => SmsSignupEgypt()); // Get.snackbar(jsonDecoeded['status'], jsonDecoeded['data'], diff --git a/lib/controller/auth/captin/register_captin_controller.dart b/lib/controller/auth/captin/register_captin_controller.dart index bd41b19..333a131 100644 --- a/lib/controller/auth/captin/register_captin_controller.dart +++ b/lib/controller/auth/captin/register_captin_controller.dart @@ -160,83 +160,124 @@ class RegisterCaptainController extends GetxController { // 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 { - SmsEgyptController smsEgyptController = Get.put(SmsEgyptController()); - isLoading = true; - update(); - - int randomNumber = Random().nextInt(100000) + 1; - isLoading = true; - update(); - - // Get the current time and the last OTP time (if it exists) - DateTime currentTime = DateTime.now(); - DateTime? lastOtpTime = box.read(BoxName.lastOtpTime); - - // Check if the last OTP was sent within 5 minutes (300 seconds) - if (lastOtpTime != null && - currentTime.difference(lastOtpTime).inSeconds < 300) { - Get.snackbar( - 'Please wait'.tr, 'You can send another OTP after 5 minutes.'.tr, - backgroundColor: AppColor.redColor); - isLoading = false; + if (_isOtpResendAllowed()) { + isLoading = true; update(); - return; - } - 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 (formKey3.currentState!.validate()) { + String countryCode = box.read(BoxName.countryCode); + String phoneNumber = 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()).loginUsingCredentials( - box.read(BoxName.driverID).toString(), - box.read(BoxName.emailDriver).toString(), - ); - } else { - await _sendOtp(randomNumber, smsEgyptController); - } - } else { - await _sendOtp(randomNumber, smsEgyptController); - } + if (countryCode == 'Egypt' && isValidEgyptianPhoneNumber(phoneNumber)) { + await _checkAndSendOtp(phoneNumber); } else { - Get.snackbar('Phone Number wrong'.tr, '', - backgroundColor: AppColor.redColor); + _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() { + Get.snackbar( + 'Phone number is already verified'.tr, + '', + backgroundColor: AppColor.greenColor, + ); + box.write(BoxName.phoneVerified, '1'); + box.write(BoxName.phone, '+2${phoneController.text}'); + Get.put(LoginDriverController()).loginUsingCredentials( + 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), + }, + ); + + // Get.snackbar('', ''); + // await smsEgyptController.sendSmsEgypt(phoneNumber, randomNumber.toString()); + + lastOtpSentTime = DateTime.now(); // Update the last OTP sent time + isSent = true; isLoading = false; update(); } - _sendOtp(int randomNumber, SmsEgyptController smsEgyptController) async { - await CRUD().post(link: AppLink.sendVerifyOtpMessage, payload: { - 'phone_number': '+2${phoneController.text}', - 'token_code': randomNumber.toString(), - "driverId": box.read(BoxName.driverID), - "email": box.read(BoxName.emailDriver), - }); - - await smsEgyptController.sendSmsEgypt( - phoneController.text.toString(), randomNumber.toString()); - - // Save the current time as the last OTP time - box.write(BoxName.lastOtpTime, DateTime.now()); - - isSent = true; - isLoading = false; - update(); +// Show error message in case of invalid phone number + void _showErrorMessage(String message) { + Get.snackbar( + message.tr, + '', + backgroundColor: AppColor.redColor, + ); } verifySMSCode() async { diff --git a/lib/controller/auth/facebook_login.dart b/lib/controller/auth/facebook_login.dart new file mode 100644 index 0000000..0741ba4 --- /dev/null +++ b/lib/controller/auth/facebook_login.dart @@ -0,0 +1,30 @@ +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter_facebook_auth/flutter_facebook_auth.dart'; + +class FacebookSignIn { + Future 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 signOut() async { + try { + await FacebookAuth.instance.logOut(); + print('Facebook Sign Out Successful'); + } catch (e) { + print('Error during Facebook Sign Out: $e'); + } + } + + Future isSignedIn() async { + final accessToken = await FacebookAuth.instance.accessToken; + return accessToken != null; + } +} diff --git a/lib/controller/auth/google_sign.dart b/lib/controller/auth/google_sign.dart index b86f693..cfe1e32 100644 --- a/lib/controller/auth/google_sign.dart +++ b/lib/controller/auth/google_sign.dart @@ -1,6 +1,8 @@ import 'package:SEFER/constant/box_name.dart'; import 'package:SEFER/constant/colors.dart'; +import 'package:SEFER/constant/links.dart'; import 'package:SEFER/controller/auth/captin/login_captin_controller.dart'; +import 'package:SEFER/controller/functions/crud.dart'; import 'package:SEFER/main.dart'; import 'package:SEFER/views/auth/captin/cards/sms_signup.dart'; import 'package:SEFER/views/home/on_boarding_page.dart'; @@ -83,7 +85,7 @@ class GoogleSignInHelper { // return null; // } // } - static Future signInFromLogin() async { + Future signInFromLogin() async { try { final GoogleSignInAccount? googleUser = await _googleSignIn.signIn(); @@ -106,11 +108,27 @@ class GoogleSignInHelper { } catch (error) { Get.snackbar('Google Sign-In error', '$error', backgroundColor: AppColor.redColor); + addError(error.toString(), 'GoogleSignInAccount?> signInFromLogin()'); print('Google Sign-In error: $error'); return null; } } + 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 + }); + } + // Method to handle Google Sign-Out static Future signOut() async { try { diff --git a/lib/controller/firebase/firbase_messge.dart b/lib/controller/firebase/firbase_messge.dart index 724b99c..3e6e1a6 100644 --- a/lib/controller/firebase/firbase_messge.dart +++ b/lib/controller/firebase/firbase_messge.dart @@ -135,7 +135,7 @@ class FirebaseMessagesController extends GetxController { }); } else if (message.notification!.title == 'Cancel Trip') { if (Platform.isAndroid) { - NotificationController().showNotification( + NotificationController1().showNotification( 'Cancel Trip'.tr, 'Passenger Cancel Trip'.tr, 'cancel', ''); } cancelTripDialog(); @@ -143,7 +143,7 @@ class FirebaseMessagesController extends GetxController { var myListString = message.data['DriverList']; var driverList = jsonDecode(myListString) as List; if (Platform.isAndroid) { - NotificationController() + NotificationController1() .showNotification('VIP Order'.tr, '', 'order', ''); } MyDialog().getDialog('VIP Order'.tr, 'midTitle', () { @@ -159,13 +159,13 @@ class FirebaseMessagesController extends GetxController { } else if (message.notification!.title == 'Cancel') { cancelTripDialog1(); } else if (message.notification!.title! == 'token change') { - // NotificationController() - // .showNotification('token change'.tr, 'token change', 'cancel'); + NotificationController1() + .showNotification('token change'.tr, 'token change', 'cancel', ''); // GoogleSignInHelper.signOut(); GoogleSignInHelper.signOut(); } else if (message.notification!.title! == 'message From passenger') { if (Platform.isAndroid) { - NotificationController() + NotificationController1() .showNotification('message From passenger'.tr, ''.tr, 'tone2', ''); } passengerDialog(message.notification!.body!); diff --git a/lib/controller/firebase/local_notification.dart b/lib/controller/firebase/local_notification.dart index cc4fa69..b031846 100644 --- a/lib/controller/firebase/local_notification.dart +++ b/lib/controller/firebase/local_notification.dart @@ -61,7 +61,7 @@ class NotificationController extends GetxController { priority: Priority.high, styleInformation: bigTextStyleInformation, playSound: true, - sound: RawResourceAndroidNotificationSound(tone), + sound: RawResourceAndroidNotificationSound(tone == '' ? 'ding' : tone), // audioAttributesUsage: AudioAttributesUsage.alarm, visibility: NotificationVisibility.public, autoCancel: false, diff --git a/lib/controller/payment/payment_controller.dart b/lib/controller/payment/payment_controller.dart index 9f95cec..dcb2451 100644 --- a/lib/controller/payment/payment_controller.dart +++ b/lib/controller/payment/payment_controller.dart @@ -16,6 +16,7 @@ import '../../constant/colors.dart'; import '../../constant/info.dart'; import '../../constant/links.dart'; import '../../main.dart'; +import '../../print.dart'; import '../functions/crud.dart'; import '../functions/toast.dart'; import 'paymob/paymob_wallet.dart'; @@ -588,25 +589,31 @@ class PaymentController extends GetxController { billingData: PaymobBillingDataWallet(), onPayment: (PaymobResponseWallet response) {}, ); - - if (response!.success == true && response.responseCode == '200') { - 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(); - }, - ), - ); + // Log.print('message: ${response!.message}'); + // Log.print('responseCode: ${response.responseCode}'); + // Log.print('success: ${response.success}'); + // Log.print('transactionID: ${response.transactionID}'); + if (response!.responseCode == '200' && response.success == true) { + // Log.print('transactionID wewer: ${response.transactionID}'); + Toast.show(context, 'Payment Successful'.tr, AppColor.greenColor); + method(); + // 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, diff --git a/lib/controller/payment/paymob/paymob_wallet.dart b/lib/controller/payment/paymob/paymob_wallet.dart index 5c9b86c..12ceff8 100644 --- a/lib/controller/payment/paymob/paymob_wallet.dart +++ b/lib/controller/payment/paymob/paymob_wallet.dart @@ -313,6 +313,70 @@ class PaymobIFrameWallet extends StatefulWidget { State createState() => _PaymobIFrameState(); } +// class _PaymobIFrameState extends State { +// 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 _getParamFromURL(String url) { +// final uri = Uri.parse(url); +// final queryParams = uri.queryParameters; +// final data = {}; + +// queryParams.forEach((key, value) { +// if (key.contains('.')) { +// final parts = key.split('.'); +// data.putIfAbsent(parts.first, () => {}); +// (data[parts.first] as Map)[parts.last] = value; +// } else { +// data[key] = value; +// } +// }); + +// return data; +// } +// } + class _PaymobIFrameState extends State { WebViewController? controller; @@ -323,16 +387,23 @@ class _PaymobIFrameState extends State { ..setNavigationDelegate( NavigationDelegate( onNavigationRequest: (NavigationRequest request) { + Log.print('request.url: ${request.url}'); + if (request.url.contains('txn_response_code') && - // request.url.contains('successfully') && 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; @@ -375,4 +446,24 @@ class _PaymobIFrameState extends State { return data; } + + void _showSuccessDialog(PaymobResponseWallet response) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: Text('Payment Successful'), + content: Text('Transaction ID: EGP'), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); // Close the dialog + }, + child: Text('OK'), + ), + ], + ); + }, + ); + } } diff --git a/lib/main.dart b/lib/main.dart index 86bcb69..da1abe7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:SEFER/views/home/Captin/orderCaptin/order_request_page.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_facebook_auth/flutter_facebook_auth.dart'; import 'package:flutter_overlay_window/flutter_overlay_window.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_stripe/flutter_stripe.dart'; @@ -129,14 +130,14 @@ void main() async { await FirebaseMessagesController().requestFirebaseMessagingPermission(); FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler); + // NotificationController1().initNotifications(); NotificationController().initNotifications(); - NotificationController1().initNotifications(); await Future.wait([ FirebaseMessagesController().getNotificationSettings(), FirebaseMessagesController().getToken(), ]); - + // await FacebookAuth.instance.init(); SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, @@ -145,6 +146,7 @@ void main() async { PaymobPayment.instance.initialize( apiKey: AK.payMobApikey, + // integrationID: 4556055, integrationID: int.parse(AK.integrationIdPayMob), userTokenExpiration: 200, iFrameID: 837992, @@ -152,6 +154,7 @@ void main() async { PaymobPaymentWallet.instance.initialize( apiKey: AK.payMobApikey, integrationID: int.parse(AK.integrationIdPayMobWallet), + // integrationID: 4556056, userTokenExpiration: 200, iFrameID: 837992, ); diff --git a/lib/views/auth/captin/login_captin.dart b/lib/views/auth/captin/login_captin.dart index 452d90d..10e25e7 100644 --- a/lib/views/auth/captin/login_captin.dart +++ b/lib/views/auth/captin/login_captin.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:SEFER/controller/auth/facebook_login.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; @@ -210,10 +211,20 @@ class LoginCaptin extends StatelessWidget { MyElevatedButton( title: 'Sign In by Google'.tr, onPressed: () async { - await GoogleSignInHelper.signInFromLogin(); + await GoogleSignInHelper().signInFromLogin(); }, kolor: AppColor.redColor, ), + // Platform.isAndroid + // ? MyElevatedButton( + // title: 'Sign In by Facebook'.tr, + // onPressed: () async { + // await FacebookSignIn() + // .signInWithFacebook(); + // }, + // kolor: AppColor.blueColor, + // ) + // : const SizedBox(), !Platform.isAndroid ? MyElevatedButton( title: 'Sign In by Apple'.tr, diff --git a/lib/views/home/Captin/home_captain/widget/left_menu_map_captain.dart b/lib/views/home/Captin/home_captain/widget/left_menu_map_captain.dart index f426df2..21e6ced 100644 --- a/lib/views/home/Captin/home_captain/widget/left_menu_map_captain.dart +++ b/lib/views/home/Captin/home_captain/widget/left_menu_map_captain.dart @@ -3,6 +3,7 @@ import 'package:SEFER/controller/firebase/local_notification.dart'; import 'package:SEFER/main.dart'; import 'package:SEFER/views/auth/captin/cards/egypt_card_a_i.dart'; import 'package:SEFER/views/auth/captin/cards/sms_signup.dart'; +import 'package:SEFER/views/auth/captin/login_captin.dart'; import 'package:flutter/material.dart'; import 'package:flutter_font_icons/flutter_font_icons.dart'; import 'package:bubble_head/bubble.dart'; @@ -276,20 +277,20 @@ GetBuilder leftMainMenuCaptainIcons() { // return IconButton( // onPressed: () async { // // FirebaseMessagesController().sendNotificationToAnyWithoutData( - // // 'Order'.tr, - // // 'from: ', - // // // jsonDecode(value)['message'].toString(), - // // 'dqK5wNrPTr20HQ8qa5KsgL:APA91bHwPW_XzCIxQtg_IkJmHg1JRd8NRMquvsgedBaHAIgErTs6Uzpw1IX0EIJqkTaZq5dxd1u2z7NVdLlvcmEzrpjjWt1pUsZaa5UU7Cpx6hUzJMUdXvhNlAYFGklM8bWUG4ZXSRf1', - // // 'order.wav'); - // // NotificationController().showNotification( - // // 'Order'.tr, - // // 'We regret to inform you that another driver has accepted this order.' - // // .tr, - // // 'order', - // // ''); - // // requestLocationPermission(); - // // Get.to(SmsSignupEgypt()); - // // print(box.read(BoxName.tokenDriver)); + // 'Order'.tr, + // 'from: ', + // // jsonDecode(value)['message'].toString(), + // 'dqK5wNrPTr20HQ8qa5KsgL:APA91bHwPW_XzCIxQtg_IkJmHg1JRd8NRMquvsgedBaHAIgErTs6Uzpw1IX0EIJqkTaZq5dxd1u2z7NVdLlvcmEzrpjjWt1pUsZaa5UU7Cpx6hUzJMUdXvhNlAYFGklM8bWUG4ZXSRf1', + // 'order.wav'); + // NotificationController1().showNotification( + // 'sdf'.tr, + // 'We regret to inform you that another driver has accepted this order.' + // .tr, + // '', + // ''); + // requestLocationPermission(); + // Get.to(() => LoginCaptin()); + // print(box.read(BoxName.tokenDriver)); // }, // icon: const Icon( // FontAwesome5.closed_captioning, diff --git a/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart b/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart index ce836ee..d722f39 100644 --- a/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart +++ b/lib/views/home/Captin/mapDriverWidgets/passenger_info_window.dart @@ -437,8 +437,12 @@ class PassengerInfoWindow extends StatelessWidget { title: 'I arrive you'.tr, kolor: AppColor.yellowColor, onPressed: () async { - if (controller - .calculateDistanceBetweenDriverAndPassengerLocation() < + // Await the result of the distance calculation + double distanceToArrive = + await controller + .calculateDistanceBetweenDriverAndPassengerLocation(); + + if (distanceToArrive < 40) { FirebaseMessagesController() .sendNotificationToPassengerToken( diff --git a/lib/views/home/my_wallet/points_captain.dart b/lib/views/home/my_wallet/points_captain.dart index 93872bd..2b7bbf7 100644 --- a/lib/views/home/my_wallet/points_captain.dart +++ b/lib/views/home/my_wallet/points_captain.dart @@ -106,7 +106,7 @@ class PointsCaptain extends StatelessWidget { .getCaptainWalletFromBuyPoints(); }); } - Get.back(); + // Get.back(); })); }, ), diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 1a3c0b5..c935bf0 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,6 +7,7 @@ import Foundation import audio_session import device_info_plus +import facebook_auth_desktop import file_selector_macos import firebase_auth import firebase_core @@ -31,6 +32,7 @@ import wakelock_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) + FacebookAuthDesktopPlugin.register(with: registry.registrar(forPlugin: "FacebookAuthDesktopPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) diff --git a/pubspec.lock b/pubspec.lock index 022a572..f61820b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -409,6 +409,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.5" + facebook_auth_desktop: + dependency: transitive + description: + name: facebook_auth_desktop + sha256: "219d559a33891e937c1913430505eae01fb946cb35729167bbdc747e3ebbd9ff" + url: "https://pub.dev" + source: hosted + version: "2.1.1" fake_async: dependency: transitive description: @@ -574,6 +582,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.8" + flutter_facebook_auth: + dependency: "direct main" + description: + name: flutter_facebook_auth + sha256: faa92fb7626c230837f30d02de7d92b6af334b77ba744867c63545d4ad7e171f + url: "https://pub.dev" + source: hosted + version: "7.1.0" + flutter_facebook_auth_platform_interface: + dependency: transitive + description: + name: flutter_facebook_auth_platform_interface + sha256: e04b8dbfa77702bea45a79993163ad5d20b2c0084109bec591fdc2b9ee505779 + url: "https://pub.dev" + source: hosted + version: "6.1.2" + flutter_facebook_auth_web: + dependency: transitive + description: + name: flutter_facebook_auth_web + sha256: "8a6890a98522604169ca9f958d7189c9f579dbf05ba4d3d7adf26eca4c4c4c93" + url: "https://pub.dev" + source: hosted + version: "6.1.1" flutter_font_icons: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 1568574..a7d8a8d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -85,6 +85,7 @@ dependencies: flutter_contacts: ^1.1.8 flutter_overlay_window: ^0.4.4 googleapis_auth: ^1.6.0 + flutter_facebook_auth: ^7.1.0 # dash_bubble: ^2.0.0 # bubble_head: ^0.0.4 # google_mlkit_face_detection: ^0.11.0