Flutter: Google sign in caused a black line running across screen - flutter

I have my code as following for Google Sign in:
// google sign in
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
],
);
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
// get firebase user
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
firebaseUser = (await _firebaseAuth.signInWithCredential(credential)).user;
After a user signs in successfully thru Google, I will see a solid thick black line running from top to bottom of the screen. I have attached two screenshots to prove it here. Any idea on getting rid of it?

Related

Flutter Google sign-in error on first time login

I am using google_sign_in plugin. It's running fine if the user has already account logged in and user just needs to select his account.
But when a new google account is added just before the login, then googleUser remains null and hence it throws exception.
Here's the code.
Future<UserCredential> signInWithGoogle() async {
//here googleUser remains null on first time login.....
GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication? googleAuth =
await googleUser?.authentication;
final OAuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth?.accessToken,
idToken: googleAuth?.idToken,
);
// Once signed in, return the UserCredential
return await FirebaseAuth.instance.signInWithCredential(credential);
}

Flutter Platform Exception in Google Sign

I have successfully completed the Google sign-in thing in Flutter. But if the user quits logging in I get an error. I couldn't figure out how to check for these errors. The answers I found are very old. Here is my code.
Future<UserCredential> signInWithGoogle() async {
final GoogleSignInAccount? googleUser =
await GoogleSignIn(scopes: <String>["email"]).signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser!.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
return await FirebaseAuth.instance.signInWithCredential(credential);
}
And my error
Exception has occurred.
PlatformException (PlatformException(sign_in_canceled, com.google.GIDSignIn, The user canceled the sign-in flow., null))
How can i handle that?

'https://www.googleapis.com/auth/contacts.readonly' not working showing loading... in google sign

Future googleSignIn() async {
final GoogleSignInAccount googleUser = await GoogleSignIn(
scopes: ['https://www.googleapis.com/auth/contacts.readonly']).signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await FirebaseAuth.instance.signInWithCredential(credential);
}
google API is not working

How to get additional scopes from GoogleSignIn in Flutter?

I have a method which I am using to get a users basic info like birthday, gender & phone number and I'm now sure how to implement it in Flutter?
void signInWithGoogle(context) async {
final GoogleSignIn _googleSignIn = GoogleSignIn();
try {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final User user = (await _auth.signInWithCredential(credential)).user;
} catch (error) {
print('Google error: $error');
}
}
I hope this answer will help you.
You can try adding a scope in your GoogleSignIn() method like that
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
'email',
'https://www.googleapis.com/auth/contacts.readonly',
],
);
And you can adjust your scopes based on the information you want to access.
And this is the link to the full list of scopes you can use Google Scopes list
Note that some scopes will require app verification and it's mentioned in the above link.

Make flutter app force a user to choose an account with FirebaseAuth and GoogleSignInAuthentication

I want to force a user to select one of his account during login time. Is there any method to do so? I haven't found any configuration like prompt=select_account+consent.
Now, with these codes, after a user logout and then try to login again, it will automatically sign in with the selected account, there is no window showing up for user to select an account.
pubspec.yaml
firebase_auth: ^0.8.1+4
google_sign_in: ^3.2.4
Login part
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
user = await _auth.signInWithCredential(credential);
Logout part
await FirebaseAuth.instance.signOut();
GoogleSignIn _googleSignIn = GoogleSignIn();
await _googleSignIn.signOut();
Use GoogleSignInAccount.disconnect() before signing out to revoke the previous authentication:
await _googleSignIn.disconnect();
await FirebaseAuth.instance.signOut();
Harold's answer used to work for me, but recently the GoogleSignIn().currentUser appears null for some devices I tested, and then the disconnect function won't work. So, what solved that problem was ensuring it is signed in to Google.
final googleCurrentUser =
GoogleSignIn().currentUser ?? await GoogleSignIn().signIn();
if (googleCurrentUser != null)
await GoogleSignIn().disconnect().catchError((e, stack) {
FirebaseCrashlytics.instance.recordError(e, stack);
});
await _auth.signOut();
A simple way to go about it :-
In your sign out method just use
_auth.signOut();
Now inside Google Sign In package, inside google_sign_in.dart
Future<GoogleSignInAccount> signIn() {
final Future<GoogleSignInAccount> result =
_addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: false);
bool isCanceled(dynamic error) =>
error is PlatformException && error.code == kSignInCanceledError;
return result.catchError((dynamic _) => null, test: isCanceled);
}
Find the above method & set the canSkipCall parameter as false
final Future<GoogleSignInAccount> result =
_addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: false);
This will enable choosing a user every time you try to sign in