0

I have 2 different cubits in my application. One is a Settings cubit and the other is a homepage cubit.

From the Homepage the user can move to the SettingsPage where settings can be modified.

The Settings cubit is created Above MaterialApp in main.dart to provide it app wide.

What I need to achieve is:

  1. I must create/load the current settings on app startup. I was thinking about doing this on the cubit constructor but can I emit from a cubit constructor?
  2. Every time settings are changed (because of the initial settings loaded or modification in settings page), the homepage should reload.

I have all working with the homepage cubit. It listens to changes with a BlocProvider and redraws the UI accordingly. But my problem is how to make it work with the settings cubit.

I could provide some code but there's a lot of unrelated bloc stuff, so I prefer to just expose the problem.

Notbad
  • 5,936
  • 12
  • 54
  • 100
  • So you want the homepage to reload if either the homepage cubit or settings cubit changes? – TarHalda Dec 02 '22 at 18:04
  • https://stackoverflow.com/questions/59562839/multi-blocbuilder-in-flutter is related to your second question. – TarHalda Dec 02 '22 at 18:07
  • Also https://stackoverflow.com/questions/68241884/issue-with-nested-blocbuilder-calls?rq=1 – TarHalda Dec 02 '22 at 18:08
  • @TarHalda yes, but remember that the settings cubit is created and loads on app start up. At this stage I think Homepage is not even created so, how is it going to reload? – Notbad Dec 02 '22 at 18:12
  • it will check for changes when it is created, then – TarHalda Dec 02 '22 at 18:14
  • About your last comment, are state changes queued or something like that until a listener is connected? Because remember that I will emit in the SettingsCubit constructor and at this statege HomePage is not built yet – Notbad Dec 02 '22 at 18:18
  • The builder will get the latest state when it builds the HomePage for the first time. (Source: that's how I've seen it work.) – TarHalda Dec 02 '22 at 18:37

0 Answers0