State management jirreferi għal kif app jimmaniġġja u ażżorna l-data (state) tiegħu u jirefletti l-bidliet fl-UI. Meta l-apps tikbir, il-ġestjoni ta' state tajba ssir importanti, u Flutter toffri mekkaniżmi integrati (setState) u ħafna libreriji (Provider, Riverpod, Bloc) għaliha.
X'inhu state
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
