title: SharedPreferences in Flutter not persisting?
body: <p>I'm trying to implement a &quot;Remember Me&quot; functionality by using SharedPreferences. Unfortunately, no matter what I do, it doesn't seem like the login details are persisting. I'm using SharedPreferences on my Sign In screen as below by invoking it in the <code>initState</code> method (through to my GetX controller):</p>
  <pre><code>  final SignInController controller = Get.put(SignInController());
   
    @override
    void initState() {
      // TODO: implement initState
      controller.loadRememberMeDetails();
      super.initState();
    }
  
  ...
  
  Row(
   children: [
                                          SizedBox(
                                            height: 24.0,
                                            width: 24.0,
                                            child: GetBuilder&lt;SignInController&gt;(
                                              builder: (s) =&gt; Checkbox(
                                                value: s.isChecked,
                                                onChanged: s.handleRememberMe,
                                              ),
                                            ),
                                          ),
                                          SizedBox(width: 5.0),
                                          Material(
                                              color: Colors.transparent,
                                              child: InkWell(
                                                onTap: () {
                                                  controller.handleRememberMe(
                                                      !controller.isChecked);
                                                },
                                                child: Text(
                                                  &quot;Remember Me&quot;,
                                                  style: TextStyle(
                                                      color: Colors.black,
                                                      fontSize: 15),
                                                ),
                                              ))
                                        ],
                                      ),
  
  </code></pre>
  <p>I invoke the following to save it:</p>
  <pre><code>  void handleRememberMe(bool? value) async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      await prefs.setBool(&quot;remember_me&quot;, value!);
      await prefs.setString('email', emailController.text);
      await prefs.setString('password', passwordController.text);
  
      print(&quot;Remember me: ${emailController.text} ${passwordController.text}&quot;);
  
      isChecked = value!;
      update();
    }
  </code></pre>
  <p><code>initState()</code> invokes the following method on initialisation:</p>
  <pre><code>
   void loadRememberMeDetails() async {
      try {
        SharedPreferences prefs = await SharedPreferences.getInstance();
        var email = prefs.getString(&quot;email&quot;) ?? &quot;&quot;;
        var password = prefs.getString(&quot;password&quot;) ?? &quot;&quot;;
        var rememberMe = prefs.getBool(&quot;remember_me&quot;) ?? false;
  
        if (rememberMe) {
          isChecked = true;
          emailController.text = email;
          passwordController.text = password;
          update();
        }
      } catch (e) {
        print(e);
      }
    }
  </code></pre>
  <p>However, <code>email</code>, etc local variables show null.</p>
  <p>Any ideas on how to fix?</p>