[Solved] Flutter Error: Could not find the correct Provider above this EditorPage Widget

2023/02/12 23:04

======== Exception caught by widgets library =======================================================
The following ProviderNotFoundException was thrown building EditorPage(dirty, state: _EditorPageState#86f14):
Error: Could not find the correct Provider<ImgStream> above this EditorPage 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 EditorPage is under your MultiProvider/Provider<ImgStream>.
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()),

consider using `builder` like so:

Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// we use `builder` to obtain a new `BuildContext` that has access to the provider
builder: (context, child) {
// No longer throws
return Text(context.watch<Example>().toString());

If none of these solutions work, consider asking for help on StackOverflow:

The relevant error-causing widget was:
EditorPage EditorPage:file:///C:/Users/Eddy/StudioProjects/itwi/lib/pages/diary_page.dart:209:24
When the exception was thrown, this was the stack:
#0 Provider._inheritedElementOf (package:provider/src/provider.dart:343:7)
#1 Provider.of (package:provider/src/provider.dart:293:30)
#2 _EditorPageState.build (package:itwi/pages/editor_page.dart:131:40)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4992:27)



Add code like the sample below before your highest level MaterialApp(...).
  create: (BuildContext context) {
    return StarListStream();

Leave a Reply

Back to top