D
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.

AspectEphemeral StateApp State
ScopeSingle widgetMultiple widgets / whole app
SolutionsetState in StatefulWidgetProvider, Riverpod, BLoC, etc.
ExamplesCurrent tab index, animation progressUser session, shopping cart, theme
Passed downNoYes โ€” 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