Event<T> class

The Event class can be used as a Redux state with flutter_redux , usually to change the internal state of a stateful widget. When creating the ViewModel with the StoreConnector, the event is "consumed" only once, and is then automatically considered "spent".

Note that since the event is spent when consumed, it can be consumed by one single widget.

If the event HAS NO VALUE AND NO GENERIC TYPE, then Event.consume() returns true if the event was dispatched, or false otherwise.

class AppState { final Event buttonEvt; }

AppState({Event buttonEvt}) : buttonEvt = buttonEvt ?? Event.spent();

Event buttonEvt_Reducer(Event buttonEvt, dynamic action) {
   if (action is Increment_Action) {
   buttonEvt = Event();
   return buttonEvt; }

If the event HAS VALUE OR SOME GENERIC TYPE, then Event.consume() returns the value if the event was dispatched, or null otherwise.

class AppState { final Event<int> buttonEvt; }

AppState({Event<int> buttonEvt}) : buttonEvt = buttonEvt ?? Event.spent();

Event buttonEvt_Reducer(Event<int> buttonEvt, dynamic action) {
   if (action is Increment_Action) {
   buttonEvt = Event(action.howMuch);
   return buttonEvt; }

For more info, see: https://pub.dartlang.org/packages/async_redux

Implementers

Constructors

Event([T? evtInfo])
Event.from(Event<T> evt1, Event<T> evt2)
This is a convenience method to create an event which consumes from more than one event. If the first event is not spent, it will be consumed, and the second will not. If the first event is spent, the second one will be consumed. So, if both events are NOT spent, the method will have to be called twice to consume both. If both are spent, returns null.
factory
Event.spent()

Properties

hashCode int
  • If two objects are equal according to the equals method, then hashcode of both must be the same. Since spent events are all equal, they should produce the same hashcode.
  • If two objects are NOT equal, hashcode may be the same or not, but it's better when they are not the same. However, events are mutable, and this could mean the hashcode of the state could be changed when an event is consumed. To avoid this, we make events always return the same hashCode.
  • no setteroverride
    isNotSpent bool
    no setter
    isSpent bool
    no setter
    runtimeType Type
    A representation of the runtime type of the object.
    no setterinherited
    state → T?
    Returns the event state.
    no setter

    Methods

    consume() → T?
    Returns the event state and consumes the event.
    noSuchMethod(Invocation invocation) → dynamic
    Invoked when a nonexistent method or property is accessed.
    inherited
    toString() String
    A string representation of this object.
    override

    Operators

    operator ==(Object other) bool
    The StoreConnector has a distinct parameter which may be set to true. As a performance optimization, distinct:true allows the widget to be rebuilt only when the ViewModel changes. If this is not done, then every time any state in the store changes the widget will be rebuilt.
    override

    Static Methods

    consumeFrom<T>(Event<T> evt1, Event<T> evt2) → T?
    This is a convenience method to consume from more than one event. If the first event is not spent, it will be consumed, and the second will not. If the first event is spent, the second one will be consumed. So, if both events are NOT spent, the method will have to be called twice to consume both. If both are spent, returns null.
    map<T, V>(Event<V> evt, T? mapFunction(V?)) Event<T>
    This is a convenience factory to create an event which is transformed by some function that, usually, needs the store state. You must provide the event and a map-function. The map-function must be able to deal with the spent state (null or false, accordingly).