title: Flutter: How to use SharedPreferences synchronously?
body: <p>I am using Shared Preferences in my Flutter app and what I would like to do is store <code>SharedPreferences</code> as a field on startup and then use it synchronously in the app. However I'm not sure if I'm not missing anything.
  What I want to achieve is instead of:</p>
  <pre><code>method1() async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    return sp.getString('someKey');
  }
  </code></pre>
  <p>to</p>
  <pre><code>SharedPreferences sp;
  //I would probably pass SharedPreferences in constructor, but the idea is the same
  someInitMethod() async {
    sp = await SharedPreferences.getInstance();
  }
  method1() {
    return sp.getString('someKey');
  }
  method2() {
    return sp.getString('someKey2');
  }
  method3() {
    return sp.getString('someKey3');
  }
  </code></pre>
  <p>In that way I would achieve synchronous access to sharedPrefs. Is it bad solution?</p>
  <p>EDIT:<br />
  What is worth mentioning is that <code>getInstance</code> method will only check for instance and if there is any than it returns it, so as I see it, is that <code>async</code> is only needed to initialize instance. And both <code>set</code> and <code>get</code> methods are sync anyway.</p>
  <pre><code>static Future&lt;SharedPreferences&gt; getInstance() async {
    if (_instance == null) {
      final Map&lt;String, Object&gt; fromSystem =
          await _kChannel.invokeMethod('getAll');
      assert(fromSystem != null);
      // Strip the flutter. prefix from the returned preferences.
      final Map&lt;String, Object&gt; preferencesMap = &lt;String, Object&gt;{};
      for (String key in fromSystem.keys) {
        assert(key.startsWith(_prefix));
        preferencesMap[key.substring(_prefix.length)] = fromSystem[key];
      }
      _instance = new SharedPreferences._(preferencesMap);
    }
    return _instance;
  }
  </code></pre>