State ManagementBeginner10 XP2 min read
What is 'state' in Flutter and how is it categorized?
TL;DR: State is any data that can change over time and affects the UI. Flutter categorizes it as ephemeral state (local to a widget, use setState) and app state (shared across widgets, use a state-management solution).
Full Answer
The Flutter documentation distinguishes two types of state based on their scope and lifetime.
| Aspect | Ephemeral State | App State |
|---|---|---|
| Scope | Single widget | Multiple widgets / whole app |
| Solution | setState in StatefulWidget | Provider, Riverpod, BLoC, etc. |
| Examples | Current tab index, animation progress | User session, shopping cart, theme |
| Passed down | No | Yes โ via InheritedWidget or DI |
๐ฏ
There's no hard rule. A form validation state could be ephemeral or app-level depending on requirements. Choose based on who needs the data, not on dogma.
Code Examples
dartEphemeral state with setState
Output
Tab switches between Home and Settings; _currentTab is local to _TabScreenState
Common Mistakes
- โLifting all state to the app level 'for consistency' โ leads to over-engineering simple UIs
- โKeeping shared state local โ causes prop-drilling or inconsistent UI across screens
Interview Tip
๐ก
Cite the Flutter docs phrase 'ephemeral vs app state'. Then say: 'In practice, I assess who needs the state before choosing a solution.'
#state#ephemeral-state#app-state#setState