Initial commit
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:SEFER/constant/box_name.dart';
|
||||
import 'package:SEFER/controller/auth/login_controller.dart';
|
||||
import 'package:SEFER/main.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../constant/links.dart';
|
||||
import '../../onbording_page.dart';
|
||||
import '../functions/crud.dart';
|
||||
|
||||
class GoogleSignInHelper {
|
||||
static final GoogleSignIn _googleSignIn = GoogleSignIn(
|
||||
@@ -32,26 +39,114 @@ class GoogleSignInHelper {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<GoogleSignInAccount?> signInFromLogin() async {
|
||||
Future<GoogleSignInAccount?> signInFromLogin() async {
|
||||
try {
|
||||
final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
if (googleUser != null) {
|
||||
await _handleSignUp(googleUser);
|
||||
// if (box.read(BoxName.countryCode) == 'Egypt') {
|
||||
await Get.put(LoginController()).loginUsingCredentials(
|
||||
box.read(BoxName.passengerID).toString(),
|
||||
box.read(BoxName.email).toString(),
|
||||
);
|
||||
// } else if (box.read(BoxName.countryCode) == 'Jordan') {
|
||||
// // Get.to(() => AiPage());
|
||||
// }
|
||||
}
|
||||
return googleUser;
|
||||
} catch (error) {
|
||||
// if (error is GoogleSignInAuthenticationException) {
|
||||
// // Handle authentication errors from Google Sign-In
|
||||
// addError("Google sign-in authentication error: ${error.message}",
|
||||
// '<GoogleSignInAccount?> signInFromLogin()');
|
||||
// } else if (error is GoogleSignInAccountNotFoundException) {
|
||||
// // Handle the case where the user is not found (if applicable)
|
||||
// addError("Google sign-in account not found error: ${error.message}",
|
||||
// '<GoogleSignInAccount?> signInFromLogin()');
|
||||
// }
|
||||
// else
|
||||
if (error is SocketException) {
|
||||
// Handle network issues, like SSL certificate issues
|
||||
addError("Network error (SSL certificate issue): ${error.message}",
|
||||
'<GoogleSignInAccount?> signInFromLogin()');
|
||||
} else if (error is PlatformException) {
|
||||
// Handle platform-specific errors, like Google Play Services issues
|
||||
if (error.code == 'sign_in_required') {
|
||||
// Google Play Services are required but not installed or outdated
|
||||
showGooglePlayServicesError();
|
||||
} else {
|
||||
addError("Platform error: ${error.message}",
|
||||
'<GoogleSignInAccount?> signInFromLogin()');
|
||||
}
|
||||
} else {
|
||||
// Catch all other unknown errors
|
||||
addError("Unknown error: ${error.toString()}",
|
||||
'<GoogleSignInAccount?> signInFromLogin()');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void showGooglePlayServicesError() async {
|
||||
const playStoreUrl =
|
||||
'https://play.google.com/store/apps/details?id=com.google.android.gms&hl=en_US';
|
||||
|
||||
if (await canLaunchUrl(Uri.parse(playStoreUrl))) {
|
||||
await launchUrl(Uri.parse(playStoreUrl));
|
||||
} else {
|
||||
// Fallback if the URL can't be opened
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('Error'.tr),
|
||||
content: Text(
|
||||
'Could not open the Google Play Store. Please update Google Play Services manually.'
|
||||
.tr),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Close'.tr),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Future<GoogleSignInAccount?> signInFromLogin() async {
|
||||
// try {
|
||||
// final GoogleSignInAccount? googleUser = await _googleSignIn.signIn();
|
||||
// if (googleUser != null) {
|
||||
// await _handleSignUp(googleUser);
|
||||
// // if (box.read(BoxName.countryCode) == 'Egypt') {
|
||||
// await Get.put(LoginController()).loginUsingCredentials(
|
||||
// box.read(BoxName.passengerID).toString(),
|
||||
// box.read(BoxName.email).toString(),
|
||||
// );
|
||||
// // } else if (box.read(BoxName.countryCode) == 'Jordan') {
|
||||
// // // Get.to(() => AiPage());
|
||||
// // }
|
||||
// }
|
||||
// return googleUser;
|
||||
// } catch (error) {
|
||||
// addError(error.toString(), '<GoogleSignInAccount?> signInFromLogin()');
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
addError(String error, where) async {
|
||||
CRUD().post(link: AppLink.addError, payload: {
|
||||
'error': error.toString(), // Example error description
|
||||
'userId': box.read(BoxName.driverID) ??
|
||||
box.read(BoxName.passengerID), // Example user ID
|
||||
'userType': box.read(BoxName.driverID) != null
|
||||
? 'Driver'
|
||||
: 'passenger', // Example user type
|
||||
'phone': box.read(BoxName.phone) ??
|
||||
box.read(BoxName.phoneDriver), // Example phone number
|
||||
|
||||
'device': where
|
||||
});
|
||||
}
|
||||
|
||||
// Method to handle Google Sign-Out
|
||||
static Future<void> signOut() async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user