Files
tripz/lib/controller/auth/google_sign.dart
Hamza-Ayed 4f2ccf6495 5/2/passnew
2024-05-02 15:01:01 +03:00

48 lines
1.3 KiB
Dart

import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/main.dart';
import 'package:get/get.dart';
import 'package:google_sign_in/google_sign_in.dart';
class GoogleSignInHelper {
static final GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'profile',
],
);
static Future<GoogleSignInAccount?> signIn() async {
try {
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
getDriverInfo();
// Get.to(() => AiPage());
return googleUser;
} catch (error) {
print('Google Sign-In error: $error');
return null;
}
}
static Future<void> signOut() async {
try {
await _googleSignIn.signOut();
} catch (error) {
print('Google Sign-Out error: $error');
}
}
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;
}
}