BLoC – writing business logic separately
BLoC stands for business logic component. This technique is widely used in a lot of applications due to its capability of decoupling your core business logic from your UI, network, or repository classes. BLoC works on streams underneath and allows you to send events from your UI and receive states to your UI in order to update the changes based on user interaction. Inside BLoC state management, there are three main keywords you will have to get yourself familiarized with:
- The bloc itself (all your business logic lies inside this class)
- The state (this tells the UI when to update itself)
- The event (you trigger the events from your UI class in order to do something inside your bloc)
Adding a BLoC dependency in your application
Just like before, create a new Flutter application through the command line:
flutter create any_name_you_wish
You will get the same counter example application with the default setState...