Bloc: Access to Bloc in different Pages and refresh event with BlocListener

Created on 23 Jun 2020  路  1Comment  路  Source: felangel/bloc

Hello there!

After going trough issues #74 #763 #776 I have to ask a question myself, I have uploaded the minimal (not) working code here: https://github.com/Vash1/flutter_weather_settings

The Problem:
Triggering the Toggle event on a Switch on Page2 works. But after returning to Page1 and again going to Page2, the initialState is fired again, resetting my choice.

My Analysis so far:
Following the advices I mentioned, this issue is gone
BlocProvider.of() called on a context that does not contain a Bloc of type SettingsBloc. No ancestor could be found starting from the context ...
But somehow my code ended up with 2 BlocProviders, leading to multiple instatiations of the SettingsBloc.

Maybe I ended up with 2 Instances of the same bloc in different contexts? Or am not refreshing/listening for changes on my HomePage properly? Because also the "Center Text $state.xyz" on my Page1 always stays unchanged when I return from Page2.
This already took me a good amount of time so now I had to ask, and I'm very grateful for advices and help.

Thanks.

question

Most helpful comment

Hi @Vash1 馃憢
Thanks for opening an issue!

I've opened a pull request to address the issue. You were creating multiple instances of the SettingsBloc rather than reusing the existing instance when navigating to the SettingsPage.

Hope that helps 馃憤

>All comments

Hi @Vash1 馃憢
Thanks for opening an issue!

I've opened a pull request to address the issue. You were creating multiple instances of the SettingsBloc rather than reusing the existing instance when navigating to the SettingsPage.

Hope that helps 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wheel1992 picture wheel1992  路  3Comments

timtraversy picture timtraversy  路  3Comments

rsnider19 picture rsnider19  路  3Comments

nhwilly picture nhwilly  路  3Comments

nerder picture nerder  路  3Comments