A read-only Signal.
All Computed signals are __ReadSignal__s.
If you want to convert a Signal into a ReadSignal use the toReadSignal method
ReadSignal(
T initialValue, {
SignalOptions<T>? options,
});initialValue is the initial value of the signal.
options are the options of the signal.
Returns the current signal value.
For example:
final count = Signal(0);
print(count.value); // prints 0Returns the current signal value.
For example:
final count = Signal(0);
print(count()); // prints 0Returns true if the signal has a previous value.
For example:
final count = Signal(0);
print(count.hasPreviousValue); // prints false
count.value++;
print(count.hasPreviousValue); // prints trueReturns the previous value, or null if the signal has no previous value.
For example:
final count = Signal(0);
print(count.previousValue); // prints null
count.value++;
print(count.previousValue); // prints 0Observe the signal and trigger the listener every time the value changes with the previous and current values.
For example:
final count = Signal(0);
count.observe((previousValue, value) {
print("The count changed from $previousValue to $value");
});
count.value++;
// prints "The count changed from 0 to 1"The observation will not be fired when created with the current value, if you want to run it at creation, set fireImmediately to true, for example:
final count = Signal(0);
count.observe((previousValue, value) {
print("The count changed from $previousValue to $value");
}, fireImmediately: true);
// prints "The count changed from null to 0"Returns the future that completes when the condition evalutes to true. If the condition is already true, it completes immediately.
For example:
final count = Signal(0);
await count.until((value) => value >= 10); // await until value >= 10Returns true if the signal has been disposed.
Disposes the signal. If the signal has already been disposed, this method does nothing. All observers will be unsubscribed.
Returns a string representation of the signal. For example:
final count = Signal(0);
count.value++;
print(count.toString());
// prints "ReadSignal<int>(value: 1, previousValue: 0, options: ...)"Converts this ReadSignal into a ValueNotifier.
If you need to convert a ValueNotifier into a ReadSignal use toSignal() instead.