kisrs - Keep It Simple, Reactive State

First, make a class for your state. If your class has a dispose() Function, it will be called on disposal.

class MyStore implements StoreData {
    MyStore(){}

    final _x = DataPoint<int>(initial: 0);
    PublicDataPoint get x => _x.public;
    void increment(){
        _x.value = _x.value + 1;
    }

    void dispose(){
        _x.dispose();
    }
}

You can then attach an object of your class to a Store or StoreManager.

  • Store<T> just passes your data down the Widget tree
  • StoreManager<T> contains a Store and automatically calls the dispose() function when the Store is being disposed. Use this for cleanup.

You can access your Store with Store.of<T>(context).

DataPoints are how your store data in your state.

  • DataPoint<T>() creates a new DataPoint of a given Type that will be null initially.
  • DataPoint<T>(initial: x) creates a new DataPoint of a given Type that contains initial data.

datapoint.value = 'Hello' sets the value of datapoint to 'Hello' and sends the new value to the stream.

datapoint.value is the current value.

datapoint.stream is is a stream of value changes. When you listen to it, it immediately sends the value.

datapoint.dispose() releases the memory used for the DataPoint. You must do this in order to prevent memory leaks!

Libraries

kisrs
reactive_text_field