useInherited<T> function

Computed<T> useInherited<T>(
  1. T getter(
    1. BuildContext
    )
)

Reactively tracks an InheritedWidget inside setup.

Provide a getter such as (context) => Theme.of(context). The hook calls it with the current BuildContext, and the returned Computed keeps widgets in sync by updating whenever the inherited widget changes.

Example:

final theme = useInherited((context) => Theme.of(context));
return () => Text('Hello', style: theme().textTheme.bodyLarge);

Returns a computed signal that stays in sync with the inherited widget.

Implementation

Computed<T> useInherited<T>(T Function(BuildContext) getter) {
  return useHook(_UseInheritedHook<T>(getter));
}