Essentially, the state of the app, or a particular widget in the app, is just information, that is used to render the UI. This means that any change in the UI was caused by a change in the state of the application.
State management is nothing but a means to handle the multiple states your application can have. But to go further here, we need to understand the difference between Ephemeral State and Application State.
You can think of the Ephemeral state as the state that is localized to a particular, very small part/widget in the application.
For example, a password text field may have two states:
As you can probably guess, the state that may be controlling this particular widget is extremely localized and can be handled easily with a setState() method.
This is an ephemeral state.
On the flip side, if you think of another more large-scale feature, such as implementing a dark mode, the state that will be working with this, will have a large-scale impact throughout the application, and hence it cannot be handled with a vanilla setState() method.
This is an Application state, and this is where the concept of requiring a state management system comes in.
We will answer this by looking at the pros and cons of using setState() and Flutter BLoC(a popular state management plugin)
Per the docs: Ephemeral State is sometimes called UI State or local State. It’s the State you can neatly contain in a single widget.
BLoC stands for Business Logic Components, and it’s much more of an architecture than setState(); it has even been compared to MVVM (Model, View, View Model). Unlike the others, BLoC makes use of Streams and it’s often used with Provider ( another state management plugin ), which is often used as a way of exposing the BLoC for the UI.
But what does it do? Anything you want. Maybe you fed it a String that said “Smith” and the logic in the BLoC was made to return a list of everyone in your contacts list with that last name. Maybe the BLoC gets fed the number of clock ticks that have passed since an animation started and the BLoC’s job is to calculate the position of your bouncing ball based on how long ago you pressed the button. You can make it do whatever you want, it’s an architecture, a method of handling State… what you do with it is entirely up to you.