This commit is contained in:
Hamza-Ayed
2024-05-20 17:01:31 +03:00
parent a953aabd9c
commit 453863aa5d
73 changed files with 751 additions and 242 deletions

View File

@@ -1,8 +1,11 @@
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: [
@@ -11,11 +14,18 @@ class GoogleSignInHelper {
],
);
// Method to handle Google Sign-In
static Future<GoogleSignInAccount?> signIn() async {
try {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
getDriverInfo();
// Get.to(() => AiPage());
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) {
print('Google Sign-In error: $error');
@@ -23,25 +33,85 @@ class GoogleSignInHelper {
}
}
static Future<GoogleSignInAccount?> 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()).loginFromSignInGoogle(
box.read(BoxName.passengerID).toString(),
box.read(BoxName.email).toString(),
);
// } else if (box.read(BoxName.countryCode) == 'Jordan') {
// // Get.to(() => AiPage());
// }
}
return googleUser;
} catch (error) {
print('Google Sign-In error: $error');
return null;
}
}
// Method to handle Google Sign-Out
static Future<void> signOut() async {
try {
await _googleSignIn.signOut();
await _handleSignOut();
print('User signed out.');
} catch (error) {
print('Google Sign-Out error: $error');
}
}
// Method to get the current signed-in user
static GoogleSignInAccount? getCurrentUser() {
return _googleSignIn.currentUser;
}
static String? getDriverInfo() {
final GoogleSignInAccount? user = _googleSignIn.currentUser;
box.write(BoxName.driverID, user!.id);
box.write(BoxName.emailDriver, user.email);
box.write(BoxName.nameDriver, user.displayName);
box.write(BoxName.driverPhotoUrl, user.photoUrl);
print('emailDriver =${box.read(BoxName.emailDriver)}');
return user.displayName;
// Method to handle sign-up process
static Future<void> _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
print('passengerID = ${box.read(BoxName.passengerID)}');
print('email = ${box.read(BoxName.email)}');
print('name = ${box.read(BoxName.name)}');
print('passengerPhotoUrl = ${box.read(BoxName.passengerPhotoUrl)}');
}
// Method to handle sign-out process
static Future<void> _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
print('User data cleared.');
}
}