getScopedValue<TResult, TScopedValue extends ScopedValue<TResult> > method
- TScopedValue provider(
- Ref ref
- void onInit(
- ScopedValueState<
TResult, TScopedValue> state
- ScopedValueState<
- void onUpdate(
- ScopedValueState<
TResult, TScopedValue> state
- ScopedValueState<
- bool listen = false,
- Object? name,
listen
does not work only for AppRef.getScopedValue.
(setting listen
to `true' does not redraw the monitored object)
AppRef.getScopedValueに限りlisten
が動作しません。
(listen
をtrue
にしても監視対象が再描画されない)
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
の値を返すメソッド。
provider
にTScopedValue
を生成するためのコールバックを指定します。
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 _scopedValueContainer
.getScopedValueState<TResult, TScopedValue>(
() => provider(this),
name: name,
onInit: onInit,
onUpdate: onUpdate,
scope: ScopedLoggerScope.app,
managedBy: toString(),
loggerAdapters: loggerAdapters,
)
.build();
}