Skip to content

Question: how to call ancestor bloc from descendant #3174

@cdprete

Description

@cdprete

Hi @felangel and thanks for this amazing library :)
I've an application which, within the body of a Scaffold, renders a list of items and the FloatingActionButton of such Scaffold is used to open a dialog which the user can use to add a new item.
In such scenario, I've at the moment 2 blocs: one for adding the new item and one for listing the available items in a paginated way.

I've the requirement to refresh the list of items as soon as the new item is added, but I cannot imagine how to it with flutter_bloc in a "nice" way.

Since the 2 blocs are under different contexts, I cannot really read the bloc handling the list from the one adding the new item.
One way I can imagine is to lift the state of the list of items up, so that the Scaffold is child of the BlocProvider instead of being the latter the child of the body of the former, but it would be really ugly because the Scaffold renders a BottomNavigationBar with 3 items (and therefore 3 pages) and this would mean define a MultiBlocProvider which provides the Bloc to each page.
As a result, the bloc managing the list (and, in the future, the ones from the other pages) would be really out of scope in my opinion (in the sense and its scope is way broader than it should be).

What do you suggest from your point of view? How would you design the interaction with the blocs in such scenario?

Kind regards and thanks in advance,
Cosimo

Metadata

Metadata

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions