Sparround

Ephemeral state vs app state

The official Flutter documentation splits state into two groups.

Ephemeral state (UI state, local state) is state you can neatly contain in a single widget. The official examples: the current page of a PageView, the progress of an animation, the selected tab of a BottomNavigationBar. A StatefulWidget with setState is enough for it.

App state (shared state) is state shared across many parts of the app that you want to keep between sessions. The official examples: user preferences, login info, notifications, the shopping cart, the read/unread state of articles.

QuestionEphemeralApp state
Who reads it?One widget and its subtreeScreens far apart in the tree
What happens when the widget is disposed?It is lost — and that is fineIt must survive
Typical tool`setState`, `ValueNotifier`Provider / Riverpod / BLoC
How it is testedThrough a widget testA separate unit test, independent of the UI

The official docs say plainly that there is no universal rule: as an app grows you sometimes have to move ephemeral state into app state. The practical principle the docs cite: do whatever is less awkward. In an interview this answer lands far better than "I always use BLoC".

📚 Sources and documentation