当我从SharedPreferences数据,它不会在字符串中显示它并给出了一个错误在该行帐户名:Text(sharedPreferenceEmail)
,错误显示,sharedPreferenceEmail = NULL
SharedPreferences sharedPreferences;
String sharedPreferenceEmail;
String value;
@override
void initState() {
super.initState();
getDataPreference();
}
getDataPreference() async {
sharedPreferences = await SharedPreferences.getInstance();
setState(() {
value = sharedPreferences.getString("email");
if(value != null) {
sharedPreferenceEmail = sharedPreferences.getString("email");
} else {
sharedPreferenceEmail = "Sign in with Google";
}
});
}
UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.blueGrey[900]),
accountName: Text(
sharedPreferenceEmail
),
如果您在使用异步执行获得的值,你需要警惕qazxsw POI时小赌怡情,而结果还没到不会造成异常:
null