Signal
Signals are the cornerstone of reactivity in solidart
. They contain values that change over time; when you change a signal’s value, it automatically updates anything that uses it.
Let’s see how to create a Signal:
Import the flutter_solidart
package:
import 'package:flutter_solidart/flutter_solidart.dart';
Import the solidart
package:
import 'package:solidart/solidart.dart';
Next create the signal with:
final counter = Signal(0);
The argument passed to the create call is the initial value, and the return value is the signal.
To retrieve the current value, you can use:
print(counter.value); // prints 0
To change the value, you can use:
// Set the value to 2counter.value = 2;// Update the value based on the current valuecounter.updateValue((value) => value * 2);