coralOf<T> method
Reactively subscribes to an ancestor InheritedCoralProviderWidget and unwraps its inner Coral<T> state.
Locates the nearest InheritedCoralProviderWidget providing type T in the ancestor tree
and flattens its underlying pipeline into a unified reactive stream.
Key Architectural Advantages of coralOf<T>():
- Lazy Computation (Push-Dirty, Pull-Data): Eliminates UI frame drops (jank) by delaying computations strictly until frame render time.
- Context Decoupling via Intent Architecture: Accesses ancestor state within business class fields without storing or leaking
BuildContextreferences. - Cascade Stream Flattening (2-Axis Unwrapping): Internally evaluates as:
dependOn<InheritedCoralProviderWidget<T>>().cascade((data) => data.provider.coral)Flattens both ancestor tree position updates and internal state mutations into a single, unified Coral<T> stream. - Topological Graph Safety (
@manifestSync): Guarantees zero-over-fetching state synchronization when declared inmanifest().
Requires:
- An ancestor InheritedCoralProviderWidget providing type
Tmust exist in the element tree.
Ensures:
- Automatically tracks changes to both the ancestor widget tree and the inner Coral<T> state.
- Returns a non-null reactive Coral<T> pipeline.
Throws:
- Throws a null assertion error if no ancestor InheritedCoralProviderWidget of type
Tis found. Use maybeCoralOf if optional.
Example:
class CounterDisplay extends ComplexComputation<Widget> with CorallineBuildContextAware {
late final counterState = coralOf<CounterState>();
}
Implementation
@protected
@pragma('vm:prefer-inline')
Coral<T> coralOf<T>() {
return dependOn<InheritedCoralProviderWidget<T>>()
.cascade((data) => data.provider.coral);
}