MomentumController<M> class
abstract
The class which holds the logic for your app. This is tied with MomentumModel.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isLazy → bool?
-
A getter that indicates if this controller is lazy loaded or not.
no setter
- loggingEnabled → bool?
-
Indicates whether debug logging for this controller is enable or not.
no setter
- maxTimeTravelSteps → int?
-
Maximum number of steps this controller can undo and redo states.
no setter
- model → M
-
The current model state.
The initial value is specified in your
init()
implementation.no setter - nextModel → M?
-
Next model state.
Will only have a value if time travel
is enabled and
backward()
was called.no setter - persistenceKey → String
-
The key used internally by momentum
for persistence with this controller.
You can also use this to clear the data
or even override the persisted json value
(use with caution).
no setter
- persistentStateDisabled → bool?
-
Indicates whether persistence is enabled or disabled for this controller.
no setter
- prevModel → M?
-
Previous model state.
Will only have value if time travel is enabled.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strategy → BootstrapStrategy?
-
The bootstrap behavior for controllers if lazy is
true
.no setter
Methods
-
addListener(
{required MomentumState< StatefulWidget> state, required void invoke(M, bool)}) → void - UPDATE NOTE: For showing dialogs/snackbars/toast/alerts/etc or navigation , use the new MomentumController.listen instead for better flow.
-
backward(
) → void -
Time travel method.
An
undo
function for states. This method will set the model state one step behind. -
bootstrap(
) → void -
An optional callback for synchronous initialization.
If lazy loading is disabled this will be called right when
the app starts. Use
bootstrapAsync()
if you want asynchronous. -
bootstrapAsync(
) → Future< void> - An optional callback for asynchronous initialization. If lazy loading is disabled this will be called right when the app starts and displays a loading widget until the async operation is finished.
-
clearStateHistory(
) → void -
Added on
v2.0.0
-
config(
{bool? enableLogging, int? maxTimeTravelSteps, bool? lazy, BootstrapStrategy? strategy}) → void - Configure this controller to set some custom behaviors.
-
controller<
T extends MomentumController> () → T - Dependency injection method for getting other controllers. Useful for accessing other controllers' function and model properties without dragging the widget context around.
-
dependOn<
T extends MomentumController> () → T - Dependency injection method for getting other controllers. Useful for accessing other controllers' function and model properties without dragging the widget context around.
-
forward(
) → void -
Time travel method.
A
redo
function for states. Ifbackward()
was called before, this method will set the model state one step ahead. -
getService<
T extends MomentumService> ({bool runtimeType = true, dynamic alias}) → T - A method for getting a service marked with MomentumService that are injected into Momentum root widget.
-
init(
) → M - Initialize the model of this controller. Required to be implemented.
-
listen<
T> ({required MomentumState< StatefulWidget> state, required void invoke(T data)}) → void - NEW FEATURE
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onReady(
) → void -
Added on
v2.0.0
-
reset(
{bool? clearHistory}) → void -
Reset the model of this controller.
The implementation of
init()
is used. -
sendEvent<
T> (T data) → void -
Send event data to all listeners of data type
T
. Listeners are created using MomentumController.listen. This should be used for notifying the widgets to show dialogs/snackbars/toast/alerts/etc. -
service<
T extends MomentumService> ({bool runtimeType = true, dynamic alias}) → T - A method for getting a service marked with MomentumService that are injected into Momentum root widget.
-
skipPersist(
) → Future< bool?> -
You can use this method to
enable/disable persistence
for this controller.
Returns
null
by default. Because this is asynchronous, you can do any asynchronous code. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited