Vm class Null safety

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

Vm({List<Object?> equals = const []})
The constructor takes an optional List of fields which will be used to determine whether two Vm are equal.

Properties

equals List<Object?>
The List of properties which will be used to determine whether two BaseModels are equal.
final
hashCode int
The hash code for this object. [...]
read-only, override
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
A string representation of this object. [...]
override

Operators

operator ==(Object other) bool
The equality operator. [...]
override