VmFactory<St, T extends Widget?, Model extends Vm> class abstract

Factory that creates a view-model of type Vm, for the StoreConnector:

return StoreConnector<AppState, _ViewModel>(
     vm: _Factory(),
     builder: ...

You must override the fromStore method:

class _Factory extends VmFactory {
   _ViewModel fromStore() => _ViewModel(
       counter: state,
       onIncrement: () => dispatch(IncrementAction(amount: 1)));
}

If necessary, you can pass the StoreConnector widget to the factory:

return StoreConnector<AppState, _ViewModel>(
     vm: _Factory(this),
     builder: ...

...
class _Factory extends VmFactory<AppState, MyHomePageConnector> {
   _Factory(connector) : super(connector);
   _ViewModel fromStore() => _ViewModel(
       counter: state,
       onIncrement: () => dispatch(IncrementAction(amount: widget.amount)));
}

Constructors

VmFactory([T? _connector])
You need to pass the connector widget only if the view-model needs any info from it.

Properties

connector → T
The connector widget that will instantiate the view-model.
no setter
dispatch Dispatch<St>
Runs the action, applying its reducer, and possibly changing the store state. Note: dispatch is of type Dispatch.
no setter
dispatchAsync DispatchAsync<St>
Runs the action, applying its reducer, and possibly changing the store state. Note: dispatchAsync is of type DispatchAsync.
no setter
dispatchSync DispatchSync<St>
Runs the action, applying its reducer, and possibly changing the store state. Note: dispatchSync is of type DispatchSync.
no setter
env Object?
no setter
hashCode int
The hash code for this object.
no setterinherited
ifVmIsNull bool
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state → St
The state the store was holding when the factory and the view-model were created. This state is final inside of the factory.
no setter
vm → Model
Once the view-model is created, and as long as it's not null, you can reference it by using the vm getter. This is meant to be used inside of Factory methods.
no setter
widget → T?
The connector widget that will instantiate the view-model.
no setter

Methods

currentState() → St
The current (most recent) store state. This will return the current state the store holds at the time the method is called.
fromStore() → Model?
getAndRemoveFirstError() UserException?
Gets the first error from the error queue, and removes it from the queue.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited