State management หมายถึงวิธีที่แอปจัดการและอัปเดต ข้อมูล (state) ของมัน และสะท้อนการเปลี่ยนแปลงใน UI เมื่อแอปเติบโตขึ้น การจัดการ state ที่ดีกลายเป็นสิ่งสำคัญ และ Flutter มีกลไกในตัว (setState) และไลบรารีมากมาย (Provider, Riverpod, Bloc) สำหรับมัน
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
