Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter google signin stuck loading after select account

i am trying to sign in with google first my info i chose google account it stuck in loading without any response or even any console message realted to it here is my code

 GoogleSignInAccount _currentUser;
GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: [
  'email',
  'https://www.googleapis.com/auth/cloud-platform.read-only',
],
);
 @override
void initState() {
super.initState();
_googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) {
  setState(() {
    _currentUser = account;
  });
});
_googleSignIn.signInSilently();
}

Future<void> _googlelogin() async {
  try {
    final GoogleSignInAccount googleSignInAccount =
        await _googleSignIn.signIn();
    final GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;
  } catch (error) {
    print(error);
  }
}

....

 RaisedButton(
      onPressed: () {
       _googlelogin();
      },),
                        ), 

preview of what happening

preview screenshot

preview of messages in console if it related messages

like image 674
Mohamed Enab Avatar asked Jan 09 '21 01:01

Mohamed Enab


1 Answers

Make sure that you are requesting only information of the scopes you are allowed to access.

In my case, I copied the following example and didn't notice that I don't have access to contacts.

  GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: [
    'email',
    'https://www.googleapis.com/auth/contacts.readonly',
  ],
);

Changing to the following worked for me.

GoogleSignIn _googleSignIn = GoogleSignIn(
  scopes: [
    'email',
  ],
);
like image 109
Omar Yasser Avatar answered Oct 05 '22 12:10

Omar Yasser