MappedEvent<V, T> class Null safety

A MappedEvent is useful when your event value must be 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).

For example, if state.indexEvt = Event<int>(5) and you must get a user from it:

var mapFunction = (index) => index == null ? null : state.users[index];
Event<User> userEvt = MappedEvent<int, User>(state.indexEvt, mapFunction);


MappedEvent(Event<V>? evt, T? mapFunction(V?))


evt Event<V>
read / write
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.
  • read-only, inherited
    isNotSpent bool
    read-only, inherited
    isSpent bool
    read-only, override
    mapFunction ↔ T? Function(V?)
    read / write
    runtimeType Type
    A representation of the runtime type of the object.
    read-only, inherited
    state → T?
    Returns the event state.
    read-only, override


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


    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. [...]