Provider: using MultiProvider, "Error: Could not find the correct Provider" occured

Created on 19 Feb 2020  Â·  2Comments  Â·  Source: rrousselGit/provider

I'm very in trouble and want to help.

When I use Provider(not MultiProvider), Could not find the correct Provider<LaborModel>is not happend and works correctly.
However when I use MultiProvider, the error was happen.

I have already ensured the Provider is an ancestor to this Consumer Widget.

My full application with the error
https://github.com/kazumaz/dama_app

version

provider:  ^4.0.2

my source Excerpt

        providers: [
          ChangeNotifierProvider<RewordModel>(create: (_) => RewordModel()),
          ChangeNotifierProvider<LaborModel>(create: (_) => LaborModel()),
          ChangeNotifierProvider<PointModel>(create: (_) => PointModel()),
        ],

my source Excerpt

  Widget build(BuildContext context) {
    return Consumer<LaborModel>(builder: (context, laborModel, child) {
      return Scaffold(
        body: ListView.builder(
          itemBuilder: (BuildContext context, int index) {
            return Card(
              child: Padding(
                child: Text(
                  laborModel.rewardList[index].point.toString() + " Point:  " + laborModel.rewardList[index].name,
                  style: TextStyle(fontSize: 22.0),
                ),
                padding: EdgeInsets.all(20.0),
              ),
            );
          },
          itemCount: laborModel.rewardList.length,
        ),
      );
    });
  }

ERROR log

flutter: The following ProviderNotFoundException was thrown building Consumer<LaborModel>(dirty):
flutter: Error: Could not find the correct Provider<LaborModel> above this Consumer<LaborModel> Widget
(base) kazumanoMacBook-Air:dama_app kazuma$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.1 19B88, locale ja-JP)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[✓] Android Studio (version 3.5)
[!] IntelliJ IDEA Community Edition (version 2019.2.4)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.42.0)
[✓] Connected device (1 available)

! Doctor found issues in 1 category.
(base) kazumanoMacBook-Air:dama_app kazuma$ 

Most helpful comment

@kazumaz what was the solution? I am facing the same issue

All 2 comments

i have fixed, sorry

@kazumaz what was the solution? I am facing the same issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stocksp picture stocksp  Â·  5Comments

tmxdyf picture tmxdyf  Â·  3Comments

Vadaski picture Vadaski  Â·  3Comments

FaizanKamal7 picture FaizanKamal7  Â·  6Comments

MaxTenco picture MaxTenco  Â·  5Comments