maybeDependOn<T extends InheritedWidget> method

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

Creates a null-safe reactive Coral pipeline subscribing to an optional InheritedWidget of type T.

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

Ensures:

  • Automatically triggers didChangeDependencies and re-computes the pipeline whenever T (or aspect) updates.
  • Returns a reactive Coral<T?> pipeline emitting T or null if T is 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();
}