找不到Flutter Firebase.signInWithGoogle方法 [英] Flutter Firebase.signInWithGoogle method not found

查看:212
本文介绍了找不到Flutter Firebase.signInWithGoogle方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Flutter应用程序中添加Google身份验证.但是我的Android Studio无法在 FirebaseAuth 类下找到方法 signInWithGoogle .我的意思是说,当我编写FirebaseAuth时. signInWithGoogle .AndroidStudio抱怨说未为类Firebase定义signInWithGoogle方法.

I am trying to add Google Authentication in my Flutter Application. But my Android studio is not able to find the method signInWithGoogle under FirebaseAuth class. I mean to say when I write FirebaseAuth.signInWithGoogle Android studio complains saying The method signInWithGoogle isn't defined for the class Firebase.

我已经拥有 Firebase.signInWithEmailAndPassword ,并且工作正常.

I already have the have Firebase.signInWithEmailAndPassword and it is working fine.

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

I have below dependency in pubspec.yaml firebase_auth: ^0.8.0+1

下面是我在班上的进口商品……

Below are my imports in the class...

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

下面的

是同一类中显示错误的方法

below is the method in the same class that shows the error

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

Also when I click the ctrl + space to see all the methods under FirebaseAuth it is not showing the signInWithGoogle method at all.

请帮助! 在此先感谢...

please help! Thanks in Advance...

推荐答案

查看firebase_auth github存储库中提供的示例 https://github.com/flutter/plugins/blob/master/packages/firebase_auth/example/lib/main.dart#L70

check out the example provided in the firebase_auth github repo 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方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆