dependOn<T extends InheritedWidget> method

  1. @protected
Coral<T> dependOn<T extends InheritedWidget>({
  1. Object? aspect,
})

Creates a reactive Coral pipeline subscribing to an InheritedWidget of type T from the element tree.

  • aspect: Optional aspect identifier for fine-grained dependency tracking when T is an InheritedModel.

Requires:

  • An ancestor InheritedWidget of type T must exist in the element tree when the pipeline is evaluated.

Ensures:

  • Automatically triggers didChangeDependencies and re-computes the pipeline whenever T (or aspect) updates.
  • Returns a non-null reactive Coral<T> pipeline emitting instances of T.

Throws:

Example:

class MyComponent extends ComplexComputation<Widget> with CorallineBuildContextAware {
  late final themeCoral = dependOn<ThemeWidget>();
}

Implementation

@protected
@pragma('vm:prefer-inline')
Coral<T> dependOn<T extends InheritedWidget>({Object? aspect}) {
  return context
      .map((e) => e.dependOnInheritedWidgetOfExactType<T>(aspect: aspect)!)
      .distinct();
}