When you want to use a BLoC as a state management pattern, a number of steps need to be performed and these are as follows:
- Create a class that will serve as the BLoC.
- In the class, declare the data that needs to be updated in the app.
- Set StreamControllers.
- Create the getters for streams and sinks.
- Add the logic of the BLoC.
- Add a constructor in which you'll set the data.
- Listen to changes.
- Set a dispose method.
- From the UI, create an instance of the BLoC.
- Use StreamBuilder to build the widgets that will use the BLoC data.
- Add events to the sink for any changes to the data (if required).
Most of the code in this recipe is similar to the previous one, Using StreamBuilder to create reactive user interfaces. The main difference is that we moved the logic of the app (the countdown in this case) to the BLoC class so that the user interface has almost no logic at all, which is the purpose of using a BLoC. Actually, the...