Ref<V extends ValueRef> extension type

A namespace for Hook functions that interact with Get objects.

Unlike most Hook functions, Ref methods (such as Ref.watch) can either be called inside HookWidget.build or in a RenderHookWidget's method. The latter allows a RenderHookElement to subscribe to updates and re-paint a widget without ever rebuilding.

Additionally, if a Substitution is made in an ancestor GetScope, these methods will reference that new value automatically.

The Ref methods include:

  • Ref.watch, for subscribing to updates from a Get object.
  • Ref.read, to ensure that the scoped version of the Get object is being accessed, if applicable.
  • Ref.vsync, to manage the ticker provider of a GetVsync object.
  • Ref.select, to select a single value from a complex Get object.
    Updates are only triggered when the selected value changes.

{@tool snippet}

The Ref.new constructor can wrap a Get object, creating a Substitution which can be passed into a GetScope (see also: useSubstitute, to achieve the same effect via a Hook function).

GetScope(
  substitutes: {Ref(getValue).sub(getOtherValue)},
  child: widget.child,
);

{@end-tool}

on
Implemented types

Constructors

Ref(GetV<V> _get)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

debugSubWidget(BuildContext context) Widget?
If a Substitution was made, returns the widget that made it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sub(V newListenable, {bool autoDispose = true}) Substitution<V>
Uses a Listenable (of the Get object's representation type) to create a Substitution which can be passed into a GetScope.
subGet(GetV<V> newGet, {bool autoDispose = true}) Substitution<V>
Uses a different Get object to create a Substitution which can be passed into a GetScope.
subGetGetter(GetGetter<V> factory, {bool autoDispose = true}) Substitution<V>
Uses a callback (typically a constructor) to create a Substitution which can be passed into a GetScope.
subGetter(ValueGetter<V> factory, {bool autoDispose = true}) Substitution<V>
Uses a callback (typically a constructor) to create a Substitution which can be passed into a GetScope.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

compute<Result>(RefComputer<Result> computeCallback) → Result
Returns the provided RefComputer's output and triggers a rebuild when any of the values referenced by ComputeRef.watch change.
read<G extends GetAny>(G get, {bool createDependency = true, bool throwIfMissing = false, bool autoVsync = true}) → G
This hook function returns a copy of the provided Get object, overriding it with any replacement in an ancestor GetScope if applicable.
select<Result, T>(GetT<T> get, Result selector(T value), {bool watching = true, bool autoVsync = true, bool useScope = true}) → Result
Selects a value from a complex Get object and triggers a rebuild when the selected value changes.
vsync<A extends GetVsyncAny>(A get, {bool useScope = true, bool watching = false}) → A
Manages this Get object's Vsync.
watch<T>(GetT<T> get, {bool watching = true, bool autoVsync = true, bool useScope = true}) → T
This hook function watches a Get object and triggers a rebuild when it sends a notification.