title: Flutter : SharedPreferences not fetching value at app start
body: <p>I am trying to store a value and based on the value I want to navigate to LandinPage or HomePage. However when my app loads I am not able to get the SharedPreferences value. Currently, the value is set on click of a button in Landing page, and when I close/minimize the app. I don't even get to see the print messages from main.dart and can't fetch values. What am I doing wrong? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import 'package:credit/src/pages/landing.dart';
  import 'package:flutter/material.dart';
  import 'package:credit/src/pages/credit/home.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatefulWidget {
    MyApp({Key key}) : super(key: key);
  
    _LoadingPageState createState() =&gt; _LoadingPageState();
  }
  
  class _LoadingPageState extends State&lt;MyApp&gt; {
    @override
    void initState() {
      super.initState();
      getUserStatus().then((userStatus) {
        if (userStatus == null) {
          Navigator.of(context)
              .push(MaterialPageRoute&lt;Null&gt;(builder: (BuildContext context) {
            return LandingPage();
          }));
        } else {
          Navigator.of(context)
              .push(MaterialPageRoute&lt;Null&gt;(builder: (BuildContext context) {
            return HomePage();
          }));
        }
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
          child: Center(
        child: CircularProgressIndicator(),
      ));
    }
  }
  
  Future&lt;String&gt; getUserStatus() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String userStatus = prefs.getString('userstatus');
    print("==On Load Check ==");
    print(userStatus);
    return userStatus;
  }
  </code></pre>