Init repo

This commit is contained in:
PartyDonut 2024-09-15 14:12:28 +02:00
commit 764b6034e3
566 changed files with 212335 additions and 0 deletions

View file

@ -0,0 +1,38 @@
import 'dart:async';
class StreamValue<T> {
final T _initialValue;
T _latestValue;
final StreamController<T> _controller;
bool _hasInitialValue = true;
StreamValue(T initialValue)
: _initialValue = initialValue,
_latestValue = initialValue,
_controller = StreamController<T>.broadcast();
Stream<T> get stream => _controller.stream;
void add(T value) {
_latestValue = value;
_hasInitialValue = false;
_controller.add(value);
}
void addError(Object error, [StackTrace? stackTrace]) {
_controller.addError(error, stackTrace);
}
void listen(void Function(T) onData, {Function? onError, void Function()? onDone, bool? cancelOnError}) {
if (_hasInitialValue) {
onData(_initialValue);
} else {
onData(_latestValue);
}
_controller.stream.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError);
}
void close() {
_controller.close();
}
}