gpt4 book ai didi

flutter - 如何在flutter中使用三进制检查sharedpreferences中的数据

转载 作者:行者123 更新时间:2023-12-03 03:35:24 25 4
gpt4 key购买 nike

我想检查我的数据在sharedpreferences ..是否存在或不使用三元数据..有没有办法做到这一点?这是代码

            Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//I want to check something inside sharedpreferences here but I don't have any idea to do that
(something I want to check) ? do something :
isLoading
? Text("Loading...")
: (_image == null)
? Text('In')
: (_data.length == 0)
? Text("Try again")
: fail
? Text("Try again")
: DateFormat("HH:mm:ss")
.format(DateTime.now()) ==
"23:59:59"
? changeTime()
: Text("Success")
],
),

最佳答案

试试这个

Take one boolean variable


bool isVisible = true;

now update your isVisible variable inside getLoginStatus() method


void getLoginStatus() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String userData = prefs.getString('YourKEY');
if (userData?.isEmpty ?? true) {
setState(() {
isVisible = false;
});
} else {
setState(() {
isVisible = true;
});
}
}

Now you can need to call getLoginStatus() when you need to check the value in sharedpreferences


Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

isVisible ? do something :
isLoading
? Text("Loading...")
: (_image == null)
? Text('In')
: (_data.length == 0)
? Text("Try again")
: fail
? Text("Try again")
: DateFormat("HH:mm:ss")
.format(DateTime.now()) ==
"23:59:59"
? changeTime()
: Text("Success")
],
),

关于flutter - 如何在flutter中使用三进制检查sharedpreferences中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61364604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com