title: How to access Shared Preferences String in build method flutter
body: <p>I'm trying to access userEmail in shared preferences, inside my build method. Here's some of the code for context:</p>
  <pre><code>  Widget build(BuildContext context) {
      final prefs = await SharedPreferences.getInstance();
      final userEmail = prefs.getString('userEmail') ?? '';
  ...
  Return Scaffold(
  body: SingleChildScrollView(
                  scrollDirection: Axis.horizontal,
                  child: StreamBuilder&lt;QuerySnapshot&gt;(
                    stream: _firestore.collection(userEmail).orderBy('time', descending: false).snapshots(),
  ...
  </code></pre>
  <p>The issue I have is, an error comes up highlighting the <code>await</code>. When i hover over it with my cursor for more info, it say <code>The await expression can only be used in an async function.  Try marking the function body with either 'async' or 'async*'.</code></p>
  <p>There is then an option to add 'async' modifier. So i clicked that, which transformed code into this:</p>
  <pre><code>Future&lt;Widget&gt; build(BuildContext context) async {
  ...
  
  </code></pre>
  <p>This causes another error message: <code>'_HomeScreenState.build' ('Future&lt;Widget&gt; Function(BuildContext)') isn't a valid override of 'State.build' ('Widget Function(BuildContext)').</code></p>
  <p>Any ideas how to solve this issue? I've tried saving the userEmail using the Provider package. This works perfectly when the user first signs in or registers, but if you hot reload, the stream doesn't work.</p>