D
State ManagementAdvanced50 XP4 min read

How do you separate UI state from domain state?

TL;DR: UI state is screen-specific (loading spinners, form validation, selected tab). Domain state represents business data (user, orders, products). Keep them in separate models/providers to avoid coupling.

Full Answer

Mixing UI and domain concerns in one state class leads to tight coupling and hard-to-test code.

AspectUI StateDomain State
ExamplesisLoading, errorMessage, selectedIndexUser profile, cart items, product list
ScopeScreen or featureApp-wide or repository
LayerPresentation layerDomain/data layer
TestingWidget testsUnit tests without Flutter
๐ŸŽฏ

A good heuristic: domain state would exist even if you replaced Flutter with a command-line app. UI state only exists because of the GUI.

Code Examples

dartSeparate UI and domain state
Output
UI state (isLoading, errorMessage) lives in LoginNotifier; domain state (User) lives in UserRepository

Common Mistakes

  • โœ—Putting User object directly in screen state โ€” creates coupling between UI and domain layers
  • โœ—Handling navigation in the state class โ€” navigation is a UI concern

Interview Tip

๐Ÿ’ก

This answer shows you understand Clean Architecture applied to Flutter โ€” a strong differentiator for senior roles.

#UI-state#domain-state#architecture#separation-of-concerns