getAlreadyExistsScopedValueState<TResult, TScopedValue extends ScopedValue<TResult> > method
ScopedValueState<TResult, ScopedValue<TResult> > ?
getAlreadyExistsScopedValueState<TResult, TScopedValue extends ScopedValue<TResult> >({
- Object? name,
- void onUpdate(
- ScopedValueState<
TResult, TScopedValue> state
- ScopedValueState<
Get the ScopedValueState associated with the TScopedValue
already stored in the ScopedValueContainer.
Returns Null if TScopedValue
does not exist.
If TScopedValue
was saved with name
, specify the same name
.
ScopedValueState.setState, ScopedValueState.initValue and ScopedValueState.didUpdateValue are not executed.
The onUpdate
is executed before the value is returned.
ScopedValueContainerにすでに保存されているTScopedValue
に関連するScopedValueStateを取得します。
TScopedValue
が存在しない場合はNullを返します。
name
を指定してTScopedValue
を保存していた場合、同じname
を指定してください。
ScopedValueState.setStateやScopedValueState.initValue、ScopedValueState.didUpdateValueは実行されません。
値が返される前にonUpdate
が実行されます。
Implementation
ScopedValueState<TResult, ScopedValue<TResult>>?
getAlreadyExistsScopedValueState<TResult,
TScopedValue extends ScopedValue<TResult>>({
Object? name,
void Function(ScopedValueState<TResult, TScopedValue> state)? onUpdate,
}) {
final key = "$TScopedValue/${name.hashCode}";
final found = _data[key];
if (found != null) {
assert(
found is ScopedValueState<TResult, TScopedValue>,
"The stored [value] type is incorrect: ${found.runtimeType}",
);
final state = found as ScopedValueState<TResult, TScopedValue>;
onUpdate?.call(state);
return state;
} else {
return null;
}
}