函数SignInWithFacebook在macOS中的Flutter Firebase Auth SDK中不存在,但在Windows中它存在

问题描述 投票:1回答:2

我今年开始使用Flutter,所以我不是专家。我正在尝试为Android和iOS开发一个应用程序,包括使用Firebase Auth登录Google和Facebook。

首先,我在Windows中的Android Studio中编写代码并且它可以工作,但是当我在macOS中的Android Studio中编写代码时,某些代码行无法正常工作。我已经在Firebase控制台和Facebook上为开发人员控制台配置了iOS项目。我没有使用CocoaPods来添加框架,但我是在Xcode上手动完成的。

基本上,错误是:The method 'signInWithFacebook' isn't defined for the class 'FirebaseAuth'.

screenshot

android ios facebook firebase flutter
2个回答
12
投票

是的,signInWithFacebook方法已从FirebaseAuth中消失了,现在我们使用带有AuthCredential和FacebookAuthProvider类的signInWithCredential方法来进行此工作,以进行身份​​验证过程。我将提供一些评论,仅仅是为了说明如何使用facebook凭据在firebase中执行auth。我希望它有所帮助......

/// in some point of your code you will get facebookLoginResult 

final facebookLoginResult = await facebookLogin
        .logInWithReadPermissions(['email', 'public_profile']);
 FacebookAccessToken myToken = facebookLoginResult.accessToken;

 ///assuming sucess in FacebookLoginStatus.loggedIn
/// we use FacebookAuthProvider class to get a credential from accessToken
/// this will return an AuthCredential object that we will use to auth in firebase
 AuthCredential credential= FacebookAuthProvider.getCredential(accessToken: myToken.token);

// this line do auth in firebase with your facebook credential.
FirebaseUser firebaseUser = await FirebaseAuth.instance.signInWithCredential(credential);

/// ... do your things

1
投票

看起来signInWithFacebook0.7.0被删除了,并且加入了signInWithCredential

更改日志本可以更清楚地了解变化:https://pub.dartlang.org/packages/firebase_auth#070

另见:https://github.com/flutter/plugins/commit/a444ad120418d622c4dea2882190968722abbcfe

如果你更新到一个较新的插件版本,你可能也会https://flutter.io/docs/development/packages-and-plugins/androidx-compatibility

© www.soinside.com 2019 - 2024. All rights reserved.