State management refers to how an app manages and updates its data (state) and reflects changes in the UI. As apps grow, managing state well becomes important, and Flutter offers built-in mechanisms (setState) and many libraries (Provider, Riverpod, Bloc) for it.
What state is
STATE = data that can change and affects the UI:
→ UI state: is a checkbox checked? what's in a text field? is a menu open?
→ app state: the logged-in user, items in a cart, fetched data
→ When state changes, the UI must UPDATE to reflect it.
Local state: setState
// for state local to a single widget → StatefulWidget + setState (built-in, simple)
setState(() {
count++; // change state → triggers a rebuild → UI updates
});
// → good for simple, LOCAL state within one widget
