【发布时间】:2021-08-25 12:25:38
【问题描述】:
我有一个这样的checkLoginStatus()。它将返回true 或false
checkLoginStatus() async {
sharedPreferences = await SharedPreferences.getInstance();
print(sharedPreferences.getString("token"));
if (sharedPreferences.getString("token") != null) {
return true;
}
return false;
}
我有一个button A,代码如下
press: () => {
if(checkLoginStatus()) {
//..Some code
} else {
//..
}
}
我点击button A 得到
Another exception was thrown: type 'Future<dynamic>' is not a subtype of type 'bool'
为什么?以及如何在if() 条件下检查checkLoginStatus() 返回true 或false?
【问题讨论】:
-
这能回答你的问题吗? What is a Future and how do I use it?