getAlreadyExistsScopedValueState<TResult, TScopedValue extends ScopedValue<TResult>> method

ScopedValueState<TResult, ScopedValue<TResult>>? getAlreadyExistsScopedValueState<TResult, TScopedValue extends ScopedValue<TResult>>({
  1. Object? name,
  2. void onUpdate(
    1. ScopedValueState<TResult, TScopedValue> state
    )?,
})

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.setStateScopedValueState.initValueScopedValueState.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;
  }
}