select<Notifier, Result> method
read a Notifier from one provider and subscribe the widget to the changes of this Notifier.
target
is a value gotten from .select or .when
the widget only will be rebuilded depending of the condition of each method.
Implementation
@override
Result select<Notifier, Result>(Target<Notifier, Result> target) {
// if the widget was rebuilded
if (_isExternalBuild) {
_clearDependencies();
}
_isExternalBuild = false;
final notifier = target.notifier;
final insideDependencies = _dependencies.containsKey(notifier);
// if there is not a listener for the current provider
if (!insideDependencies) {
target.rebuild = _rebuild;
if (notifier is StateNotifier) {
if (target.filter == Filter.select) {
createStateSelectListener(target);
} else {
throw FlutterError('.when filter only is allowed with ref.watch');
}
} else {
createSimpleSelectListener(target);
}
final listener = target.listener;
// add the listener to the current notifier
_dependencies[notifier as BaseNotifier] = listener;
_targets[notifier] = target;
(notifier as ListeneableNotifier).addListener(listener);
}
return _targets[notifier]!.selectValue; // coverage:ignore-line
}