Bloc: Lack of examples for nesting blocs and complex apps.

Created on 18 Jun 2020  路  4Comments  路  Source: felangel/bloc

Hi, I can't find how to deal with nested blocs in documentation and in examples list. Spend a lot of time but made sort of Frankenstein.
For example, if I have a todo app where tasks - also need to be blocs:

Image 3

Here is a couple of the problems I encountered. Can we discuss it?

  1. I want to manipulate with all tasks from TodosListBloc. To make this, I decided to create an array of TaskBloc-s right inside TodosListBloc. I can't create TaskBloc with regular BlocProvider because I need some link to it in TodosListBloc. And "BlocProvider.of" - can't grab something which is lower in the widget tree.
    Is this a good idea to create an array of blocks right inside another bloc?
  1. Each time when database updates I download JSON. So according to it, It's necessary to create a new array of TaskBlocs each time database gets updated.
    Is this a good idea to create this array of blocks many times on every database update? If so how I can safely delete the old array of blocs?

3) Any tips on how to architect the app from the image in general?

example question

Most helpful comment

@felangel Of course. I鈥檝e been doing this since yesterday. This is exactly what I need! There are also many good code tricks to follow. Big thanks!
It is strange that I did not find it on my own. I was looking in bloclibrary.dev in Tutorial section, in this repo in the examples folder and in google by 'flutter nested blocs' query and not found your link. )
Perhaps it could be useful between tutorials.

All 4 comments

Hi @1g0rrr 馃憢
Thanks for opening an issue!

You can check out this todos app for a more complex example with a bloc for each todo item. Let me know if that helps 馃憤

@1g0rrr can you take a look at the app I linked above and let me know if that helps? Thanks 馃檹

@felangel Of course. I鈥檝e been doing this since yesterday. This is exactly what I need! There are also many good code tricks to follow. Big thanks!
It is strange that I did not find it on my own. I was looking in bloclibrary.dev in Tutorial section, in this repo in the examples folder and in google by 'flutter nested blocs' query and not found your link. )
Perhaps it could be useful between tutorials.

Awesome! Glad it helped and I鈥檒l try to incorporate it into the tutorials when I have time 馃憤

Was this page helpful?
0 / 5 - 0 ratings