0

Code

Error: Could not find the correct Provider above this PostCard Widget

This happens because you used a BuildContext that does not include the provider of your choice. There are a few common scenarios:

  • You added a new provider in your main.dart and performed a hot-reload. To fix, perform a hot-restart.

  • The provider you are trying to read is in a different route.

    Providers are "scoped". So if you insert of provider inside a route, then other routes will not be able to access that provider.

  • You used a BuildContext that is an ancestor of the provider you are trying to read.

    Make sure that PostCard is under your MultiProvider/Provider. This usually happens when you are creating a provider and trying to read it immediately.

    For example, instead of:

    Widget build(BuildContext context) {
      return Provider<Example>(
        create: (_) => Example(),
        // Will throw a ProviderNotFoundError, because `context` is associated
        // to the widget that is the parent of `Provider<Example>`
        child: Text(context.watch<Example>().toString()),
      );
    }
    
vamshi
  • 1
  • 1
  • https://stackoverflow.com/questions/72047084/error-could-not-find-the-correct-provider-above-this-widget , here this might help you – Mado Jun 30 '22 at 07:45
  • Welcome to SO! Please, [you should I not upload images of code/data/errors when asking a question](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question/285557#285557). Click on the link below the question to [Edit](https://stackoverflow.com/posts/72811681/edit) it and replace the image with the code itself. Also, if possible, a [minimal-reproducible-example](https://stackoverflow.com/help/minimal-reproducible-example) would help users identify an adequate answer. – lepsch Jun 30 '22 at 08:55

0 Answers0