状態管理とは、アプリがどのように**データ(状態)**を管理・更新し、その変更をUIに反映させるかを指します。アプリが成長するにつれて、状態を適切に管理することが重要になり、Flutterは組み込みの仕組み(setState)と多くのライブラリ(Provider、Riverpod、Bloc)を提供しています。
状態とは
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.
ローカル状態: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
