title: Flutter SharedPreferences getInstance return null
body: <p>Although I set the _sharedPreferences in the constructor, it gets null in getUsername. I don't know missing what:</p>
  
  <pre><code>  class PreferencesProvider {
    SharedPreferences _sharedPreferences;
  
    PreferencesProvider() {
      SharedPreferences.getInstance().then((prefs) =&gt; _sharedPreferences = prefs);
    }
  
    String getUsername() {
      return _sharedPreferences.getString("Username");
    }
  
    String getX() {
      return _sharedPreferences.getString("X");
    }
  
    String getY() {
      return _sharedPreferences.getString("Y");
    }
  
    String getZ() {
      return _sharedPreferences.getString("Z");
    }
  }
  </code></pre>
  
  <p>alternatively it didn't work either:</p>
  
  <pre><code>class LoginProvider {
    SharedPreferences _sharedPreferences;
  
    LoginProvider._internal();
    static final LoginProvider _instance = LoginProvider._internal();
  
    factory LoginProvider() {
      _instance.initPreferences();
      return _instance;
    }
  
    initPreferences() async {
      _sharedPreferences = await SharedPreferences.getInstance();
    }
  </code></pre>
  
  <p>I want to use this in MaterialApp:</p>
  
  <pre><code>initialRoute: PreferencesProvider().isLoggedIn() ? "MainPage" : "LoginPage"
  </code></pre>
  
  <p>Edit: I know I should use await. But then keyword isn't same? I don't want to wait the instance again for all returns. In the other hand, I can't use await in initialRoute.</p>