CurrentValueSubject<T> class
An Observable that holds a current value and notifies listeners when the value changes.
This is the concrete implementation of Observable used internally by Store to manage state and action streams.
Creating a Subject
final subject = CurrentValueSubject.create<int>(0);
subject.listen((value) => print(value)); // prints 0 immediately
subject.add(1); // prints 1
Derived Subjects
Create a derived subject that projects a subset of the value:
final name = subject.derive((user) => user.name);
- Inheritance
-
- Object
- Observable<
T> - CurrentValueSubject
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
listeners
↔ List<
Listener< T> > -
getter/setter pair
- onCancel ← void Function()
-
Sets the cancellation callback. Can only be set once.
no getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T
-
The current value held by this subject.
no setter
Methods
-
add(
T value) → void -
Emits a new
valueto all listeners. -
cancel(
int id) → void -
Cancels a subscription by its
id, as returned from listen.override -
derive<
Derived> (Derived deriveState(T state)) → CurrentValueSubject< Derived> - Creates a derived subject that projects a subset of this subject's value.
-
dispose(
) → void - Removes all listeners and clears the cancellation callback.
-
distinct(
[bool isEqual(T a, T b)?]) → Observable< T> -
Returns an observable that only emits when the value changes according
to
isEqual(defaults to==).inherited -
listen(
OnChangeCallback< T> callback, {bool fireImmediately = true}) → int -
Subscribes to value changes.
override
-
map<
R> (R transform(T value)) → Observable< R> -
Returns an observable that transforms each emitted value using
transform.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
when(
bool predicate(T value)) → Observable< T> -
Returns an observable that only emits values satisfying
predicate.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create<
T> (T value) → CurrentValueSubject< T> -
Creates a subject with an initial
value. -
empty<
T> () → CurrentValueSubject< T> - Creates a subject without an initial value.