我正在尝试使用 Facebook 制作登录屏幕,但在运行代码时出现此错误。这是我的代码:
import 'package:facebook_login/services/auth_service.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_login_facebook/flutter_login_facebook.dart';
import 'package:auth/auth.dart';
class AuthBloc {
final authService = AuthService();
final fb = FacebookLogin();
Stream<User> get currentUser => authService.currentUser;
loginFacebook() async {
print('Starting Facebook Login');
final res = await fb.logIn(
permissions: [
FacebookPermission.publicProfile,
FacebookPermission.email
]
);
switch(res.status){
case FacebookLoginStatus.Success:
print('It worked');
//Get Token
final FacebookAccessToken fbToken = res.accessToken;
//Convert to Auth Credential
final AuthCredential credential
= FacebookAuthProvider.getCredential(accessToken: fbToken.token);
//User Credential to Sign in with Firebase
final result = await authService.signInWithCredentail(credential);
print('${result.user.displayName} is now logged in');
break;
case FacebookLoginStatus.Cancel:
print('The user canceled the login');
break;
case FacebookLoginStatus.Error:
print('There was an error');
break;
}
}
logout(){
authService.logout();
}
}
当我运行它时,我收到此错误消息
Invalid depfile: C:\Users\Main\OneDrive\stuff\Documents\seltech\st\.dart_tool\flutter_build\7b28b646cfa2e7424746c78d0801893a\kernel_snapshot.d
Error: Couldn't resolve the package 'facebook_login' in 'package:facebook_login/services/auth_service.dart'.
Error: Couldn't resolve the package 'auth' in 'package:auth/auth.dart'.
lib/src/bloc/auth_bloc:1:8: Error: Not found: 'package:facebook_login/services/auth_service.dart'
import 'package:facebook_login/services/auth_service.dart';
还有更多错误弹出。
如果您需要更多代码,我可以发送更多代码,它太多了,不适合这里
我得到的所有错误都来自 auth_block。我在单独的屏幕上创建了另一个登录页面。我在那里也有一个使用 firebase auth 的手动登录。