NanoVar

Pub Build codecov License

A variable that can be subscribed to so the subscribers get notified when changes occur.

Usage

Create a NanoVar instance with a given initial value:

final counter = NanoVar(0);

Subscribe to changes made to the value of the NanoVar instance:

final unsubscribe = counter.subscribe((oldValue, newValue) {
    print("The counter changed from $oldValue to $newValue");
});

Assign a new value to the NanoVar instance:

counter.value = 1;

The callback declared above is now called with the assigned value and the previous value.

Call unsubscribe to make the NanoVar instance stop calling the callback:

unsubscribe();

Motivation

This library was created to be used in Flutter NanoVar, which provides a lightweight method of state management in Flutter. However, NanoVar can be used on its own as well.

Libraries

nano_var