谷歌登录返回一个未处理的异常,我正在与firebase谷歌登录扑灭

时间:2018-01-19 18:33:36

标签: widget dart firebase-authentication flutter

these are the errors on logcat

这是使用Google帐户登录的方法的代码。   包含在其统计数据中,我可以解决此问题的任何想法???

     void main() {
     runApp(new FriendlychatApp());
      }

      Future<Null> _ensureLoggedIn() async {
      GoogleSignInAccount user = googleSignIn.currentUser;
      if (user == null)
      user = await googleSignIn.signInSilently();
      if (user == null) {
      user = await googleSignIn.signIn();
      analytics.logLogin();
      }
      if (await auth.currentUser() == null) {
      GoogleSignInAuthentication credentials =
      await googleSignIn.currentUser.authentication;
      await auth.signInWithGoogle(
      idToken: credentials.idToken,
      accessToken: credentials.accessToken,
      );
        }
       }

2 个答案:

答案 0 :(得分:1)

抱歉,它没有帮助,请尝试按照此示例here进行操作,并确保将您的应用正确地与firebase集成,就像您在身份验证部分启用了GoogleAuthentication并将功能更改为

一样
Future<Null> _ensureLoggedIn() async {
  GoogleSignInAccount user =  await googleSignIn.currentUser;
  if (user == null)
    user = await googleSignIn.signInSilently();
  if (user == null) {
    user = await googleSignIn.signIn();
    analytics.logLogin();
  }

  var response = await auth.currentUser();
  if (response.uid == null) {
    GoogleSignInAuthentication credentials =
    await googleSignIn.currentUser.authentication;
    await auth.signInWithGoogle(
      idToken: credentials.idToken,
      accessToken: credentials.accessToken,
    );
  }
}

答案 1 :(得分:0)

我认为您还需要等待下面提到的这一行。

GoogleSignInAccount user = googleSignIn.currentUser;

所以你应该实际使用。

GoogleSignInAccount user = await googleSignIn.currentUser;

让我知道这是否有帮助,

非常感谢, 鳅。