Vm class abstract
Vm is a base class for your view-models.
A view-model is a helper object to a StoreConnector widget. It holds the part of the Store state the corresponding dumb-widget needs, and may also convert this state part into a more convenient format for the dumb-widget to work with.
Each time the state changes, all StoreConnectors in the widget tree will create a view-model, and compare it with the view-model they created with the previous state. Only if the view-model changed, the StoreConnector will rebuild. For this to work, you must implement equals/hashcode for the view-model class. Otherwise, the StoreConnector will think the view-model changed everytime, and thus will rebuild everytime. This wouldn't create any visible problems to your app, but would be inefficient and maybe slow.
Using the Vm class you can implement equals/hashcode without having to override these methods. Instead, simply list all fields (which are not immutable, like functions) to the equals parameter in the constructor. For example:
ViewModel({this.counter, this.onIncrement}) : super(equals: [counter]);
Each listed state will be compared by equality (==), unless it is of type VmEquals, when it will be compared by the VmEquals.vmEquals method, which by default is a comparison by identity (but can be overridden).
- Annotations
Constructors
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
createFrom<
St, T extends Widget?, Model extends Vm> (Store< St> store, VmFactory<St, T, Model> factory) → Model -
To test the view-model generated by a Factory, use createFrom and pass it the
store
and thefactory
. Note this method must be called in a recently created factory, as it can only be called once per factory instance.