ABSTRACT

In this chapter, you will learn one more strategy to manage states in Flutter applications. You will also learn to implement the state-management solution using the BLoC pattern. The BLoC pattern was introduced by Google I/O 2018 (Build reactive mobile apps with Flutter (Google I/O ‘18)) that uses reactive programming to manage the Flutter application's data flow (s). A BLoC is a design pattern to facilitate data flow to Flutter widgets and vice versa. It stands for B usiness Lo gic C omponent. The data sources can be API responses or data/events generated from widgets. The BLoC receives streams of the event(s) from data sources and/or widgets, perform business logic on events received and emits corresponding states. First you will learn to implement BLoC pattern using in-built dart features like Stream, Sink, and StreamController. Once you build your understanding of the BLoC pattern, you will learn to improvise the implementations by converting events and states into their classes. You will implement both of the solutions to re-architect the CounterApp. Lastly, you will use the bloc library package to reduce the boiler-plate code due to manual implementation.