useEntity<T extends Object> function
- WidgetRef ref, {
- required String type,
- required String? id,
- required EntityDecoder<
T> fromGraph, - EntityEncoder<
T> ? toGraph, - bool enabled = true,
- bool subscribe = true,
Watches one entity at type + id.
The provider family is keyed by its arguments, so useMemoized holds the
provider instance stable across rebuilds. Without it, a fromGraph closure
written inline at the call site would produce a new family key every render
— a subscription churn that is easy to write and hard to notice.
Set subscribe false for a one-shot read that ignores later graph changes.
Set enabled false to hold the read without unmounting the widget.
Implementation
AsyncValue<EntitySnapshot<T>> useEntity<T extends Object>(
WidgetRef ref, {
required String type,
required String? id,
required EntityDecoder<T> fromGraph,
EntityEncoder<T>? toGraph,
bool enabled = true,
bool subscribe = true,
}) {
final provider = useMemoized(
() => entityProvider<T>(
type: type,
id: id,
fromGraph: fromGraph,
toGraph: toGraph,
enabled: enabled,
subscribe: subscribe,
),
[type, id, enabled, subscribe],
);
return ref.watch(provider);
}