ids method
- @Deprecated('the .ids filter is obsolete in favor to .select' ' and it will be removed in flutter_meedu:^6.x.x')
use this method to rebuild your Consumer using ids (a list of strings)
passed when you call [notify('id1','id2',...
)]
If you pass to notify method using
an empty list of ids you can use allowNotifyWithEmptyIds
to decide if the Consumer widget or a ProviderListener must be notified
Implementation
@Deprecated('the .ids filter is obsolete in favor to .select'
' and it will be removed in flutter_meedu:^6.x.x')
Target<Notifier, List> ids(
List<String> Function() cb, {
bool allowNotifyWithEmptyIds = true,
}) {
final target = Target<Notifier, List>(read);
target.filter = Filter.ids;
// ignore: prefer_function_declarations_over_variables
final listener = (_) {
final List<String> listeners = _;
// get the ids passed in the notify method
// get the ids returned in the callback
final ids = cb();
if (listeners.isNotEmpty) {
// if the current Consumer contains at least one id inside the listeners
for (final id in ids) {
if (listeners.contains(id)) {
if (target.rebuild != null) {
target.rebuild!();
}
break;
}
}
} else if (allowNotifyWithEmptyIds) {
// update the widget if listeners is empty
if (target.rebuild != null) {
target.rebuild!();
}
}
};
target.listener = listener as dynamic;
return target;
}