![]() An event can be fired from anywhere, such as from a UI widget. Important BLoC conceptsīefore we dive in, let’s review some basic BLoC concepts and terms so we’re all on the same page. This facilitates the reusability of the code. Since the BLoC handles the rotation and changing color operation, both operations can be performed on any widget. Similarly, the circle widget changes its color when the Change color to Red button is clicked. The triangle widget rotates itself upon receiving the RotatedState from the BLoC. Take the simple example below:Īs soon as the Rotate 90° button is clicked, the RotateEvent is dispatched to BLoC and the state representing the rotation, i.e. In simple terms, BLoC accepts a stream of events, processes the data based on events, and produces the output as states. Writing code in BLoC makes it easier to write and reuse tests. What is BLoC?īusiness logic components (BLoC) allow you to separate the business logic from the UI. We’ll explain what BLoC means and demonstrate how to implement any feature in BLoC. In this tutorial, we’ll focus on using the BLoC design pattern for state management in Flutter. There are myriad state management solutions available for Flutter, including Provider, InheritedWidget and InheritedModel, Redux, BLoC, GetIt, MobX, Riverpod, etc. Staying on top of everything requires an effective state management technique. There are many other factors you should also consider while developing a Flutter app, such as architecture, scalability, readability, complexity, etc. But while setState can be your best friend, it’s not a good idea to depend on it solely. In Flutter, you can manage the state of your app just by using setState. All UI components should be aware of the state of the app at all times. With multiple components, it’s crucial to implement effective communication between them. When working on a Flutter app, you might encounter the need to split a large UI component into several smaller ones to improve the readability of the code. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |