CkBehaviorStream<T> class
A stream that caches the latest value and replays it to new listeners. Pure Dart — no Flutter dependency, no state management lock-in.
When a listener subscribes for the first time, it immediately receives the last emitted value (if any), so the screen never starts blank.
Usage:
final stream = CkBehaviorStream<int>(initialValue: 0);
stream.listen((value) => print(value)); // prints 0 immediately
stream.add(1); // prints 1
// New subscriber gets last value (1) immediately
stream.listen((value) => print(value)); // prints 1 immediately
Constructors
- CkBehaviorStream({required T initialValue})
Properties
Methods
-
add(
T value) → void - Add new value to the stream
-
dispose(
) → void - Dispose the stream controller
-
listen(
void onData(T value), {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription< T> - Listen to the stream — immediately receives last value, then future updates
-
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