refProvided<T> method
Ref<T>
refProvided<T>(
- String name,
- InitialValueProvider<
T> initialValueProvider, { - bool global = false,
Creates a reference with the given name and
the result of a call to initialValueProvider.
If no reference is registered with the given
name, a new reference is created with by calling
initialValueProvider. The next time the
reference is accessed, this value will be returned.
A reference will persist until the component is
removed from the node hierarchy.
Use this method if the initial value is expensive to compute, because the function will only be called once to create the initial value.
Setting global to true makes the reference
accessible for all children of the component.
Implementation
Ref<T> refProvided<T>(String name, InitialValueProvider<T> initialValueProvider, {bool global = false}) {
return _refs.putIfAbsent(name, () {
final initialValue = initialValueProvider.call();
final ref = Ref<T>._(global, initialValue);
//_instance.logger.fine('${_location}: created ref with name ${name} with initial value ${initialValue}');
return ref;
}) as Ref<T>;
}