maybeDependOn<T extends InheritedWidget> method
Creates a null-safe reactive Coral pipeline subscribing to an optional InheritedWidget of type T.
aspect: Optional aspect identifier for fine-grained dependency tracking whenTis an InheritedModel.
Ensures:
- Automatically triggers
didChangeDependenciesand re-computes the pipeline wheneverT(oraspect) updates. - Returns a reactive Coral<T?> pipeline emitting
TornullifTis absent from the tree.
Example:
class MyComponent extends ComplexComputation<Widget> with CorallineBuildContextAware {
late final optionalThemeCoral = maybeDependOn<CustomThemeWidget>();
}
Implementation
@protected
@pragma('vm:prefer-inline')
Coral<T?> maybeDependOn<T extends InheritedWidget>({Object? aspect}) {
return context
.map((e) => e.dependOnInheritedWidgetOfExactType<T>(aspect: aspect))
.distinct();
}