Flutter Bloc with Multiple Streams

Posted by Andre Scott | Updated on

Flutter Bloc with Multiple Streams. As the name say, the core idea behind BLoC is to separate the responsibilities between UI and business rules, so depends on how you want to architect and organize that logic. Maybe if you implement a bloc for a simple screen, you’ll be good with one stream, but as your app gets complex maybe you’ll need to break those blocs in small blocs with logic that is related with a single object and then compose it for each screen.

To answer the question, the true is that depends of the case, but as you emphasize that the two actions treat distinct objects ill suggest you to handle it in different streams to have a nice separation of responsibilities. In the future, if you need to refactor and maintain the code it will be easier since you already have all the logic completely separated.

Another important advantage of this is that you can have strongly typed Streams with all the benefits that entails, in the second case Actions must be in the same hierarchy in order to be added to the same sink.

Hope it helps!

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers