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?
Gets the store environment. This can be used to create a global value, but scoped to the store. For example, you could have a service locator, here, or a configuration value.
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

clearExceptionFor(Object actionTypeOrList) → void
Removes the given actionTypeOrList from the list of action types that failed.
currentState() → St
The current (most recent) store state. This will return the current state the store holds at the time the method is called.
exceptionFor(Object actionTypeOrList) UserException?
Returns the UserException of the actionTypeOrList that failed.
fromStore() → Model?
getAndRemoveFirstError() UserException?
Gets the first error from the error queue, and removes it from the queue.
isFailed(Object actionOrTypeOrList) bool
Returns true if an actionOrActionTypeOrList failed with an UserException. Note: This method uses the EXACT type in actionOrActionTypeOrList. Subtypes are not considered.
isWaiting(Object actionOrTypeOrList) bool
You can use isWaiting to check if:
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prop<V>(Object? key) → V
Gets a property from the store. This can be used to save global values, but scoped to the store. For example, you could save timers, streams or futures used by actions.
setProp(Object? key, Object? value) → void
Sets a property in the store. This can be used to save global values, but scoped to the store. For example, you could save timers, streams or futures used by actions.
toString() String
A string representation of this object.
inherited
waitAllActions(List<ReduxAction<St>> actions, {bool completeImmediately = false}) Future<void>
Returns a future that completes when ALL given actions finished dispatching. You MUST provide at list one action, or an error will be thrown.
waitCondition(bool condition(St), {int? timeoutMillis}) Future<ReduxAction<St>?>
Returns a future which will complete when the given state condition is true. If the condition is already true when the method is called, the future completes immediately.

Operators

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