observeContext<T> function

ValueListenable<T> observeContext <T>(
  1. T dependency(
    1. BuildContext
    )
)

Implementation

ValueListenable<T> observeContext<T>(T Function(BuildContext) dependency) {
  final target = activeObservable;
  final result = ValueNotifier<T>(dependency(target.context));

  observeLifecycle(StateLifecyclePhase.didChangeDependencies, () {
    final currentDependency = dependency(target.context);
    if (currentDependency == result.value) return;
    result.value = currentDependency;
  });

  return result;
}