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

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stream Stream<T>
Get the raw stream (without replay — for advanced use)
no setter
value → T
Current value (synchronous access)
no setter

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