Files
driver_tripz/lib/controller/auth/google_sign.dart
Hamza-Ayed 9d3c522038 5/2/4
2024-05-02 12:07:38 +03:00

50 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';
import '../../views/auth/captin/ai_page.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;
}
}