watch<T> method

T watch<T>(
  1. Watchable<T> watchable
)

Reads the current state of watchable and rebuilds the widget calling this methods when the state changes.

Cannot be called outside a build method.

Implementation

T watch<T>(Watchable<T> watchable) {
  assert(
      widget is LayoutBuilder ||
          widget is SliverWithKeepAliveWidget ||
          debugDoingBuild,
      'Cannot call watch() outside a build method.');
  final keys = <BinderKey>[];
  return watchScope(watchable, keys).read(watchable, keys);
}