title: Flutter: `Provider.of(context)` cannot be found when it is a `FutureProvider()`
body: <p>I have a provider in my widget tree and I call <code>Provider.of&lt;List&lt;...&gt;&gt;(context)</code> to find it. If it is a provider of any type it works fine, however, as soon as change the provider from a <code>Provider()</code> (for example) to a <code>FutureProvider()</code> it doesn't work.</p>
  <p>I haven't changed any widgets in the tree and haven't changed their position in the navigator. <code>Provider.of()</code> works fine but once I set it to be a <code>FutureProvider()</code> then it doesn't work.</p>
  <p>Edit: My code looks something like this:</p>
  <p>inside widget build:</p>
  <pre class="lang-dart prettyprint-override"><code>return FutureProvider(
        initialData: [],
        create: (_) =&gt;
            DatabaseService(uid: _auth.getUser()!.uid).getJournalEntries(),
        catchError: (context, error) {
          print(error.toString());
        },
        ...
  }
  </code></pre>
  <p>Then one of the children is another widget and this is its build function:</p>
  <pre class="lang-dart prettyprint-override"><code>List&lt;JournalEntryData&gt; entries =
          Provider.of&lt;List&lt;JournalEntryData&gt;&gt;(context);
      return ElevatedButton(
          onPressed: () {
            print(entries);
          },
          child: Text('print provider data'));
  }
  </code></pre>
  <p>I get the following error:</p>
  <p>Error: Could not find the correct Provider&lt;List&gt; above this TestButton Widget</p>
  <p>This happens because you used a <code>BuildContext</code> that does not include the provider
  of your choice. There are a few common scenarios:</p>
  <ul>
  <li><p>You added a new provider in your <code>main.dart</code> and performed a hot-reload.
  To fix, perform a hot-restart.</p>
  </li>
  <li><p>The provider you are trying to read is in a different route.</p>
  <p>Providers are &quot;scoped&quot;. So if you insert of provider inside a route, then
  other routes will not be able to access that provider.</p>
  </li>
  <li><p>You used a <code>BuildContext</code> that is an ancestor of the provider you are trying to read.</p>
  <p>Make sure that TestButton is under your MultiProvider/Provider&lt;List&gt;.
  This usually happens when you are creating a provider and trying to read it immediately.</p>
  <p>For example, instead of:</p>
  <pre><code>Widget build(BuildContext context) {
    return Provider&lt;Example&gt;(
      create: (_) =&gt; Example(),
      // Will throw a ProviderNotFoundError, because `context` is associated
      // to the widget that is the parent of `Provider&lt;Example&gt;`
      child: Text(context.watch&lt;Example&gt;()),
    ),
  }
  </code></pre>
  <p>consider using <code>builder</code> like so:</p>
  <pre><code>Widget build(BuildContext context) {
    return Provider&lt;Example&gt;(
      create: (_) =&gt; Example(),
      // we use `builder` to obtain a new `BuildContext` that has access to the provider
      builder: (context) {
        // No longer throws
        return Text(context.watch&lt;Example&gt;()),
      }
    ),
  }
  </code></pre>
  </li>
  </ul>
  <p>The problem is that there is a provider in the widget tree:
  <a href="https://i.stack.imgur.com/pmc3F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pmc3F.png" alt="Widget Tree" /></a></p>
  <p>Replacing the <code>FutureProvider()</code> with any other type of provider makes it work, but I need a <code>FutureProvider()</code>.</p>