问题数据sharedpreferences - 扑

问题描述 投票:1回答:1

当我从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
                  ),

enter image description here

android dart flutter sharedpreferences
1个回答
1
投票

如果您在使用异步执行获得的值,你需要警惕qazxsw POI时小赌怡情,而结果还没到不会造成异常:

null
© www.soinside.com 2019 - 2024. All rights reserved.