Bloc: Question: using bloc between multiple pages

Created on 16 Nov 2019  路  2Comments  路  Source: felangel/bloc

Hi
sorry if this not belong here but I could not find any forum.

Let's say I have the application with movies and I can each movie mark as 'favourite'. And we have 3 pages:

  • movie list page
  • detail page of the movie
  • favourites list page

From each page, I can directly mark/unmark movie as favourited. What is properly setup/architecture for this?

  • Having for each page own Bloc? (I am coming from MVC / MVVM world and this make 'sense' to me)
  • Having top-level MoviesBloc and share this bloc on every page?

Data are stored in some abstract 'repository' layer.
In case of having for each page its own bloc how can i orchestrate them? (e.g from detail movie was marked, how to propagate this change to another bloc..)

Also what we want to achieve

  • rebuild movie widget within list only that change its state (marked/unmarked as a favorite), not the whole list
  • when for example I mark as favourite within detail page, after I return (pop up the stack) back to list, change must be propagated.

bloc

These are questions which I am a bit confused about.
Thank you for any help!

question

Most helpful comment

Creating bloc per page is a good option, but you might want rather create one bloc per big enough functionality.

You would like to, probably, have one main Bloc for movie list, and some other Bloc to handle showing the individual movie, etc.

Check TodosBloc and FilteredTodosBloc bloc-to-bloc communication at https://bloclibrary.dev/#/fluttertodostutorial

All 2 comments

Creating bloc per page is a good option, but you might want rather create one bloc per big enough functionality.

You would like to, probably, have one main Bloc for movie list, and some other Bloc to handle showing the individual movie, etc.

Check TodosBloc and FilteredTodosBloc bloc-to-bloc communication at https://bloclibrary.dev/#/fluttertodostutorial

Hi @petrnymsa 馃憢
Thanks for opening an issue!

As @tenhobi mentioned, I would recommend having a single bloc which manages the state of the movie list for the entire application. Each movie can include a property for whether it is a favorite. Changes in the favorites bloc can then update the movies bloc (analogous to how you can update a todo as done). Hope that helps and I'd definitely recommend looking at the todos tutorial for inspiration.

Hope that helps and feel free to ask any additional questions on gitter 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clicksocial picture clicksocial  路  3Comments

RobPFarley picture RobPFarley  路  3Comments

ricktotec picture ricktotec  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

frankrod picture frankrod  路  3Comments