The BLoC pattern

In most of the projects we have built so far, we've dealt with the state using stateful widgets. While this approach is great for prototyping or simple apps, it is not ideal when your app grows.

There are several reasons for this. Arguably, the most important reason is that you would put at least part of the logic of your app in the same class as your layout. You should avoid mixing layout and code, as it's hard to maintain and reuse the same code in different circumstances. It also makes it easier for developers in a group to work on the same code base if you keep the logic and UI clearly separated.

Also, if you have data that changes in your app, and you need to update several widgets on different screens, then you also risk unnecessarily duplicating your code. Maintaining your app may become extremely costly, and keeping the quality of your software might become challenging.

The BLoC pattern is a state management system for Flutter recommended by Google developers. BLoC helps in managing the state and accessing data from a shared class in your project.

There are several ways to manage the state in Flutter. BloC is the recommended one at this time, but it's also worth mentioning the inherited widget method, which allows the propagation of data to its child widgets, and the scoped model method, which is an external package built on top of Inherited Widget, and Redux, which may be familiar to you if you've used React. For more information about the different options for maintaining a state, have a look at https://flutter.dev/docs/development/data-and-backend/state-mgmt/options.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.42.128