找不到Flutter Firebase.signInWithGoogle方法

我正在尝试在Flutter应用程序中添加Google身份验证。但是我的

Android Studio无法在FirebaseAuth类下找到方法signInWithGoogle。我的意思是说我写FirebaseAuth的时候。signInWithGoogle Android Studio抱怨说 未为Firebase类定义方法signInWithGoogle。

我已经有Firebase.signInWithEmailAndPassword,并且

工作正常。

我在pubspec.yaml firebase_auth中具有以下依赖项:^ 0.8.0 + 1

以下是我在课堂上的进口……

import 'package:firebase_auth/firebase_auth.dart';

import 'package:flutter/material.dart';

import 'package:google_sign_in/google_sign_in.dart';

import 'package:my_project/auth.dart';

import 'package:my_project/register.dart';

import 'package:my_project/signin/button_list.dart';

import 'package:my_project/signin/button_view.dart';

import 'package:my_project/utils.dart';

class _LoginPageState extends State<LoginPage> {

final formKey = GlobalKey<FormState>();

// Google Sign In

final GoogleSignIn _googleSignIn = GoogleSignIn();

final FirebaseAuth _auth = FirebaseAuth.instance; // No errors so far

另外,当我单击ctrl +空格以查看FirebaseAuth下的所有方法时,它根本没有显示signInWithGoogle方法。

回答:

查看firebase_auth github存储库

https://github.com/flutter/plugins/blob/master/packages/firebase_auth/example/lib/main.dart#L70

Future<String> _testSignInWithGoogle() async {

final GoogleSignInAccount googleUser = await _googleSignIn.signIn();

final GoogleSignInAuthentication googleAuth =

await googleUser.authentication;

final AuthCredential credential = GoogleAuthProvider.getCredential(

accessToken: googleAuth.accessToken,

idToken: googleAuth.idToken,

);

final AuthResult authResult = await _auth.signInWithCredential(credential);

final FirebaseUser user = authResult.user;

assert(user.email != null);

assert(user.displayName != null);

assert(!user.isAnonymous);

assert(await user.getIdToken() != null);

final FirebaseUser currentUser = await _auth.currentUser();

assert(user.uid == currentUser.uid);

return 'signInWithGoogle succeeded: $user';

}

以上是 找不到Flutter Firebase.signInWithGoogle方法 的全部内容, 来源链接: utcz.com/qa/421903.html

回到顶部