flutter firebase googlesign 在说 - 'GoogleSignInAccount?' 类型的值不能分配给 'GoogleSignInAccount' 类型的变量
flutter firebase googlesign in says - A value of type 'GoogleSignInAccount?' can't be assigned to a variable of type 'GoogleSignInAccount'
我知道这里也有同样的帖子,但似乎没有答案。我在 GoogleSignIn 下方有这条红线,某处提到将 google_sign_in 软件包版本从 5.0.4 降级到 5.03,但这并没有帮助我摆脱这个错误。到目前为止,这是我的代码 -
[![在此处输入图片描述][1]][1]
GoogleSignIn().signIn()
return GoogleSignInAccount?这意味着它可能为空。另一方面,您的 googleUser
变量属于 GoogleSignInAccount 类型,这意味着它不能为空。您应该将代码重构为如下所示:
Future<UserCredential?> signInWithGoogle() async {
final GoogleSignInAccount? googleUser = GoogleSignIn().signIn();
if (googleUser != null) {
// Rest of the code
...
}
}
我知道这里也有同样的帖子,但似乎没有答案。我在 GoogleSignIn 下方有这条红线,某处提到将 google_sign_in 软件包版本从 5.0.4 降级到 5.03,但这并没有帮助我摆脱这个错误。到目前为止,这是我的代码 -
[![在此处输入图片描述][1]][1]
GoogleSignIn().signIn()
return GoogleSignInAccount?这意味着它可能为空。另一方面,您的 googleUser
变量属于 GoogleSignInAccount 类型,这意味着它不能为空。您应该将代码重构为如下所示:
Future<UserCredential?> signInWithGoogle() async {
final GoogleSignInAccount? googleUser = GoogleSignIn().signIn();
if (googleUser != null) {
// Rest of the code
...
}
}