Member-only story
Flutter: A very brief explanation of BLoC and Streams.
BLoC stands for Business Logic Component.
Model View Controller (MVC) is a popular design pattern amongst developers across the community. However, as it is incompatible with the nature of Flutter, so BLoC was created.
BLoC, stands for Business Logic Component, like other design patterns, is used to manage state using streams and sinks. BLoC acts as a middle layer between source of data (e.g db, api call) and UI widgets that need that data.
The BLoC will receive a stream of data from source, apply any transformation/business logic required and then publishes streams of changed data to widgets listening to the stream.
BLoC is baked into the flutter framework, so “sinks” and “streams” are provided by the inbuilt “stream controller”. Streams of events/data are added into a sink and those listening to the stream automagically receive updates.