Flutter: How to read preferences at Widget startup? : <p>I have been trying to read preferences at Widget startup but have been unable to find a solution.
I wish to show the users name in a TextField (which they can change) and store it in preferences so that it is shown as soon as they go back to the page.</p>

<pre><code>class _MyHomePageState extends State&lt;MyHomePage&gt; {
  TextEditingController _controller;
  :
  :
  Future&lt;Null&gt; storeName(String name) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString("name", name);
  }

  @override
  initState() async {
    super.initState();
    SharedPreferences prefs = await SharedPreferences.getInstance();
    _controller = new TextEditingController(text: prefs.getString("name"));
  }

  @override
  Widget build(BuildContext context) {
  :
  :
  return new TextField(
               decoration: new InputDecoration(
                 hintText: "Name (optional)",
               ),
               onChanged: (String str) {
                 setState(() {
                   _name = str;
                   storeName(str);
                 });
               },
               controller: _controller,
             )
  }
}
</code></pre>

<p>I got the idea for using async on initState() from :<br/>
<a href="https://stackoverflow.com/questions/45107702/flutter-timing-problems-on-stateful-widget-after-api-call">flutter timing problems on stateful widget after API call</a> <br/>
But the async seems to cause this error on startup :</p>

<pre><code>'package:flutter/src/widgets/framework.dart': Failed assertion: line 967 pos 12: 
'_debugLifecycleState == _StateLifecycle.created': is not true.
</code></pre>

<p>I looked for examples of FutureBuilder but cannot seem to find any which are similar to what I am trying to do.</p>
