This is a snapshot of your application's state, defined as an immutable data structure using the Modelbuilt_value library.
This is a pure function that produces a new state of your application given the previous state and, optionally, new commands to process. Update
Upd<TModel, TMsg> update(TMsg msg, TModel model)
Updis simple data-container, it contains properties
model → TModeland
effects → Cmd<TMsg>(side-effects)
This is a pure function that produces a new UI (Widget's tree) given the current state. ViewDispatch is simple function
Widget view<TModel, TMsg>(BuildContext ctx, Dispatch<TMsg> dispatch, TModel model)
void dispatch(TMsg msg)which is dispatched
messagesinto program loop.
This an event representing a change (delta) in the state of your application, originally defined as MessageUnion type in Elm or Discriminated union in F#. Dart doesn't have built-in support for Algebraic data types, so we can use simple inheritance instead.
This is a carrier of instructions, that when evaluated may produce one or more messages. It's used for controlled side-effects. Command
The events from the outside world, which are translated into messages. For example data from Websockets, timers and etc. Subscriptions
The heart of the MVU application are three yellow boxes on the diagram. First, the state of the app (Model) is mapped to the widgets tree (View). Second, events from the UI are translated into Messages and goes to the Update function (together with current app state). Update function is the brain of the app. It contains all the presentation logic, and it MUST be pure. All the side-effects (such as database queries, http requests and etc) must be isolated using Commands and Subscriptions.
Code structure conventions
Every screen or component consists of
Model and two main functions
view. Optionally it may have
init function, which creates initial state of a
subscription function, which is subscribed to the events from the outside world and translates them to the
For every screen we have thise files:
messagesand all the other classes which is required by
xxxis screen or component name. It's composition (library) of all three parts above.
Model immutability it need to be created with
built_value library uses code generation.
build_runner are added as dev dependencies.
Whenever you update your Value Classes you need to run this command in console:
flutter packages pub run build_runner build
or run it in
flutter packages pub run build_runner watch