import 'package:SEFER/constant/box_name.dart'; import 'package:SEFER/controller/auth/login_controller.dart'; import 'package:SEFER/main.dart'; import 'package:get/get.dart'; import 'package:google_sign_in/google_sign_in.dart'; import '../../onbording_page.dart'; class GoogleSignInHelper { static final GoogleSignIn _googleSignIn = GoogleSignIn( scopes: [ 'email', 'profile', ], ); // Method to handle Google Sign-In static Future signIn() async { try { final GoogleSignInAccount? googleUser = await _googleSignIn.signIn(); if (googleUser != null) { await _handleSignUp(googleUser); // if (box.read(BoxName.countryCode) == 'Egypt') { // Get.to(() => EgyptCardAI()); // } else if (box.read(BoxName.countryCode) == 'Jordan') { // Get.to(() => AiPage()); // } } return googleUser; } catch (error) { return null; } } static Future signInFromLogin() async { try { final GoogleSignInAccount? googleUser = await _googleSignIn.signIn(); if (googleUser != null) { await _handleSignUp(googleUser); // if (box.read(BoxName.countryCode) == 'Egypt') { await Get.put(LoginController()).loginUsingCredentials( box.read(BoxName.passengerID).toString(), box.read(BoxName.email).toString(), ); // } else if (box.read(BoxName.countryCode) == 'Jordan') { // // Get.to(() => AiPage()); // } } return googleUser; } catch (error) { return null; } } // Method to handle Google Sign-Out static Future signOut() async { try { await _googleSignIn.signOut(); await _handleSignOut(); } catch (error) {} } // Method to get the current signed-in user static GoogleSignInAccount? getCurrentUser() { return _googleSignIn.currentUser; } // Method to handle sign-up process static Future _handleSignUp(GoogleSignInAccount user) async { // Store driver information box.write(BoxName.passengerID, user.id); box.write(BoxName.email, user.email); box.write(BoxName.name, user.displayName); box.write(BoxName.passengerPhotoUrl, user.photoUrl); // Perform any additional sign-up tasks or API calls here // For example, you can send the user data to your server for registration } // Method to handle sign-out process static Future _handleSignOut() async { // Clear stored driver information box.remove(BoxName.passengerPhotoUrl); box.remove(BoxName.driverID); box.remove(BoxName.email); box.remove(BoxName.lang); box.remove(BoxName.name); box.remove(BoxName.passengerID); box.remove(BoxName.phone); box.remove(BoxName.tokenFCM); box.remove(BoxName.tokens); box.remove(BoxName.addHome); box.remove(BoxName.addWork); box.remove(BoxName.agreeTerms); box.remove(BoxName.apiKeyRun); box.remove(BoxName.countryCode); box.remove(BoxName.accountIdStripeConnect); box.remove(BoxName.passengerWalletTotal); box.remove(BoxName.isVerified); 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 } }