AnyNotifier<StateT, ValueT> class abstract Notifiers

A base class for all "notifiers".

This is a good interface to target for writing mixins for Notifiers.

To perform logic before/after the build method of a notifier, you can override runBuild:

mixin MyMixin<T> extends AnyNotifier<T, FutureOr<T>> {
  @override
  void runBuild() {
    // It is safe to use "ref" here.
    listenSelf((prev, next) => print("New state $next"));

    print('Before build');
    super.runBuild();
    print('After build');
  }
}
Available extensions
Annotations
  • @publicInRiverpodAndCodegen

Constructors

AnyNotifier.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
ref Ref
The Ref associated with this notifier.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state ↔ StateT
The value currently exposed by this notifier.
getter/setter pair

Methods

listenSelf(void listener(StateT? previous, StateT next), {void onError(Object error, StackTrace stackTrace)?}) → RemoveListener
Listens to changes on the value exposed by this provider.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
persist<KeyT, EncodedT>(FutureOr<Storage<KeyT, EncodedT>> storage, {required KeyT key, required EncodedT encode(ValueT state), required ValueT decode(EncodedT encoded), StorageOptions options = const StorageOptions()}) PersistResult

Available on AnyNotifier<StateT, ValueT>, provided by the NotifierPersistX extension

Persist the state of a provider to a database.
runBuild() → void
Executes Notifier.build.
toString() String
A string representation of this object.
inherited
updateShouldNotify(StateT previous, StateT next) bool
A method invoked when the state exposed by this Notifier changes. It compares the previous and new value, and return whether listeners should be notified.

Operators

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