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

  1. @override
TResult getScopedValue<TResult, TScopedValue extends ScopedValue<TResult>>(
  1. TScopedValue provider(
    1. Ref ref
    ), {
  2. void onInit(
    1. ScopedValueState<TResult, TScopedValue> state
    )?,
  3. void onUpdate(
    1. ScopedValueState<TResult, TScopedValue> state
    )?,
  4. bool listen = false,
  5. Object? name,
})
override

A method that returns the value of TResult while creating, saving, and managing the state of TScopedValue.

Specify a callback to generate TScopedValue in provider.

If listen is specified, the process of redrawing the widget or page will run when the value is updated (when ScopedValueState.setState is executed) on the widget or page that uses this.

Basically, TScopedValue is stored with the type name of TScopedValue as Key. (All generic types are also taken into account. ValueNotifier

If a value already exists for the same Key in the respective scopes of the app, page, and widget, the same object is retrieved as the last retrieved object. (If the scope is different, such as app and page, you will get a different object even if the same Key is used.)

If you want to keep them as different values with the same type on the same scope, specify name explicitly. If both type and name are the same, they are considered to be the same Key.

TScopedValueの生成・保存・状態管理を行いつつTResultの値を返すメソッド。

providerTScopedValueを生成するためのコールバックを指定します。

listenを指定するとこれを利用したWidgetやページで値の更新時(ScopedValueState.setState実行時)にWidgetやページを再描画する処理が走ります。

基本的にはTScopedValueの型名をKeyとしてTScopedValueが保存されます。 (ジェネリックタイプもすべて考慮されます。ValueNotifier<int>ValueNotifier<double>は別のKeyとして認識されます。)

アプリとページ、ウィジェットのそれぞれのスコープにおいて、すでに同じKeyに値が存在している場合、前回取得したオブジェクトと同じオブジェクトが取得されます。 (アプリとページなどスコープが異なる場合は同じKeyだった場合でも別のオブジェクトが取得されます。)

同一スコープ上で同じ型で別の値として保持したい場合はnameを明示的に指定してください。 型とnameがどちらも同じ場合は同じKeyとしてみなされます。

Implementation

@override
TResult getScopedValue<TResult, TScopedValue extends ScopedValue<TResult>>(
  TScopedValue Function(Ref ref) provider, {
  void Function(ScopedValueState<TResult, TScopedValue> state)? onInit,
  void Function(ScopedValueState<TResult, TScopedValue> state)? onUpdate,
  bool listen = false,
  Object? name,
}) {
  return _listener.getScopedValueResult<TResult, TScopedValue>(
    () => provider(this),
    onInit: onInit,
    onUpdate: onUpdate,
    listen: listen,
    name: name,
  );
}