Air State
air_state is the reactive engine behind Air Framework. It provides a clean API for managing state units and building reactive UIs.
Core Concepts
Section titled “Core Concepts”1. Global State Access
Section titled “1. Global State Access”Access and update state from anywhere using keys.
// Set a valueAir().state<int>('counter', initialValue: 0).value = 5;
// Get a valuefinal count = Air().state<int>('counter').value;2. Typed Keys (Recommended)
Section titled “2. Typed Keys (Recommended)”To avoid “magic strings” and ensure type safety, use SimpleStateKey.
// 1. Defineconst counterKey = SimpleStateKey<int>('counter', defaultValue: 0);
// 2. Accessprint(counterKey.value);
// 3. UpdatecounterKey.value = 10;3. No Providers Required
Section titled “3. No Providers Required”Unlike other state management solutions in Flutter, Air Framework does not require a Provider or any context-based injection at the widget level.
The reactive state is globally accessible and managed by the modules, meaning you can access your Flows and Pulses from anywhere without passing BuildContext down the tree.
Reactive Builders
Section titled “Reactive Builders”AirBuilder
Section titled “AirBuilder”A simple widget that rebuilds when a specific key changes.
AirBuilder<int>( stateKey: 'counter', initialValue: 0, builder: (context, value) { return Text('Count: $value'); },);AirView
Section titled “AirView”AirView is more powerful. It automatically tracks any state accessed within its builder function and rebuilds only when those specific values change.
AirView((context) { // Automatically rebuilds if counterKey.value changes return Text('Current value: ${counterKey.value}');});