Signals

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';

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
// or
print(counter());

To change the value, you can use:

// Increments by 1
counter.value++; 
// Set the value to 2
counter.value = 2;
// equivalent to
counter.set(2);
// Update the value based on the current value
counter.updateValue((value) => value * 2);