I am a new developer in FLUTTER.
I have a class in which I want to receive in CTR an instance of BLOC.
In addition, in the class itself I want to use STATES from the BLOC and listen to changes in STATE.
How can I do that??
I am a new developer in FLUTTER.
I have a class in which I want to receive in CTR an instance of BLOC.
In addition, in the class itself I want to use STATES from the BLOC and listen to changes in STATE.
How can I do that??
2
Answers
I sent the instance of the bloc to the class in this way:
And I used the instance of the bloc in the Aclass:
Block (BLoC, from Business Logic Component) is an architecture pattern widely used in the development of Flutter applications for state management. It helps separate business logic from the user interface, making the code more modular, testable, and scalable.
Let’s look at an example of how we can use this state manager to pull in data and display it on the screen
After connecting the Block to the project using the library, create a class and extends it from the block
We send an event to perform some action in the block, in our case receiving data in initState method
His way we get a modular architecture and a built user interface that knows nothing about the data, because only the block has access to it, this way we can use the block correctly in our class, you can read more in the documentation – https://pub.dev/packages/flutter_bloc