watch<T extends Listenable?> method

T watch<T extends Listenable?>(
  1. T callback(
    1. QueryScopedValueRef<PageOrWidgetScopedValueRef> ref
    ), {
  2. List<Object> keys = const [],
  3. Object? name,
  4. bool disposal = true,
})

You can monitor it by passing a callback that returns a ChangeNotifier.

When ChangeNotifier.notifyListeners is executed, the update is notified and the associated widget is redrawn.

If keys is different from the previous value, callback is executed again and the new ChangeNotifier is saved.

If name is specified, it is saved as a separate type. If keys is changed, the previous state is discarded, but if name is changed, it is kept as a separate state.

If disposal is set to false, when ScopedValue is destroyed, the content T is not destroyed.

ChangeNotifierを返すcallbackを渡すとそれを監視することができます。

ChangeNotifier.notifyListenersが実行されると更新が通知され、関連するウィジェットが再描画されます。

keysが前の値と違う場合再度callbackが実行され、新しいChangeNotifierが保存されます。

nameを指定すると別のタイプとして保存されます。keysを変えた場合は以前の状態は破棄されますが、nameを変えた場合は別々の状態として保持されます。

disposalfalseにするとScopedValue破棄時、中身のTは破棄されません。

Implementation

T watch<T extends Listenable?>(
  T Function(QueryScopedValueRef<PageOrWidgetScopedValueRef> ref) callback, {
  List<Object> keys = const [],
  Object? name,
  bool disposal = true,
}) {
  return getScopedValue<T, _WatchValue<T, PageOrWidgetScopedValueRef>>(
    (ref) => _WatchValue<T, PageOrWidgetScopedValueRef>(
      callback: callback,
      keys: keys,
      ref: this,
      disposal: disposal,
      autoDisposeWhenUnreferenced: false,
    ),
    listen: true,
    name: name,
  );
}