Skip to main content

Flutter hooks for state management

Flutter hooks are functions that hold state or logic and return a value a widget or another hook can use. In utopia_hooks, the hook model is not limited to local widget state. The same primitive powers local state, shared app state, async loading, pagination, form fields, and unit-testable screen logic.

If you come from React, the entry point is familiar: useState stores a mutable value, useEffect runs lifecycle work, and useMemoized derives values from dependencies. The difference is that Flutter has no virtual DOM and no React context tree; utopia_hooks adds the Flutter-specific pieces needed to make hooks the architecture of a whole app.

What hooks cover

Problemutopia_hooks answerStart here
Local screen stateuseState, composed into a useXScreenState hookBasics
Derived valuesuseMemoized keyed on explicit dependenciesCommon hooks
Side effectsuseEffect, with optional cleanupuseEffect
Shared app stateHookProviderContainerWidget + useProvided<T>()Global state
Async readsuseAutoComputedStateFutureBuilder alternative
Writes and submitsuseSubmitStateSubmit state
Infinite scrollusePaginatedComputedState + PaginatedComputedStateWrapperPagination
FormsuseFieldState + TextEditingControllerWrapperForms and fields
Unit testsSimpleHookContextTesting

Hooks as architecture

A hook by itself is just a primitive. The architecture comes from where hooks are allowed to live.

Every non-trivial screen follows Screen / State / View:

screens/profile
|- profile_screen.dart
|- state/profile_screen_state.dart
|- view/profile_screen_view.dart

The Screen is a thin coordinator that reads BuildContext, builds navigation callbacks, calls one state hook, and returns the View. The state hook owns the logic. The View is a StatelessWidget that receives only state.

That split is what lets hooks scale past a counter example. It gives the screen one place for logic, one place for UI, and a state hook that can run under SimpleHookContext without pumping a widget tree.

utopia_hooks and flutter_hooks

flutter_hooks is the established hook primitive for Flutter widgets. utopia_hooks is a separate implementation with a different goal: using hooks as the state-management layer for the whole presentation architecture.

The practical difference:

If you need...flutter_hooksutopia_hooks
Local widget hooksYesYes
Global app state as hooksBring another state solutionBuilt in with providers + useProvided
Unit-test hooks without a widget treeWidget-test orientedSimpleHookContext
Architecture conventionsOut of scopeScreen / State / View
Managed async and pagination hooksBring your own patternsuseAutoComputedState, usePaginatedComputedState

See the full comparison in utopia_hooks vs flutter_hooks.

Best starting paths