【发布时间】:2020-05-08 20:50:55
【问题描述】:
我想让 TextFormField 启用属性为 false 或 true。我尝试从 sharedpreferences 中获取虚假或真实的价值。我在应用打开时保存 ifLogged 值“true”。
所以,我在我的屏幕上使用 ifLogged 值之一。 我的问题是; isLogged 参数第一次为假,第二次为真。
bool isLogged = false;
Future<bool> checkLogin() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
isLogged = (prefs.getBool('ifLogged') ?? false);
return isLogged;
}
@override
void initState() {
super.initState();
checkLogin();
}
TextFormField(enabled: isLogged ? true : false,
...
bool isLogged在Future<bool>之间有什么问题吗
【问题讨论】: