Learn
View, ViewState, and ViewEffect
Separate repeatable rendering data from one-time work for the currently active View.
View, ViewState, and ViewEffect
The three concepts solve different temporal problems.
ViewState is repeatable
ViewState contains everything needed to render the current frame: formatted text, visible sections, enabled actions, validation messages, loading state, and stable error information.
Rendering the same ViewState repeatedly must remain correct. It is never consumed merely because Flutter rebuilt a widget.
View forwards intent
View receives ViewState and the concrete Presenter API. A child widget should therefore receive ordinary values and callbacks:
ProfileView(
title: viewState.title,
isSaving: viewState.isSaving,
canSave: viewState.canSave,
onSave: presenter.save,
)
It does not receive Model and does not locate the original business objects.
ViewEffect is one-time
Navigation, a transient message, focus, clipboard access, or a dialog belongs to ViewEffect. Effects are broadcast without retention or replay. A newly attached View must not repeat an old navigation request.
Use Never when a Presenter has no effects.
Failure rule
Information the user must be able to revisit belongs in business state and then ViewState. An effect may draw immediate attention to the same failure, but it cannot be the only record of important information.
In Flutter, onEffect receives the currently active BuildContext. This keeps tree-dependent work in the live View without storing context in Presenter.