rrousselGit / provider

InheritedWidgets, but simple
https://pub.dev/packages/provider
MIT License
5.12k stars 511 forks source link

Provider<ThemeProvider> not found for Consumer<ThemeProvider> works in debug; broken in release. #831

Open davehorner opened 1 year ago

davehorner commented 1 year ago

I have an app that works fine in debug mode. When run in release the application can not find the provider from the context. I can see that the MultiProvider is working as I see the constructor printing output in both release and debug. I see from many other reports that others have experienced the same problem of debug builds succeeding and release builds failing but I see no one has created a reproduction.

To reproduce, I pulled apart my code and tried to get the basics of what I'm doing in a new flutter project. https://github.com/davehorner/provider-release-debug-reproduction This works in debug and grey screen exception in release.

The sample tries to create a themeprovider which is used to create and theme the materialApp. Then when the user clicks the "s" button, it tries to get the provider from the context using Consumer. I did not connect the provider to display or actually set the themes in the sample. Debug does allow you to change the theme from the settings page and it shows properly on MyHomePage when settings is pop'd. Release will not construct settings page and gives a grey screen exception.

Hopefully this gives you an idea of what I'm doing wrong. I didn't spend too much time on the sample, it isn't functional, but if you run in debug, you'll find the Consumer gets the provider, running in release, it will fail.

I/flutter (18027): THEMEPROVIDER!!!
I/flutter (18027): THEMEPROVIDER!!! ThemeMode.system
I/flutter (18027): THEMEPROVIDER!!! EXIT CONSTRUCTOR
I/flutter (18027): Provider<ThemeProvider> not found for Consumer<ThemeProvider>
I/flutter (18027): #0      Provider._inheritedElementOf (package:provider/src/provider.dart:343)
I/flutter (18027): #1      Provider.of (package:provider/src/provider.dart:293)
I/flutter (18027): #2      Consumer.buildWithChild (package:provider/src/consumer.dart:181)
I/flutter (18027): #3      SingleChildStatelessWidget.build (package:nested/nested.dart:259)
I/flutter (18027): #4      StatelessElement.build (package:flutter/src/widgets/framework.dart:5156)
I/flutter (18027): #5      SingleChildStatelessElement.build (package:nested/nested.dart:279)
I/flutter (18027): #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5086)
I/flutter (18027): #7      Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #8      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #9      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #10     SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222)
I/flutter (18027): #11     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #12     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #14     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #15     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #16     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #17     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #18     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #19     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #20     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #21     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #22     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #23     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #25     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #26     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #27     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #28     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #29     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #30     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #31     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #33     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #35     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #36     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #37     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #38     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #39     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #40     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #41     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #42     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #43     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #44     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #45     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #46     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #47     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #48     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #49     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #50     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #51     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #52     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #53     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #54     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #55     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #56     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #57     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #58     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #59     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #60     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #61     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #62     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #63     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #64     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #65     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #66     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #67     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #68     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #69     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #70     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #71     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #72     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #73     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #74     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #75     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #76     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #77     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #78     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #79     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #80     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #81     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #82     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #83     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #84     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #85     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6435)
I/flutter (18027): #86     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #87     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #88     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #89     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #90     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #91     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
I/flutter (18027): #92     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5242)
I/flutter (18027): #93     ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062)
I/flutter (18027): #94     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971)
I/flutter (18027): #95     Element.updateChild (package:flutter/src/widgets/framework.dart:3708)
I/flutter (18027): #96     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111)
I/flutter (18027): #97     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251)
I/flutter (18027): #98     Element.rebuild (package:flutter/src/widgets/framework.dart:4805)
I/flutter (18027): #99     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:5068)
Application finished.

I am running this on android. I tried going back to 5.0.0, error persists. Running out of ideas.

davehorner commented 1 year ago

After factoring out the problem to a reproduction; going back to my application. I changed the AppManifest to use android:label="@string/app_name" which is different depending on release/debug. The main application is now working in both debug and release.

The sample is still failing and a valid reproduction case. I don't know if the label changing is the thing that unstuck the application... it is troublesome debugging when things just start working. Luckily we have a reproduction and I can continue my development without being stuck!

Let me know if you have any suggestions on how to help corral this issue.

davehorner commented 1 year ago

My application is not working anymore. There's something strange going on.

rrousselGit commented 1 year ago

I don't have any error in release mode. I was correctly able to open the settings page and change the theme

rrousselGit commented 1 year ago

Maybe try flutter clean / flutter pub uprade and try again

davehorner commented 1 year ago

clean and upgrades done many times. I'm glad and also sorry to hear it works. not a fun problem.

davehorner commented 1 year ago

Both the sample and the application exhibit the release exception here.

I'm running Flutter (Channel stable, 3.10.6, on Microsoft Windows [Version 10.0.19045.3324], locale en-US) I am using multidex in the application, the sample does not so it may not relate.

I have no other ideas other than to try it on another machine; which is what you've done.

davehorner commented 1 year ago

Do you see anything wrong with the code? It's happening in debug this evening.

rrousselGit commented 1 year ago

Nope, I see nothing wrong with the sample you gave so far