The Business Logic Components (BloC) pattern in the Flutter community is a popular UI pattern that separates UI and business logic. It was originally developed by Google to share code between Flutter and Angular Dart. However, the pattern has evolved over time and is now widely used in Flutter projects. While the BloC pattern can help separate logic and UI, it is important to understand that following the rules of the pattern may only sometimes result in the best code. Sometimes, bending or breaking the rules may be necessary to achieve the desired outcome.
When using the BloC pattern, one key concept is distinguishing between "business logic" and "UI logic." It is common for the business logic in a Flutter app to be heavily focused on the UI, so attempting to remove all UI logic from the controller may be unnecessary and even counter-productive. Instead, it may be more effective to think critically about the app's structure and make informed decisions about the appropriate balance between business and UI logic.
Effective communication and consensus among team members are also crucial in software development. A set of rules, such as those provided by the BloC pattern, is separate from discussion and collaboration. It is important to work with other programmers, understand the tradeoffs, and reach a consensus on the best approach for your project.
Testing is another important factor to consider when using the BloC pattern. While unit tests can be useful in certain circumstances, widget tests may be more effective in covering controller logic. Anything that cannot be covered by widget tests is unlikely to occur in the app.
In summary, the BloC pattern can be a useful tool for separating UI and business logic in Flutter projects. However, it is important to understand that the strict rules of the pattern may not always apply and to consider the tradeoffs and make informed decisions about its use in your project. Effective communication and collaboration among team members and careful consideration of testing strategies can also help ensure the success of your project.