Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davehorner opened this issue Aug 15, 2023 · 8 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@davehorner
Copy link

davehorner commented Aug 15, 2023

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 davehorner added bug Something isn't working needs triage labels Aug 15, 2023
@davehorner
Copy link
Author

davehorner commented Aug 15, 2023

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
Copy link
Author

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

@rrousselGit
Copy link
Owner

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

@rrousselGit
Copy link
Owner

Maybe try flutter clean / flutter pub uprade and try again

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Aug 16, 2023
@davehorner
Copy link
Author

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

@davehorner
Copy link
Author

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
Copy link
Author

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

@rrousselGit
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants