So you should have noticed that there has been no attempt to layer our app so that we are back in the Dark ages before patterns like MVVM and MVC. Now maybe you liked the Dark Ages but architecture becomes more important as your app grows in size to manage complexity. the BLOC pattern is almost the same as MVVM and if you like we call it our ViewModel. The BLOC pattern can be build on Streams or RxDart , a reactive functional programming library for Google Dart, based on ReactiveX.
Google Dart comes with a very decent Streams API out-of-the-box; rather than attempting to provide an alternative to this API, RxDart adds functionality on top of it . I pull in RXDart as it includes Observables. So then our architecture can look like this and the ViewModel folks should be happier.
So lets look at how I use BLOC in a app that I am working on. I need to a list of routines (set of exercises) and use a repository to have a Mock provider and HTTP provider. I will only share the Mock for the blog. we are going to use StreamBuilder and a stream provides a way to receive a sequence of events. Each event is either a data event, also called an element of the stream, or an error event. You listen on a stream to make it start generating events, and to set up listeners that receive the events.