This commit is contained in:
Hamza-Ayed
2024-05-18 09:39:55 +03:00
parent 81080ce292
commit c74b87b272
17 changed files with 1469 additions and 586 deletions

View File

@@ -1,5 +1,6 @@
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/main.dart';
import 'package:SEFER/views/auth/captin/cards_egypt/egypt_card_a_i.dart';
import 'package:get/get.dart';
import 'package:google_sign_in/google_sign_in.dart';
@@ -13,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');
@@ -25,25 +33,50 @@ class GoogleSignInHelper {
}
}
// 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);
// 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);
print('emailDriver =${box.read(BoxName.emailDriver)}');
return user.displayName;
// 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)}');
}
// Method to handle sign-out process
static Future<void> _handleSignOut() async {
// Clear stored driver information
box.remove(BoxName.driverID);
box.remove(BoxName.emailDriver);
box.remove(BoxName.nameDriver);
box.remove(BoxName.driverPhotoUrl);
// 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.');
}
}