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>
Dispatches the action, applying its reducer, and possibly changing the store state. The action may be sync or async.
no setter
dispatchAndWait DispatchAndWait<St>
Dispatches the action, applying its reducer, and possibly changing the store state. The action may be sync or async. In both cases, it returns a Future that resolves when the action finishes.
no setter
dispatchAsync DispatchAsync<St>
no setter
dispatchSync DispatchSync<St>
Dispatches the action, applying its reducer, and possibly changing the store state. However, if the action is ASYNC, it will throw a StoreException.
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?
fromStoreTester(StoreTester<St> storeTester) → Model?
To test the view-model generated by a Factory, first create a store-tester. Then call the fromStoreTester method, passing the store-tester. You will get the view-model, which you can use to:
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