117 lines
3.7 KiB
Dart
117 lines
3.7 KiB
Dart
import 'package:SEFER/constant/box_name.dart';
|
|
import 'package:SEFER/controller/auth/captin/login_captin_controller.dart';
|
|
import 'package:SEFER/main.dart';
|
|
import 'package:SEFER/views/auth/captin/cards/sms_signup.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:google_sign_in/google_sign_in.dart';
|
|
|
|
import '../../onbording_page.dart';
|
|
import '../../views/auth/captin/ai_page.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) {
|
|
print('Google Sign-In error: $error');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
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.find<LoginCaptinController>().loginFromSignInGoogle(
|
|
box.read(BoxName.driverID).toString(),
|
|
box.read(BoxName.emailDriver).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');
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
print('User data cleared.');
|
|
}
|
|
|
|
// Method to get the current signed-in user
|
|
static GoogleSignInAccount? getCurrentUser() {
|
|
return _googleSignIn.currentUser;
|
|
}
|
|
|
|
// Method to handle sign-up process
|
|
static Future<void> _handleSignUp(GoogleSignInAccount user) async {
|
|
// Store driver information
|
|
box.write(BoxName.driverID, user.id);
|
|
box.write(BoxName.emailDriver, user.email);
|
|
// box.write(BoxName.nameDriver, user.displayName);
|
|
// box.write(BoxName.driverPhotoUrl, 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('driverID = ${box.read(BoxName.driverID)}');
|
|
print('emailDriver = ${box.read(BoxName.emailDriver)}');
|
|
// print('nameDriver = ${box.read(BoxName.nameDriver)}');
|
|
// print('driverPhotoUrl = ${box.read(BoxName.driverPhotoUrl)}');
|
|
}
|
|
}
|