5/2/4
This commit is contained in:
49
lib/controller/auth/google_sign.dart
Normal file
49
lib/controller/auth/google_sign.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user