watch<Res> method
Returns the value exposed by a provider and rebuild the widget when that value changes.
See also:
- ProviderBase.select, which allows a widget to filter rebuilds by observing only the properties.
- listen, to react to changes on a provider, such as for showing modals.
Implementation
@override
Res watch<Res>(ProviderListenable<Res> target) {
return _dependencies.putIfAbsent(target, () {
final oldDependency = _oldDependencies?.remove(target);
if (oldDependency != null) {
return oldDependency;
}
return _container.listen<Res>(
target,
(_, __) => markNeedsBuild(),
);
}).read() as Res;
}