我是 Flutter 的新手。我有Firebase Auth/Google Auth 的问题FirebaseUser未定义代码:
FirebaseAuth _auth = FirebaseAuth.instance;
GoogleSignIn googleSignIn = GoogleSignIn();
Future<FirebaseUser> currentUser() async { // The Issue is here in the Future<>
final GoogleSignInAccount account = await googleSignIn.signIn();
final GoogleSignInAuthentication authentication =
await account.authentication;
final GoogleAuthCredential credential = GoogleAuthProvider.getCredential(
idToken: authentication.idToken, accessToken: authentication.accessToken);
final AuthResult authResult = await _auth.signInWithCredential(credential);
final FirebaseUser user = authResult.user; // and here as I can't define this FirebaseUser object to return
return user;
}
Run Code Online (Sandbox Code Playgroud)
pubspec.yml
dependencies:
flutter:
sdk: …Run Code Online (Sandbox Code Playgroud) google-authentication dart firebase firebase-authentication flutter
我正在尝试在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
Run Code Online (Sandbox Code Playgroud)
另外,当我单击ctrl +空格以查看FirebaseAuth下的所有方法时,它根本没有显示signInWithGoogle方法。
请帮忙!提前致谢...