Listener<T extends State> class

Set up a listener for your state It is required to fill in the generic with your state, if you do not do this the store will be unable to find your listener. Example:

class Counter implements State{
  final int count;
  const Counter(this.counter);

  Counter addOne(){
    return Counter(counter + 1);
  }
}

main(){
  //sets up the Store, look at the documentation of Store for more information
  final store = Store(const [Counter()])
   //this prints the number of the counter everytime it changes
  Listener<Counter>(store:store, onEvent: (state) => print(state.count))
}

You can define these widgets anywhere inside you code, one it is called it will permanently listen to the Counter. To stop the listener from listening you can call cancel

final listener = Listener<Counter>(store:store, onEvent: (state) => print(state.count))
listener.cancel();

Constructors

Listener({required Store store, required void onEvent(T state)})

Properties

hashCode int
The hash code for this object.
no setterinherited
onEvent → void Function(T state)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
store Store
final

Methods

cancel() → void
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