我正在使用flutter SDK 3.3.8并在将它们转换为字符串后比较空值时遇到问题



我使用谷歌登录并比较获得用户的值,我的代码是:

await _googleSignIn.signIn().then((value) {
if (kDebugMode) {
print('Google sign in value:$value');
}
print("user email:${value?.email.toString()}");
///check profile available or not

if (value?.email.toString().trim() != "" &&
value?.email.toString() != "null") {
print("here we are>>>>>>>>>>>>");
//navigateToHomePage();
}
});

价值?。Email在这里为空,但是条件为真,并且运行if条件中的代码。

我想知道它是否有效或不转换为字符串的空值进行比较?

我认为更好的方法是检查value?.email本身是否为Null

例如:

if (value?.email != "" &&
value?.email != null) {
print("here we are>>>>>>>>>>>>");
//navigateToHomePage();
}

最新更新