nstater 0.0.4
nstater: ^0.0.4 copied to clipboard
NStater is a minimal and fast way to manage state in Flutter. You control the lifecycle of controllers and reactive values yourself, using your own types and subscriptions.
NStater β lightweight state management with zero dependencies #
NStater is a minimal and fast way to manage state in Flutter. You control the lifecycle of controllers and reactive values yourself, using your own types and subscriptions.
π¦ Features #
- NVar β a typed reactive variable that notifies listeners about changes
- NField β a widget that listens to an
NVarand rebuilds only when the value actually changes - NController β a base state controller class
- NState β widget that creates a controller and manages its lifecycle
- No dependency on
ChangeNotifier/ValueNotifier - You can combine multiple
NVarΡΠΊNControllerinstances on a single screen
π Quick API #
NVar<T> #
Reactive value with subscribe / unsubscribe:
final n = NVar<int>(0);
n.addListener((v) => print('new value: $v'));
// new value: 0
n.value = 42;
print(n.value);
// 42
NField<T> #
A widget that listens to an NVar and rebuilds only when the value actually changes:
NField<int>(
data: counter,
builder: (v) => Text('$v'),
);
NController #
Base controller class with subscriptions and no dependencies:
class MyController extends NController {
int count = 0;
void inc() {
count++;
notify();
}
}
NState<C extends NController> #
Builds UI based on a controller and automatically creates and disposes it:
NState<MyController>(
create: () => MyController(),
builder: (c) => Text('${c.count}'),
);