BLoCs are pure Dart code, and so they should contain no platform-specific logic or dependencies. They should only display data and respond to user interaction. Keep the business logic out of the views. The I/O of a BLoC will be discussed later. For more information, see the documentation on implicit interfaces. Interfaces must be written in pure, platform-independent Dart code. ![]() Views communicate with the BLoC layer, which communicates to the repositories, and the repositories talk to the data layer. To achieve this, there are rules you must follow: BLoC PatternīLoC is a fancy word invented by Google meaning “ business logic components.” The idea of the BLoC pattern is to store as much of your business logic as possible in pure Dart code so it can be reused by other platforms. For a quick intro, I recommend watching Flutter/AngularDart – Code sharing, better together (DartConf 2018) when you have the time. I started looking around how to get over this and came across BLoC. I already have loads of business logic in my app and I wanted to reuse it as much as possible, and the idea of changing the code in at least two places for a single change in business logic was unacceptable. ![]() ![]() Also, Flutter only supports Android and iOS, but I wanted to publish to the web. While I fell in love with Flutter on first sight, I still had some reservations: While propagating state down the widget tree, Flutter’s InheritedWidget or Redux-with all its variations-will do the job, but with a new framework like Flutter, you would expect that the view layer would be a little more reactive, i.e., widgets would be stateless themselves, and change according to the state they’re fed from outside, but they aren’t. Flutter was the choice for mobile platforms, and I was thinking about what to choose for the web side. Mid last year, I wanted to port an Android app to iOS and web.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |