ComputedSignal<T, V> constructor
ComputedSignal<T, V> ({
- required BaseSignal<
T> source, - required V transform(
- T
A read-only signal whose value is derived from another signal.
Use this when you need a computed/derived value from a signal that lives in the same node, without the verbosity of TransformBridgeSignal.
late final total = registerSignal(
ComputedSignal(products, (list) => list.fold<double>(
0.0, (prev, e) => prev + e.price,
)),
);
Implementation
ComputedSignal({required this.source, required this.transform})
: super(transform(source.value)) {
_subscription = source.stream.listen((data) {
if (unsafeValue != value) {
unsafeValue = value;
controller.add(value);
}
});
}