state library
Reactive state, and the widgets that observe it.
The observable primitives a state class is built from — Rx, RxList and RxEvent — together with the widgets that read them: Obx for values, EventListener for one-off signals.
class CounterState {
final count = Rx<int>(0);
}
Obx((ref) => Text('${ref.watch(state.count)}'))
These are plain Listenable/ValueListenable implementations, so
ValueNotifier, ChangeNotifier, TextEditingController and friends work
with ref.watch, and with a controller's sync/subscribe, just as well.
Controllers and the widget that binds one to a subtree live in
package:subtree/subtree.dart.
Classes
-
EventListener<
T> - Runs listener with a BuildContext every time event fires, and renders child unchanged.
- Obx
-
Rebuilds its builder whenever an observable read through
ref.watchchanges. - ObxWidget
- Base class for widgets that build inside a reactive block.
- ReactiveBlock
- A reactive block outside the widget tree.
- ReactiveBlockRef
- Read access to observables that also subscribes the caller to them.
- ReactiveBlockRefExt
-
The
refhanded to an Obx builder: ReactiveBlockRef plus widget-only helpers. -
Rx<
T> - A single observable value — the basic building block of a state class.
-
RxEvent<
T> - A fire-and-forget signal: navigation, toasts, "the link was invalid".
-
RxList<
T> - An observable list whose value is always unmodifiable.
-
StateObx<
S extends Object> -
An Obx that also resolves
Sfrom the enclosing subtree.