这是我的授权类
class Authentication {
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn();
Future<User?> signInWithGoogle() async {
try {
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
if (googleUser == null) {
// User canceled the sign-in process
print('User canceled Google Sign-In.');
return null; // Return null to indicate cancellation
}
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final UserCredential userCredential =
await _auth.signInWithCredential(credential);
return userCredential.user;
} catch (e) {
print('Google sign-in error: $e');
return null;
}
}
Future<void> signOutGoogle() async {
await googleSignIn.signOut();
print("Google user signed out");
}
}
这就是在手势检测器 ontap 中调用的方式
Authentication auth = Authentication();
User? user = await auth.signInWithGoogle();
一旦点击,应用程序崩溃(iOS 模拟器 iPhone 15) 并给出这个错误
flutter:Google 登录错误:PlatformException(google_sign_in,无活动配置。确保在 Info.plist 中设置 GIDClientID。,NSInvalidArgumentException,null) 与设备的连接丢失。 退出了。
过去 3 周工作正常,但突然出现此错误,不知道如何处理..
将 GoogleService-Info.plist 中的客户端 ID 添加到应用的 [my_project]/ios/Runner/Info.plist 文件中。
<key>GIDClientID</key>
<string>Copied from GoogleService-Info.plist key IOS CLIENT ID</string>
有关更多信息,请访问文档:https://pub.dev/packages/google_sign_in_ios