简体   繁体   English

Flutter:未为类“ FirebaseAuth”定义方法“ signInWithGoogle”

[英]Flutter:The method 'signInWithGoogle' isn't defined for the class 'FirebaseAuth'

I am trying to add a google sign in to my flutter application, but the method googleSignIn always shows the red squiggly lines. 我正在尝试将Google登录信息添加到我的flutter应用程序中,但方法googleSignIn始终显示红色的波浪线。 When I hover my mouse over it, it says: 当我将鼠标悬停在它上面时,它说:

The method 'signInWithGoogle' isn't defined for the class FirebaseAuth. 未为类FirebaseAuth定义方法'signInWithGoogle'。

What is the solution to this problem? 这个问题有什么解决方案?

I have added and imported all the required dependencies. 我已经添加并导入了所有必需的依赖项。

The dependencies I use are: 我使用的依赖项是:

google_sign_in: ^3.2.4
firebase_auth: ^0.7.0

I don't use the latest available dependency versions because of AndroidX Compatibility issue 由于AndroidX兼容性问题,我不使用最新的可用依赖项版本

In newer versions it works a little differently: 在较新的版本中,它的工作方式略有不同:

add dependency: 添加依赖项:

google_sign_in: ^4.0.1:
firebase_auth: ^0.8.1

After: 后:

final GoogleSignIn googleSignIn = GoogleSignIn(); final GoogleSignIn googleSignIn = GoogleSignIn();

final FirebaseAuth firebaseAuth = FirebaseAuth.instance; 最终的FirebaseAuth firebaseAuth = FirebaseAuth.instance;

Future<FirebaseUser> signInWithGoogle() async {
final GoogleSignInAccount googleAccount = await googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth = await googleAccount.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
  accessToken: googleAuth.accessToken,
  idToken: googleAuth.idToken,
);
return firebaseAuth.signInWithCredential(credential);

} }

Of course all Firebase settings should be made as given in the lib documentation: firebase_auth 当然,应按照lib文档中的说明进行所有Firebase设置: firebase_auth

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM