This commit is contained in:
Hamza-Ayed
2024-05-02 12:07:38 +03:00
parent 8684223b6a
commit 9d3c522038
14 changed files with 601 additions and 460 deletions

View File

@@ -0,0 +1,49 @@
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;
}
}