fetch<T> method
This is used to retrieve a ScopedValue already registered in watch
or cache
with the widget below it, etc.
An error is returned when trying to retrieve a ScopedValue that is not registered in watch
or cache
.
ScopedValue registered in watch
and ScopedValue registered in cache
are processed in this order.
When watch
returns a registered ScopedValue, it will be associated with the widget and notify the user of the change.
If there are multiple ScopedValue of the same type in the scope, specify name
.
watch
やcache
ですでに登録しているScopedValueをその下のウィジェット等で取得するために利用します。
watch
やcache
で登録されていないScopedValueを取得しようとした時エラーが返されます。
watch
で登録したScopedValue、cache
で登録したScopedValueの順番で処理されます。
watch
で登録したScopedValueを返すときにウィジェットに関連付けて変更を通知するようにします。
そのスコープ内に同じ型のScopedValueが複数存在する場合はname
を指定してください。
Implementation
T fetch<T>([
Object? name,
]) {
final res = getAlreadyExistsScopedValue<T,
_WatchValue<T, PageOrWidgetScopedValueRef>>(
name: name,
listen: true,
) ??
getAlreadyExistsScopedValue<T,
_CacheValue<T, PageOrWidgetScopedValueRef>>(
name: name,
);
assert(
res != null,
"Could not find $T. Please define $T in the element above.",
);
return res!;
}