This repository contains a reference implementation of the Flutter state management architecture. It uses centralized application State managed by the Store. (Redux like approach but without reducers). It does not use BLoC or Provider patents.
The app implementation adheres to the following principles:
AppStateis the root of the application state.- Each object that is part of the state hierarchy (sub-state object) is immutable and implements a
copyWithfunction. - If an initial state is required for initialization, an
initial()factory method is provided by the class. nullvalues are not allowed for the properties of the state/sub-state objects. If a value can be null,Maybetype is used.AppStoreis the container of theAppStateit is globally accessible and exposes:state- current version of the app statestate$-Observable<AppState>- representation of the state changes over timedispath(ActionFunction)
- State can be modified by calling Store.dispatch(...) function passing Action as a parameter
- There are two reference implementations of the Actions 1) as a regular Classs (ActionClass) that implements updateState AppState->AppState that returns modified version of the state.
Actionsare always synchronous and used only to modify the state/sub-state.- For asynchronous functionality of fetching and manipulating the data a special
Fettcherservice is used.- Fetcher methods are responsible for calling
Store::dispatch(...)method before (if needed) and after fetching and preparing the data to update the state. - Fetcher methods return
Future<>to allow the caller of thefetchmethods (usually UI components) to handle success or failure of thefetchcalls to make "Navigation Decisions".
- Fetcher methods are responsible for calling
ConnectStatewidget is used to control the rendering (build(..)) of the UI Components (Widgets) by subscribing to changes of the parts of the AppState relevant to the Component.