Flutter architecture with Screen / State / View
A testable Flutter architecture for separating screen state, hook logic, views, navigation, global state, and services with utopia_hooks.
Local State
"Local state" refers to the presentation logic of a single screen or widget. It is one half of the Screen / State / View pattern - the State and Hook parts that a Screen wires to its View. It usually consists of the following parts:
Global State
"Global state" refers to any logic shared throughout the whole app, e.g. authentication, database management or user
Testing Flutter state without widget tests
Unit test utopia_hooks state hooks with SimpleHookContext, fake provided state, and mock injected services without pumping a Flutter widget tree.
Provider
Global state needs a way to reach the hooks that consume it without threading values through constructor arguments. utopiahooks solves this with its own provider mechanism: values are placed in the tree and resolved by type with useProvided(). It is the same idea as an InheritedWidget, but it works from inside a hook and rebuilds the hook when the value changes.
Dependency injection & services
A state hook that builds its own dependencies is not testable and not reusable: